Initial commit

This commit is contained in:
zhongjin
2020-06-13 18:34:34 +08:00
commit 52aaa9f15d
655 changed files with 96796 additions and 0 deletions
@@ -0,0 +1,24 @@
var LegendModelBase = require('../../../../../src/geo/map/legends/legend-model-base');
var createEngine = require('../../../fixtures/engine.fixture.js');
var Engine = require('../../../../../src/engine');
var MyLegendModel = LegendModelBase.extend({ TYPE: 'type' });
describe('src/geo/map/legends/legend-model-base', function () {
var engineMock;
var legendModel;
beforeEach(function () {
engineMock = createEngine();
legendModel = new MyLegendModel({}, { engine: engineMock });
});
it('should have a "loading" state', function () {
expect(legendModel.isLoading()).toBeTruthy();
});
it('should change state to "loading" when vis is reloading', function () {
legendModel.set('state', 'something');
expect(legendModel.isLoading()).toBeFalsy();
engineMock._eventEmmitter.trigger(Engine.Events.RELOAD_STARTED);
expect(legendModel.isLoading()).toBeTruthy();
});
});
+121
View File
@@ -0,0 +1,121 @@
var Legends = require('../../../../../src/geo/map/legends/legends');
var createEngine = require('../../../fixtures/engine.fixture.js');
describe('geo/map/legends/legends', function () {
var engineMock;
beforeEach(function () {
engineMock = createEngine();
this.legends = new Legends([
{
type: 'bubble',
title: 'Bubble Legend',
pre_html: '<p>PRE Bubble Legend</p>',
post_html: '<p>POST Bubble Legend</p>',
definition: {
color: '#FABADA'
}
},
{
type: 'category',
title: 'Categories Legend',
pre_html: '<p>PRE Category Legend</p>',
post_html: '<p>POST Category Legend</p>',
definition: {
prefix: 'prefix',
suffix: 'suffix'
}
},
{
type: 'choropleth',
title: 'Choropleth Legend',
pre_html: '<p>PRE Choropleth Legend</p>',
post_html: '<p>POST Choropleth Legend</p>',
definition: {
prefix: 'prefix',
suffix: 'suffix'
}
},
{
type: 'custom',
title: 'Custom Legend',
pre_html: '<p>PRE Custom Legend</p>',
post_html: '<p>POST Custom Legend</p>',
definition: {
categories: [
{ type: 'color', name: 'Item 1', color: '#CACACA;' },
{ type: 'color', name: 'Item 2', color: '#FABADA;' }
]
}
}
], {
engine: engineMock
});
});
it('should initialize bubble legends correctly', function () {
expect(this.legends.bubble.get('title')).toEqual('Bubble Legend');
expect(this.legends.bubble.get('preHTMLSnippet')).toEqual('<p>PRE Bubble Legend</p>');
expect(this.legends.bubble.get('postHTMLSnippet')).toEqual('<p>POST Bubble Legend</p>');
expect(this.legends.bubble.get('fillColor')).toEqual('#FABADA');
});
it('should initialize category legends correctly', function () {
expect(this.legends.category.get('title')).toEqual('Categories Legend');
expect(this.legends.category.get('preHTMLSnippet')).toEqual('<p>PRE Category Legend</p>');
expect(this.legends.category.get('postHTMLSnippet')).toEqual('<p>POST Category Legend</p>');
expect(this.legends.category.get('prefix')).toEqual('prefix');
expect(this.legends.category.get('suffix')).toEqual('suffix');
});
it('should initialize choropleth legends correctly', function () {
expect(this.legends.choropleth.get('title')).toEqual('Choropleth Legend');
expect(this.legends.choropleth.get('preHTMLSnippet')).toEqual('<p>PRE Choropleth Legend</p>');
expect(this.legends.choropleth.get('postHTMLSnippet')).toEqual('<p>POST Choropleth Legend</p>');
expect(this.legends.choropleth.get('prefix')).toEqual('prefix');
expect(this.legends.choropleth.get('suffix')).toEqual('suffix');
});
it('should initialize custom legends correctly', function () {
expect(this.legends.custom.get('title')).toEqual('Custom Legend');
expect(this.legends.custom.get('preHTMLSnippet')).toEqual('<p>PRE Custom Legend</p>');
expect(this.legends.custom.get('postHTMLSnippet')).toEqual('<p>POST Custom Legend</p>');
expect(this.legends.custom.get('items').length).toEqual(2);
});
it("it should 'show' all legends that have data", function () {
this.legends = new Legends([
{
type: 'bubble',
title: 'Bubble Legend',
pre_html: '<p>PRE Bubble Legend</p>',
post_html: '<p>POST Bubble Legend</p>',
definition: {
color: '#FABADA'
}
}
], {
engine: engineMock
});
expect(this.legends.bubble.isVisible()).toBeTruthy();
expect(this.legends.category.isVisible()).toBeFalsy();
this.legends = new Legends([
{
type: 'category',
title: 'Categories Legend',
pre_html: '<p>PRE Category Legend</p>',
post_html: '<p>POST Category Legend</p>',
definition: {
prefix: 'prefix',
suffix: 'suffix'
}
}
], {
engine: engineMock
});
expect(this.legends.bubble.isVisible()).toBeFalsy();
expect(this.legends.category.isVisible()).toBeTruthy();
});
});
@@ -0,0 +1,20 @@
var StaticLegendModelBase = require('../../../../../src/geo/map/legends/static-legend-model-base');
var createEngine = require('../../../fixtures/engine.fixture.js');
var Engine = require('../../../../../src/engine');
var MyLegendModel = StaticLegendModelBase.extend({ TYPE: 'type' });
describe('src/geo/map/legends/static-legend-model-base', function () {
var engineMock;
var legendModel;
beforeEach(function () {
engineMock = createEngine();
legendModel = new MyLegendModel({}, { engine: engineMock });
});
it('should never change state to "loading" when vis is reloading', function () {
legendModel.set('state', 'something');
expect(legendModel.isLoading()).toBeFalsy();
engineMock._eventEmmitter.trigger(Engine.Events.RELOAD_STARTED);
expect(legendModel.isLoading()).toBeFalsy();
});
});