|
|
|
@ -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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|