pull/13215/head
rubenmoya 7 years ago
parent 1ca0d22650
commit ad153f3c1f

@ -3,7 +3,6 @@ var Backbone = require('backbone');
var ModalsService = require('../../../../javascripts/cartodb3/components/modals/modals-service-model');
var LayerDefinitionModel = require('../../../../javascripts/cartodb3/data/layer-definition-model');
var EditorPane = require('../../../../javascripts/cartodb3/editor/editor-pane');
var WidgetDefinitionModel = require('../../../../javascripts/cartodb3/data/widget-definition-model');
var EditorModel = require('../../../../javascripts/cartodb3/data/editor-model');
var VisDefinitionModel = require('../../../../javascripts/cartodb3/data/vis-definition-model');
var ConfigModel = require('../../../../javascripts/cartodb3/data/config-model');
@ -203,7 +202,10 @@ describe('editor/editor-pane', function () {
});
it('should render correctly', function () {
expect(this.view.$el.text()).toContain('editor.button_add');
expect(this.view.$el.text()).toContain('Foo Map');
expect(this.view.$el.text()).toContain('editor.tab-pane.layers.title-label');
expect(this.view.$el.text()).toContain('editor.tab-pane.widgets.title-label');
expect(this.view.$el.text()).toContain('editor.button_publish');
});
it('should create PanelWithOptionsView with selector for onboarding', function () {
@ -234,35 +236,6 @@ describe('editor/editor-pane', function () {
});
});
describe('add button', function () {
beforeEach(function () {
this.widgetDefModel = new WidgetDefinitionModel({
type: 'formula',
title: 'formula example',
layer_id: 'l-1',
column: 'areas',
operation: 'avg',
order: 0
}, {
configModel: {},
mapId: 'm-123'
});
});
it('should be displayed when there are items on the selected tab', function () {
expect(this.view.$('.js-add').hasClass('is-hidden')).toBeTruthy();
this.widgetDefinitionsCollection.add(this.widgetDefModel);
expect(this.view.$('.js-add').hasClass('is-hidden')).toBeFalsy();
});
it('should be hidden when an item is removed', function () {
this.widgetDefinitionsCollection.add(this.widgetDefModel);
this.widgetDefinitionsCollection.reset([]);
expect(this.view.$('.js-add').hasClass('is-hidden')).toBeTruthy();
});
});
describe('max layers', function () {
var otherLayer = new LayerDefinitionModel({
id: 'l-2',

@ -90,14 +90,13 @@ describe('editor/layers/layer-content-view/analyses/analyses-workflow-list-view'
});
it('should highlight selected node', function () {
expect(this.view.$('.is-selected').length).toEqual(1);
expect(this.view.$('li:eq(2)').hasClass('is-selected')).toBeTruthy();
expect(this.view.$('li:eq(2)').text()).toContain('a2');
expect(this.view.$('li:eq(1) .VerticalRadioList-radio .CDB-Radio').attr('checked')).toBe('checked');
expect(this.view.$('li:eq(1)').text()).toContain('a2');
});
describe('when another non-selected node is clicked', function () {
beforeEach(function () {
this.view.$('li:eq(3)').click();
this.view.$('li:eq(2)').click();
});
it('should change selected workflow item', function () {
@ -105,7 +104,7 @@ describe('editor/layers/layer-content-view/analyses/analyses-workflow-list-view'
});
it('should only have one item selected still', function () {
expect(this.view.$('.is-selected').length).toEqual(1);
expect(this.view.$('.CDB-Radio:checked').length).toEqual(1);
});
});

@ -82,6 +82,7 @@ describe('editor/layers/layers-view', function () {
this.view = new LayersView({
configModel: configModel,
userModel: {},
pollingModel: {},
editorModel: new EditorModel(),
userActions: this.userActions,
analysis: this.analysis,

@ -1,45 +1,56 @@
var $ = require('jquery');
var LayerDefinitionModel = require('../../../../../javascripts/cartodb3/data/layer-definition-model');
var ConfigModel = require('../../../../../javascripts/cartodb3/data/config-model');
var EditorWidgetView = require('../../../../../javascripts/cartodb3/editor/widgets/widget-view');
var WidgetDefinitionModel = require('../../../../../javascripts/cartodb3/data/widget-definition-model');
var WidgetsService = require('../../../../../javascripts/cartodb3/editor/widgets/widgets-service');
var FactoryModals = require('../../factories/modals');
var ENTER_KEY_CODE = 13;
var WIDGET_DEFINITION = {
type: 'formula',
title: 'AVG districts homes',
column: 'areas',
operation: 'avg',
layer_id: 'l-1',
source: 'a0'
};
var LAYER_DEFINITION = {
id: 'l-1',
options: {
type: 'CartoDB',
color: 'red',
name: 'layerrr'
}
};
describe('editor/widgets/widget-view', function () {
var model;
var view;
var layer;
var layerDefinitionModel;
var stackLayoutModel;
var widgetDefinitionModel;
beforeEach(function () {
jasmine.clock().install();
var configModel = new ConfigModel({
base_url: '/u/pepe'
});
model = new WidgetDefinitionModel({
type: 'formula',
title: 'AVG districts homes',
column: 'areas',
operation: 'avg',
layer_id: 'l-1'
}, {
configModel: configModel,
widgetDefinitionModel = new WidgetDefinitionModel(WIDGET_DEFINITION, {
configModel: {},
mapId: 'm-123'
});
layer = new LayerDefinitionModel({
id: 'l-1',
options: {
type: 'CartoDB',
color: 'red',
name: 'layerrr'
}
}, {
layerDefinitionModel = new LayerDefinitionModel(LAYER_DEFINITION, {
parse: true,
configModel: configModel
configModel: {}
});
layerDefinitionModel.findAnalysisDefinitionNodeModel = function () {
return {
get: function () {
return 'Source';
},
isSourceType: function () {
return true;
}
};
};
stackLayoutModel = jasmine.createSpyObj('stackLayoutModel', ['nextStep']);
@ -48,8 +59,8 @@ describe('editor/widgets/widget-view', function () {
view = new EditorWidgetView({
modals: FactoryModals.createModalService(),
userActions: {},
model: model,
layer: layer,
model: widgetDefinitionModel,
layer: layerDefinitionModel,
stackLayoutModel: stackLayoutModel,
querySchemaModel: {}
});
@ -62,6 +73,15 @@ describe('editor/widgets/widget-view', function () {
view.remove();
});
describe('.render', function () {
it('should render correctly', function () {
expect(view.$el.text()).toContain(WIDGET_DEFINITION.title);
expect(view.$el.text()).toContain(WIDGET_DEFINITION.source);
expect(view.$('.js-toggle-menu').length).toBe(1);
expect(view.$el.text()).toContain(LAYER_DEFINITION.options.name);
});
});
it('should have no leaks', function () {
expect(view).toHaveNoLeaks();
});
@ -71,14 +91,7 @@ describe('editor/widgets/widget-view', function () {
});
it('should add a data attribute with the model cid', function () {
expect(view.$el.data('model-cid')).toBe(model.cid);
});
it('should render correctly', function () {
expect(view.$el.text()).toContain('AVG districts home');
expect(view.$('.CDB-SelectorLayer-letter').length).toBe(1);
expect(view.$('.js-toggle-menu').length).toBe(1);
expect(view.$el.text()).toContain('layerrr');
expect(view.$el.data('model-cid')).toBe(widgetDefinitionModel.cid);
});
it('should show context menu', function () {
@ -89,13 +102,13 @@ describe('editor/widgets/widget-view', function () {
});
it('should rename', function () {
var e = $.Event('keyup');
e.which = 13;
var event = $.Event('keyup');
event.which = ENTER_KEY_CODE;
view.$('.js-toggle-menu').click();
view._contextMenuFactory.getContextMenu().$('[data-val="rename-widget"]').click();
view.$('.js-input').val('foo').trigger('keyup');
view.$('.js-input').trigger(e);
view.$('.js-input').trigger(event);
expect(EditorWidgetView.prototype._renameWidget).toHaveBeenCalled();
});
@ -104,7 +117,7 @@ describe('editor/widgets/widget-view', function () {
spyOn(WidgetsService, 'removeWidget');
view.$('.js-toggle-menu').click();
view._contextMenuFactory.getContextMenu().$('[data-val="delete-widget"]').click();
expect(WidgetsService.removeWidget).toHaveBeenCalledWith(model);
expect(WidgetsService.removeWidget).toHaveBeenCalledWith(widgetDefinitionModel);
});
});
@ -112,6 +125,6 @@ describe('editor/widgets/widget-view', function () {
spyOn(WidgetsService, 'editWidget');
view.$('.js-title').trigger('click');
jasmine.clock().tick(201);
expect(WidgetsService.editWidget).toHaveBeenCalledWith(model);
expect(WidgetsService.editWidget).toHaveBeenCalledWith(widgetDefinitionModel);
});
});

@ -2,17 +2,12 @@ var $ = require('jquery');
var Backbone = require('backbone');
var UserActions = require('../../../../../javascripts/cartodb3/data/user-actions');
var LayerDefinitionModel = require('../../../../../javascripts/cartodb3/data/layer-definition-model');
var ConfigModel = require('../../../../../javascripts/cartodb3/data/config-model');
var EditorWidgetsView = require('../../../../../javascripts/cartodb3/editor/widgets/widgets-view');
var WidgetDefinitionModel = require('../../../../../javascripts/cartodb3/data/widget-definition-model');
var FactoryModals = require('../../factories/modals');
describe('editor/widgets/widgets-view', function () {
beforeEach(function () {
this.configModel = new ConfigModel({
base_url: '/u/pepe'
});
this.model = new LayerDefinitionModel({
id: 'l-100',
options: {
@ -20,8 +15,18 @@ describe('editor/widgets/widgets-view', function () {
}
}, {
parse: true,
configModel: this.configModel
configModel: {}
});
this.model.findAnalysisDefinitionNodeModel = function () {
return {
get: function () {
return 'Source';
},
isSourceType: function () {
return true;
}
};
};
this.analysisDefinitionNodeModel = new Backbone.Model();
this.analysisDefinitionNodeModel.querySchemaModel = new Backbone.Model();
@ -31,9 +36,8 @@ describe('editor/widgets/widgets-view', function () {
spyOn(this.model, 'getAnalysisDefinitionNodeModel').and.returnValue(this.analysisDefinitionNodeModel);
this.widgetDefinitionsCollection = new Backbone.Collection();
this.layerDefinitionsCollection = new Backbone.Collection([
this.model
]);
this.analysisDefinitionNodesCollection = new Backbone.Collection();
this.layerDefinitionsCollection = new Backbone.Collection([this.model]);
this.layerDefinitionsCollection.loadAllQueryGeometryModels = function (callback) {
callback();
@ -59,6 +63,9 @@ describe('editor/widgets/widgets-view', function () {
this.view = new EditorWidgetsView({
modals: FactoryModals.createModalService(),
userActions: this.userActions,
userModel: {},
configModel: {},
analysisDefinitionNodesCollection: this.analysisDefinitionNodesCollection,
widgetDefinitionsCollection: this.widgetDefinitionsCollection,
layerDefinitionsCollection: this.layerDefinitionsCollection,
stackLayoutModel: jasmine.createSpyObj('stackLayoutModel', ['nextStep'])
@ -104,7 +111,7 @@ describe('editor/widgets/widgets-view', function () {
operation: 'avg',
order: 1
}, {
configModel: this.configModel,
configModel: {},
mapId: 'm-123'
});
this.widgetDefModel2 = new WidgetDefinitionModel({
@ -114,7 +121,7 @@ describe('editor/widgets/widgets-view', function () {
column: 'population',
order: 0
}, {
configModel: this.configModel,
configModel: {},
mapId: 'm-123'
});
this.widgetDefinitionsCollection.add(this.widgetDefModel1);
@ -159,19 +166,19 @@ describe('editor/widgets/widgets-view', function () {
column: 'areas',
operation: 'avg'
}, {
configModel: this.configModel,
configModel: {},
mapId: 'm-123'
});
this.widgetDefinitionsCollection.add(widgetDefModel);
});
it('should have no leaks', function () {
this.view.render();
expect(this.view).toHaveNoLeaks();
});
it('should go to the widget view', function () {
expect(this.view._stackLayoutModel.nextStep).toHaveBeenCalled();
});
});
it('should have no leaks', function () {
this.view.render();
expect(this.view).toHaveNoLeaks();
});
});

Loading…
Cancel
Save