Initial commit
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
var VisDefinitionModel = require('builder/data/vis-definition-model');
|
||||
var ConfigModel = require('builder/data/config-model');
|
||||
var renameMap = require('builder/editor/map-operations/rename-map');
|
||||
|
||||
describe('editor/map-operations/rename-map', function () {
|
||||
var visDefinitionModel;
|
||||
var successSaveSpy;
|
||||
var errorSaveSpy;
|
||||
|
||||
beforeEach(function () {
|
||||
var configModel = new ConfigModel({
|
||||
base_url: '/u/pepe'
|
||||
});
|
||||
|
||||
visDefinitionModel = new VisDefinitionModel({
|
||||
name: 'Foo Map',
|
||||
privacy: 'LINK',
|
||||
updated_at: '2016-06-21T15:30:06+00:00',
|
||||
type: 'derived',
|
||||
tags: ['foo', 'bar'],
|
||||
permission: {}
|
||||
}, {
|
||||
configModel: configModel
|
||||
});
|
||||
|
||||
successSaveSpy = jasmine.createSpy('successSave');
|
||||
errorSaveSpy = jasmine.createSpy('erroSave');
|
||||
spyOn(visDefinitionModel, 'save');
|
||||
});
|
||||
|
||||
it('should rename document title and the suffix should contain | CARTO', function () {
|
||||
renameMap({
|
||||
onSuccess: successSaveSpy,
|
||||
onError: errorSaveSpy,
|
||||
visDefinitionModel: visDefinitionModel,
|
||||
newName: 'Wadus',
|
||||
description: 'Wadus',
|
||||
tags: ['foo', 'bar']
|
||||
});
|
||||
|
||||
expect(visDefinitionModel.save).toHaveBeenCalled();
|
||||
visDefinitionModel.save.calls.argsFor(0)[1].success();
|
||||
|
||||
expect(successSaveSpy).toHaveBeenCalled();
|
||||
expect(document.title).not.toMatch(/CartoDB/);
|
||||
expect(document.title).toBe('Wadus | 快点');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,80 @@
|
||||
var Backbone = require('backbone');
|
||||
var zoomToData = require('builder/editor/map-operations/zoom-to-data');
|
||||
|
||||
describe('map-operations/zoom-to-data', function () {
|
||||
var bounds = {
|
||||
rows: [{
|
||||
maxx: 50
|
||||
}]
|
||||
};
|
||||
var responses = {
|
||||
success: {
|
||||
status: 200,
|
||||
responseText: JSON.stringify(bounds)
|
||||
},
|
||||
error: {
|
||||
status: 400
|
||||
}
|
||||
};
|
||||
var configModel = new Backbone.Model({
|
||||
user_name: 'curtis',
|
||||
sql_api_template: 'api_template',
|
||||
api_key: 'TERN4SC0'
|
||||
});
|
||||
var query = 'SELECT * FROM gringotts';
|
||||
|
||||
beforeEach(function () {
|
||||
jasmine.Ajax.install();
|
||||
jasmine.clock().install();
|
||||
});
|
||||
|
||||
afterEach(function () {
|
||||
jasmine.clock().uninstall();
|
||||
jasmine.Ajax.uninstall();
|
||||
});
|
||||
|
||||
it('should throw error if parameters not provided', function () {
|
||||
expect(function () {
|
||||
zoomToData();
|
||||
}).toThrowError('configModel is required');
|
||||
|
||||
expect(function () {
|
||||
zoomToData({});
|
||||
}).toThrowError('stateModel is required');
|
||||
|
||||
expect(function () {
|
||||
zoomToData({}, {});
|
||||
}).toThrowError('query is required');
|
||||
});
|
||||
|
||||
it('should call stateModel.setBounds with the bounds response', function () {
|
||||
var result;
|
||||
var stateModel = {
|
||||
setBounds: function (bounds) {
|
||||
result = bounds;
|
||||
}
|
||||
};
|
||||
|
||||
// Actual call
|
||||
zoomToData(configModel, stateModel, query);
|
||||
|
||||
// Respond to call
|
||||
var request = jasmine.Ajax.requests.mostRecent();
|
||||
request.respondWith(responses.success);
|
||||
jasmine.clock().tick(10);
|
||||
|
||||
expect(result[0][1]).toBe(bounds.rows[0].maxx);
|
||||
});
|
||||
|
||||
it('should not call again if a request is ongoing', function () {
|
||||
var stateModel = {};
|
||||
|
||||
// First call
|
||||
zoomToData(configModel, stateModel, query);
|
||||
expect(jasmine.Ajax.requests.count()).toBe(1);
|
||||
|
||||
// Second call
|
||||
zoomToData(configModel, stateModel, query);
|
||||
expect(jasmine.Ajax.requests.count()).toBe(1);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user