Initial commit

This commit is contained in:
zhongjin
2020-06-15 10:58:47 +08:00
commit 4f1dfe7564
8590 changed files with 1516878 additions and 0 deletions
@@ -0,0 +1,43 @@
var $ = require('jquery');
var AnalysisTooltip = require('builder/editor/layers/analysis-views/analyses-tooltip-error');
describe('editor/layers/analysis-views/analysis-tooltip-error', function () {
beforeEach(function () {
this.view = $('<div class="view"><div class="Error" style="width:10px; height: 10px; background: red; "></div></div>');
$('body').append(this.view);
this.analysisNode = {
get: function (what) {
if (what === 'status') return 'failed';
if (what === 'error') return false;
if (what === 'id') return 'a1';
}
};
this._analysisTooltip = new AnalysisTooltip({
analysisNode: this.analysisNode,
element: this.view,
triggerSelector: '.Error'
});
});
it('should not have any leaks', function () {
expect(this._analysisTooltip).toHaveNoLeaks();
});
it('should create the tooltip on mouseover', function () {
this.view.find('.Error').trigger('mouseover');
expect(this._analysisTooltip.tooltip).toBeDefined();
});
it('should destroy the tooltip on mouseout', function () {
this.view.find('.Error').trigger('mouseover');
expect(this._analysisTooltip.tooltip).toBeDefined();
this.view.find('.Error').trigger('mouseout');
expect(this._analysisTooltip.tooltip).not.toBeDefined();
});
afterEach(function () {
$('.view').remove();
});
});
@@ -0,0 +1,161 @@
var ConfigModel = require('builder/data/config-model');
var CompositeLayerAnalysisView = require('builder/editor/layers/analysis-views/composite-layer-analysis-view');
var UserModel = require('builder/data/user-model');
var LayerDefinitionsCollection = require('builder/data/layer-definitions-collection');
var AnalysisDefinitionNodesCollection = require('builder/data/analysis-definition-nodes-collection');
describe('editor/layers/analysis-views/composite-layer-analysis-view', function () {
beforeEach(function () {
var configModel = new ConfigModel({
base_url: '/u/pepe'
});
var userModel = new UserModel({}, {
configModel: configModel
});
this.analysisDefinitionNodesCollection = new AnalysisDefinitionNodesCollection(null, {
configModel: configModel,
userModel: userModel
});
this.analysisDefinitionNodesCollection.add({
id: 'a1',
type: 'intersection',
primary_source_name: 'target',
status: 'ready',
params: {
source: {
id: 'b0', // ref, belongs to another layer
type: 'source',
params: {
query: 'SELECT * FROM second'
},
options: {
table_name: 'second'
}
},
target: {
id: 'a0',
type: 'source',
params: {
query: 'SELECT * FROM first'
},
options: {
table_name: 'first'
}
}
}
});
var model = this.analysisDefinitionNodesCollection.get('a1');
this.layerDefinitionsCollection = new LayerDefinitionsCollection(null, {
configModel: configModel,
userModel: userModel,
analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
mapId: 'map-123',
stateDefinitionModel: {}
});
this.layerDefinitionsCollection.add({
id: 'l1',
kind: 'carto',
options: {
table_name: 'first',
cartocss: 'asd'
}
});
this.layerDefinitionsCollection.add({
id: 'l2',
kind: 'carto',
options: {
table_name: 'second',
cartocss: 'asd'
}
});
this.layerDefinitionModel = this.layerDefinitionsCollection.at(0);
this.layerDefinitionModel.set({ source: model.id });
this.view = new CompositeLayerAnalysisView({
model: model,
analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
layerDefinitionModel: this.layerDefinitionModel
});
this.view.render();
});
it('should have no leaks', function () {
expect(this.view).toHaveNoLeaks();
});
describe('when secondary source is a source node belonging to another layer', function () {
beforeEach(function () {
this.view.render();
});
it('should render the own source', function () {
expect(this.view.$('.js-primary-source').text()).toContain('a1');
expect(this.view.$('.js-primary-source').text()).toContain('intersection');
});
it('should render the secondary source as a reference to the other layer', function () {
expect(this.view.$('.js-secondary-source').text()).toContain('second');
});
it('should render the id', function () {
expect(this.view.$('.js-secondary-source').text()).toContain('b0');
});
});
describe('when secondary source is a (non-source) node belonging to another layer ', function () {
beforeEach(function () {
this.analysisDefinitionNodesCollection.add({
id: 'b1',
type: 'buffer',
status: 'ready',
params: {
radius: 100,
source: this.analysisDefinitionNodesCollection.get('b0').toJSON()
}
});
this.analysisDefinitionNodesCollection.get('a1').set('source', 'b1');
this.view.render();
});
it('should render the own source', function () {
expect(this.view.$('.js-primary-source').text()).toContain('a1');
expect(this.view.$('.js-primary-source').text()).toContain('intersection');
});
it('should render the secondary source as a reference to the other layer', function () {
expect(this.view.$('.js-secondary-source').text()).toContain('area-of-influence');
});
it('should render the id', function () {
expect(this.view.$('.js-secondary-source').text()).toContain('b1');
});
});
describe('when secondary source is a source node belonging to own layer', function () {
beforeEach(function () {
this.analysisDefinitionNodesCollection.get('b0').set('id', 'own');
this.analysisDefinitionNodesCollection.get('a1').set('source', 'own');
this.view.render();
});
it('should render the own source', function () {
expect(this.view.$('.js-primary-source').text()).toContain('a1');
expect(this.view.$('.js-primary-source').text()).toContain('intersection');
});
it('should render the secondary source as a source but without the id', function () {
expect(this.view.$('.js-secondary-source').text()).toContain('second');
});
it('should not render the id', function () {
expect(this.view.$('.js-secondary-source').text()).not.toContain('own');
});
});
});
@@ -0,0 +1,132 @@
var Backbone = require('backbone');
var _ = require('underscore');
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
var DefaultLayerAnalysisView = require('builder/editor/layers/analysis-views/default-layer-analysis-view');
var $ = require('jquery');
describe('editor/layers/analysis-views/default-layers-analysis-view', function () {
var $el;
beforeEach(function () {
$el = $('<div class="js-layer"><div class="js-Editor-ListLayer-titleText"></div></div>');
this.model = new AnalysisDefinitionNodeModel({
id: 'a3',
type: 'trade-area',
kind: 'walk',
time: 300,
source: 'a2'
}, {
configModel: {},
sqlAPI: {}
});
this.analysisNode = new Backbone.Model();
this.layerDefinitionModel = new Backbone.Model({id: 'l-1'});
this.view = new DefaultLayerAnalysisView({
model: this.model,
analysisNode: this.analysisNode,
layerDefinitionModel: this.layerDefinitionModel
});
});
afterEach(function () {
$el.remove();
});
describe('.render', function () {
beforeEach(function () {
this.view.render();
});
it('should render correctly', function () {
expect(_.size(this.view._subviews)).toBe(2); // [AnalysisTooltip, TipsyTooltipView]
expect(this.view.$el.text()).toContain('analyses.area-of-influence');
expect(this.view.el.className).toContain('js-analysis-node');
expect(this.view.$el.attr('data-analysis-node-id')).toContain('a3');
});
describe('when analysis node is loading', function () {
it('should render the loading state', function () {
expect(this.view.$el.html()).toContain('Loader');
expect(this.view.$el.text()).not.toContain('a3');
});
});
describe('when analysis node is ready', function () {
it('should render the node id', function () {
this.analysisNode.set('status', 'ready');
expect(this.view.$el.text()).toContain('a3');
expect(this.view.$el.html()).not.toContain('Loader');
});
});
describe('when analysis node status is failed', function () {
it('should render the error elements', function () {
this.analysisNode.set('status', 'failed');
expect(this.view.$el.hasClass('has-error')).toBe(true);
expect(this.view.$('.Editor-ListAnalysis-itemError').length).toBe(1);
});
});
});
describe('._initBinds', function () {
it('should call _toggleHover on _stateModel change highlighted', function () {
spyOn(this.view, '_toggleHover');
this.view._initBinds();
this.view._stateModel.trigger('change:highlighted');
expect(this.view._toggleHover).toHaveBeenCalled();
});
});
describe('._onMouseEnter', function () {
it('should set _stateModel highlighted to true', function () {
expect(this.view._stateModel.get('highlighted')).toBe(false);
this.view._onMouseEnter();
expect(this.view._stateModel.get('highlighted')).toBe(true);
});
});
describe('._onMouseLeave', function () {
it('should set _stateModel highlighted to false', function () {
this.view._stateModel.set('highlighted', true, { silent: true });
expect(this.view._stateModel.get('highlighted')).toBe(true);
this.view._onMouseLeave();
expect(this.view._stateModel.get('highlighted')).toBe(false);
});
});
describe('._toggleHover', function () {
it('should toggle hover', function () {
$el.append(this.view.render().el);
this.view._stateModel.set('highlighted', true, { silent: true });
this.view._toggleHover();
expect($el.hasClass('is-hover')).toBe(true);
expect($el.find('.js-Editor-ListLayer-titleText').hasClass('is-hover')).toBe(true);
this.view._stateModel.set('highlighted', false, { silent: true });
this.view._toggleHover();
expect($el.hasClass('is-hover')).toBe(false);
expect($el.find('.js-Editor-ListLayer-titleText').hasClass('is-hover')).toBe(false);
});
});
it('should have no leaks', function () {
expect(this.view).toHaveNoLeaks();
});
afterEach(function () {
this.view.clean();
});
});
@@ -0,0 +1,69 @@
var Backbone = require('backbone');
var LayerDefinitionModel = require('builder/data/layer-definition-model');
var AnalysisDefinitionNodeModel = require('builder/data/analysis-definition-node-model');
var RefLayerAnalysisView = require('builder/editor/layers/analysis-views/ref-layer-analysis-view');
describe('editor/layers/analysis-views/ref-layer-analysis-view', function () {
beforeEach(function () {
this.model = new AnalysisDefinitionNodeModel({
id: 'a3',
type: 'trade-area',
kind: 'walk',
time: 300,
source: 'a2'
}, {
configModel: {},
sqlAPI: {}
});
this.analysisNode = new Backbone.Model();
this.layerDefinitionModel = new LayerDefinitionModel({
id: 'layerA',
kind: 'carto',
options: {
table_name: 'alice'
}
}, {
configModel: {}
});
spyOn(this.layerDefinitionModel, 'getName').and.returnValue('layer-name');
this.view = new RefLayerAnalysisView({
model: this.model,
analysisNode: this.analysisNode,
layerDefinitionModel: this.layerDefinitionModel
});
this.view.render();
});
it('should have no leaks', function () {
expect(this.view).toHaveNoLeaks();
});
it('should render title', function () {
expect(this.view.$el.text()).toContain('analyses.area-of-influence');
expect(this.view.$el.text()).toContain('layer-name');
});
it('should render the loading until ready', function () {
expect(this.view.$el.html()).toContain('Loader');
expect(this.view.$el.text()).not.toContain('a3');
});
it('should render the data-attrs and js hook to edit analysis', function () {
expect(this.view.el.className).toContain('js-analysis-node');
expect(this.view.el.dataset.analysisNodeId).toEqual('a3');
});
describe('when analysis node is ready', function () {
beforeEach(function () {
this.analysisNode.set('status', 'ready');
});
it('should render id', function () {
expect(this.view.$el.text()).toContain('a3');
expect(this.view.$el.html()).not.toContain('Loader');
});
});
});
@@ -0,0 +1,171 @@
var Backbone = require('backbone');
var UserModel = require('builder/data/user-model');
var SourceLayerAnalysisView = require('builder/editor/layers/analysis-views/source-layer-analysis-view');
var AnalysisDefinitionNodesCollection = require('builder/data/analysis-definition-nodes-collection');
var ConfigModel = require('builder/data/config-model');
var TableModel = require('builder/data/table-model');
var _ = require('underscore');
var $ = require('jquery');
describe('editor/layers/analysis-views/source-layer-analysis-view', function () {
var $el;
beforeEach(function () {
$el = $('<div class="js-layer"><div class="js-Editor-ListLayer-titleText"></div></div>');
this.configModel = new ConfigModel({
base_url: '/u/pepe'
});
this.userModel = new UserModel({
username: 'chacho'
}, {
configModel: this.configModel
});
this.analysisDefinitionNodesCollection = new AnalysisDefinitionNodesCollection([{
id: 'a0',
type: 'source',
table_name: 'foo_bar',
params: {
query: 'SELECT * FROM foo_bar'
}
}], {
configModel: this.configModel,
userModel: this.userModel
});
this.sourceAnalysisDefinitionNodeModel = this.analysisDefinitionNodesCollection.get('a0');
this.layerDefinitionModel = new Backbone.Model({user_name: 'somebody'});
this.layerDefinitionModel.getQualifiedTableName = function () {};
this.view = new SourceLayerAnalysisView({
model: this.sourceAnalysisDefinitionNodeModel,
analysisNode: this.sourceAnalysisDefinitionNodeModel,
layerDefinitionModel: this.layerDefinitionModel
});
});
afterEach(function () {
$el.remove();
});
describe('.render', function () {
it('should render correctly', function () {
this.view.render();
expect(this.view.$el.text()).toContain('a0');
expect(this.view.$el.text()).toContain('foo_bar');
expect(_.size(this.view._subviews)).toBe(1); // [tooltip]
});
describe('when layer is sync', function () {
var syncView;
beforeEach(function () {
var table = new TableModel({
id: 'harrr',
name: 'another_table',
synchronization: {
id: 'test'
}
}, {
parse: true,
configModel: this.configModel
});
spyOn(this.sourceAnalysisDefinitionNodeModel, 'getTableModel').and.returnValue(table);
syncView = new SourceLayerAnalysisView({
model: this.sourceAnalysisDefinitionNodeModel,
analysisNode: this.sourceAnalysisDefinitionNodeModel,
layerDefinitionModel: this.layerDefinitionModel
});
syncView.render();
});
it('should render correctly', function () {
expect(syncView.$el.html()).toContain('CDB-IconFont CDB-IconFont-wifi');
expect(_.size(syncView._subviews)).toBe(2); // [tooltip, sync tooltip]
});
});
describe('when custom query is applied', function () {
beforeEach(function () {
spyOn(this.view._analysisNode, 'isCustomQueryApplied').and.returnValue(true);
this.view.render();
});
it('should render correctly', function () {
expect(this.view.$el.html()).toContain('js-sql');
expect(this.view.$('.js-sql').html()).toContain('SQL');
expect(_.size(this.view._subviews)).toBe(2); // [tooltip, customQuery tooltip]
});
});
});
describe('._initBinds', function () {
it('should call _toggleHover on _stateModel change highlighted', function () {
spyOn(this.view, '_toggleHover');
this.view._initBinds();
this.view._stateModel.trigger('change:highlighted');
expect(this.view._toggleHover).toHaveBeenCalled();
});
it('should call render on _tableNodeModel change synchronization', function () {
spyOn(this.view, 'render');
this.view._initBinds();
this.view._tableNodeModel.trigger('change:synchronization');
expect(this.view.render).toHaveBeenCalled();
});
});
describe('._onMouseEnter', function () {
it('should set _stateModel highlighted to true', function () {
expect(this.view._stateModel.get('highlighted')).toBe(false);
this.view._onMouseEnter();
expect(this.view._stateModel.get('highlighted')).toBe(true);
});
});
describe('._onMouseLeave', function () {
it('should set _stateModel highlighted to false', function () {
this.view._stateModel.set('highlighted', true, { silent: true });
expect(this.view._stateModel.get('highlighted')).toBe(true);
this.view._onMouseLeave();
expect(this.view._stateModel.get('highlighted')).toBe(false);
});
});
describe('._toggleHover', function () {
it('should toggle hover', function () {
$el.append(this.view.render().el);
this.view._stateModel.set('highlighted', true, { silent: true });
this.view._toggleHover();
expect($el.hasClass('is-hover')).toBe(true);
expect($el.find('.js-Editor-ListLayer-titleText').hasClass('is-hover')).toBe(true);
this.view._stateModel.set('highlighted', false, { silent: true });
this.view._toggleHover();
expect($el.hasClass('is-hover')).toBe(false);
expect($el.find('.js-Editor-ListLayer-titleText').hasClass('is-hover')).toBe(false);
});
});
it('should have no leaks', function () {
expect(this.view).toHaveNoLeaks();
});
afterEach(function () {
this.view.clean();
});
});