Initial commit
This commit is contained in:
+356
@@ -0,0 +1,356 @@
|
||||
var Backbone = require('backbone');
|
||||
var AnalysisService = require('../../../../../src/analysis/analysis-service.js');
|
||||
var CartoDBLayer = require('../../../../../src/geo/map/cartodb-layer');
|
||||
var DataviewModel = require('../../../../../src/dataviews/dataview-model-base');
|
||||
var AnalysisSerializer = require('../../../../../src/windshaft/map-serializer/anonymous-map-serializer/analysis-serializer');
|
||||
var createEngine = require('../../../fixtures/engine.fixture.js');
|
||||
|
||||
describe('analysis-serializer', function () {
|
||||
var engineMock;
|
||||
var mapModel;
|
||||
var layersCollection;
|
||||
var dataviewsCollection;
|
||||
var analysisService;
|
||||
var analysisDefinition;
|
||||
var analysisModel;
|
||||
|
||||
beforeEach(function () {
|
||||
mapModel = new Backbone.Model();
|
||||
engineMock = createEngine();
|
||||
layersCollection = new Backbone.Collection();
|
||||
dataviewsCollection = new Backbone.Collection();
|
||||
analysisService = new AnalysisService({
|
||||
engine: engineMock,
|
||||
camshaftReference: fakeCamshaftReference
|
||||
});
|
||||
analysisDefinition = {
|
||||
id: 'd0',
|
||||
type: 'source',
|
||||
params: {
|
||||
query: 'select * from subway_stops'
|
||||
}
|
||||
};
|
||||
analysisModel = analysisService.analyse(analysisDefinition);
|
||||
});
|
||||
|
||||
describe('.serialize', function () {
|
||||
describe('layer sources', function () {
|
||||
it('should serialize a single analysis', function () {
|
||||
var cartoDBLayer = new CartoDBLayer({
|
||||
id: 'l1',
|
||||
source: analysisModel,
|
||||
cartocss: 'cartocssMock',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
layersCollection.reset([ cartoDBLayer ]);
|
||||
|
||||
var actual = AnalysisSerializer.serialize(layersCollection, dataviewsCollection);
|
||||
var expected = [ analysisDefinition ];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it("should NOT include an analysis if it's part of the analysis of another layer", function () {
|
||||
var analysis1 = analysisService.analyse({
|
||||
id: 'b1',
|
||||
type: 'union',
|
||||
params: {
|
||||
join_on: 'cartodb_id',
|
||||
source: {
|
||||
id: 'a2',
|
||||
type: 'estimated-population',
|
||||
params: {
|
||||
columnName: 'estimated_people',
|
||||
source: {
|
||||
id: 'a1',
|
||||
type: 'trade-area',
|
||||
params: {
|
||||
kind: 'walk',
|
||||
time: 300,
|
||||
source: {
|
||||
id: 'a0',
|
||||
type: 'source',
|
||||
params: {
|
||||
query: 'select * from subway_stops'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
var analysis2 = analysisService.analyse({
|
||||
id: 'a2',
|
||||
type: 'estimated-population',
|
||||
params: {
|
||||
columnName: 'estimated_people',
|
||||
source: {
|
||||
id: 'a1',
|
||||
type: 'trade-area',
|
||||
params: {
|
||||
kind: 'walk',
|
||||
time: 300,
|
||||
source: {
|
||||
id: 'a0',
|
||||
type: 'source',
|
||||
params: {
|
||||
query: 'select * from subway_stops'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var cartoDBLayer1 = new CartoDBLayer({
|
||||
id: 'l1',
|
||||
source: analysis1,
|
||||
cartocss: 'cartocssMock',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
var cartoDBLayer2 = new CartoDBLayer({
|
||||
id: 'l2',
|
||||
source: analysis2,
|
||||
cartocss: 'cartocssMock',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
layersCollection.reset([
|
||||
cartoDBLayer1, cartoDBLayer2
|
||||
]);
|
||||
|
||||
var actual = AnalysisSerializer.serialize(layersCollection, dataviewsCollection);
|
||||
var expected = [{
|
||||
'id': 'b1',
|
||||
'type': 'union',
|
||||
'params': {
|
||||
'join_on': 'cartodb_id',
|
||||
'source': {
|
||||
'id': 'a2',
|
||||
'type': 'estimated-population',
|
||||
'params': {
|
||||
'columnName': 'estimated_people',
|
||||
'source': {
|
||||
'id': 'a1',
|
||||
'type': 'trade-area',
|
||||
'params': {
|
||||
'kind': 'walk',
|
||||
'time': 300,
|
||||
'source': {
|
||||
'id': 'a0',
|
||||
'type': 'source',
|
||||
'params': {
|
||||
'query': 'select * from subway_stops'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
expect(actual.length).toEqual(1);
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dataview sources', function () {
|
||||
it('should serialize a single analysis', function () {
|
||||
var dataview = new DataviewModel({
|
||||
source: analysisModel
|
||||
}, {
|
||||
map: mapModel,
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
dataviewsCollection.reset([ dataview ]);
|
||||
|
||||
var actual = AnalysisSerializer.serialize(layersCollection, dataviewsCollection);
|
||||
var expected = [analysisDefinition];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it("should NOT include an analysis if it's part of the analysis of another dataview", function () {
|
||||
var analysis1 = analysisService.analyse({
|
||||
id: 'b1',
|
||||
type: 'union',
|
||||
params: {
|
||||
join_on: 'cartodb_id',
|
||||
source: {
|
||||
id: 'a2',
|
||||
type: 'estimated-population',
|
||||
params: {
|
||||
columnName: 'estimated_people',
|
||||
source: {
|
||||
id: 'a1',
|
||||
type: 'trade-area',
|
||||
params: {
|
||||
kind: 'walk',
|
||||
time: 300,
|
||||
source: {
|
||||
id: 'a0',
|
||||
type: 'source',
|
||||
params: {
|
||||
query: 'select * from subway_stops'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
var analysis2 = analysisService.analyse({
|
||||
id: 'a2',
|
||||
type: 'estimated-population',
|
||||
params: {
|
||||
columnName: 'estimated_people',
|
||||
source: {
|
||||
id: 'a1',
|
||||
type: 'trade-area',
|
||||
params: {
|
||||
kind: 'walk',
|
||||
time: 300,
|
||||
source: {
|
||||
id: 'a0',
|
||||
type: 'source',
|
||||
params: {
|
||||
query: 'select * from subway_stops'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
var dataview1 = new DataviewModel({
|
||||
source: analysis1
|
||||
}, {
|
||||
map: mapModel,
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
var dataview2 = new DataviewModel({
|
||||
source: analysis2
|
||||
}, {
|
||||
map: mapModel,
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
dataviewsCollection.reset([
|
||||
dataview1, dataview2
|
||||
]);
|
||||
|
||||
var actual = AnalysisSerializer.serialize(layersCollection, dataviewsCollection);
|
||||
var expected = [{
|
||||
'id': 'b1',
|
||||
'type': 'union',
|
||||
'params': {
|
||||
'join_on': 'cartodb_id',
|
||||
'source': {
|
||||
'id': 'a2',
|
||||
'type': 'estimated-population',
|
||||
'params': {
|
||||
'columnName': 'estimated_people',
|
||||
'source': {
|
||||
'id': 'a1',
|
||||
'type': 'trade-area',
|
||||
'params': {
|
||||
'kind': 'walk',
|
||||
'time': 300,
|
||||
'source': {
|
||||
'id': 'a0',
|
||||
'type': 'source',
|
||||
'params': {
|
||||
'query': 'select * from subway_stops'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
expect(actual.length).toEqual(1);
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should only include an analysis once when more than one layer or dataview point to the same analysis', function () {
|
||||
var cartoDBLayer1 = new CartoDBLayer({
|
||||
id: 'l1',
|
||||
source: analysisModel,
|
||||
cartocss: 'cartocssMock',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
var cartoDBLayer2 = new CartoDBLayer({
|
||||
id: 'l2',
|
||||
source: analysisModel,
|
||||
cartocss: 'cartocssMock',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
var dataview = new DataviewModel({
|
||||
source: analysisModel
|
||||
}, {
|
||||
map: mapModel,
|
||||
engine: engineMock
|
||||
});
|
||||
|
||||
layersCollection.reset([
|
||||
cartoDBLayer1, cartoDBLayer2
|
||||
]);
|
||||
dataviewsCollection.reset([
|
||||
dataview
|
||||
]);
|
||||
|
||||
var actual = AnalysisSerializer.serialize(layersCollection, dataviewsCollection);
|
||||
var expected = [ analysisDefinition ];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
// We use a "fake" reference instead of the one in src/analysis/camshaft-reference
|
||||
// to ensure that tests won't break if the real thing changes
|
||||
var fakeCamshaftReference = {
|
||||
getSourceNamesForAnalysisType: function (analysisType) {
|
||||
var map = {
|
||||
'source': [],
|
||||
'trade-area': ['source'],
|
||||
'estimated-population': ['source'],
|
||||
'point-in-polygon': ['points_source', 'polygons_source'],
|
||||
'union': ['source']
|
||||
};
|
||||
if (!map[analysisType]) {
|
||||
throw new Error('analysis type ' + analysisType + ' not supported');
|
||||
}
|
||||
return map[analysisType];
|
||||
},
|
||||
|
||||
getParamNamesForAnalysisType: function (analysisType) {
|
||||
var map = {
|
||||
'source': ['query'],
|
||||
'trade-area': ['kind', 'time'],
|
||||
'estimated-population': ['columnName'],
|
||||
'point-in-polygon': [],
|
||||
'union': ['join_on']
|
||||
};
|
||||
if (!map[analysisType]) {
|
||||
throw new Error('analysis type ' + analysisType + ' not supported');
|
||||
}
|
||||
return map[analysisType];
|
||||
}
|
||||
};
|
||||
+110
@@ -0,0 +1,110 @@
|
||||
var Backbone = require('backbone');
|
||||
var AnalysisService = require('../../../../../src/analysis/analysis-service.js');
|
||||
var CartoDBLayer = require('../../../../../src/geo/map/cartodb-layer');
|
||||
var DataviewModelBase = require('../../../../../src/dataviews/dataview-model-base');
|
||||
var AnonymousMapSerializer = require('../../../../../src/windshaft/map-serializer/anonymous-map-serializer/anonymous-map-serializer');
|
||||
|
||||
var MyDataviewModel = DataviewModelBase.extend({
|
||||
toJSON: function () {
|
||||
return {};
|
||||
}
|
||||
});
|
||||
|
||||
describe('anonymous-map-serializer', function () {
|
||||
describe('.serialize', function () {
|
||||
var engineMock;
|
||||
var mapModel;
|
||||
var layersCollection;
|
||||
var dataviewsCollection;
|
||||
var analysisService;
|
||||
var analysisModel;
|
||||
var payload;
|
||||
|
||||
beforeEach(function () {
|
||||
mapModel = new Backbone.Model();
|
||||
engineMock = new Backbone.Model();
|
||||
layersCollection = new Backbone.Collection();
|
||||
dataviewsCollection = new Backbone.Collection();
|
||||
|
||||
// Analyses
|
||||
analysisService = new AnalysisService({
|
||||
engine: engineMock,
|
||||
camshaftReference: fakeCamshaftReference
|
||||
});
|
||||
analysisModel = analysisService.analyse({
|
||||
id: 'ANALYSIS_ID',
|
||||
type: 'source',
|
||||
params: {
|
||||
query: 'select * from subway_stops'
|
||||
}
|
||||
});
|
||||
|
||||
// Layers
|
||||
var cartoDBLayer = new CartoDBLayer({
|
||||
id: 'LAYER_ID',
|
||||
source: analysisModel,
|
||||
cartocss: 'cartocssMock',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
layersCollection.add(cartoDBLayer);
|
||||
|
||||
// Dataviews
|
||||
var dataview = new MyDataviewModel({
|
||||
id: 'DATAVIEW_ID',
|
||||
source: analysisModel
|
||||
}, {
|
||||
map: mapModel,
|
||||
engine: engineMock
|
||||
});
|
||||
dataviewsCollection.add(dataview);
|
||||
|
||||
// Serialized payload
|
||||
payload = AnonymousMapSerializer.serialize(layersCollection, dataviewsCollection);
|
||||
});
|
||||
|
||||
it('should include buffersize', function () {
|
||||
expect(payload.buffersize).toEqual({
|
||||
mvt: 0
|
||||
});
|
||||
});
|
||||
|
||||
it('should include one layer', function () {
|
||||
expect(payload.layers.length).toEqual(1);
|
||||
expect(payload.layers[0].id).toEqual('LAYER_ID');
|
||||
});
|
||||
|
||||
it('should include one dataview', function () {
|
||||
expect(Object.keys(payload.dataviews).length).toEqual(1);
|
||||
expect(payload.dataviews['DATAVIEW_ID']).toBeDefined();
|
||||
});
|
||||
|
||||
it('should include one analysis', function () {
|
||||
expect(payload.analyses.length).toEqual(1);
|
||||
expect(payload.analyses[0].id).toEqual('ANALYSIS_ID');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
var fakeCamshaftReference = {
|
||||
getSourceNamesForAnalysisType: function (analysisType) {
|
||||
var map = {
|
||||
'source': []
|
||||
};
|
||||
if (!map[analysisType]) {
|
||||
throw new Error('analysis type ' + analysisType + ' not supported');
|
||||
}
|
||||
return map[analysisType];
|
||||
},
|
||||
|
||||
getParamNamesForAnalysisType: function (analysisType) {
|
||||
var map = {
|
||||
'source': ['query']
|
||||
};
|
||||
if (!map[analysisType]) {
|
||||
throw new Error('analysis type ' + analysisType + ' not supported');
|
||||
}
|
||||
return map[analysisType];
|
||||
}
|
||||
};
|
||||
+116
@@ -0,0 +1,116 @@
|
||||
var Backbone = require('backbone');
|
||||
var CategoryDataviewModel = require('../../../../../src/dataviews/category-dataview-model');
|
||||
var HistogramDataviewModel = require('../../../../../src/dataviews/histogram-dataview-model');
|
||||
var FormulaDataviewModel = require('../../../../../src/dataviews/formula-dataview-model');
|
||||
var MockFactory = require('../../../../helpers/mockFactory');
|
||||
var DataviewsSerializer = require('../../../../../src/windshaft/map-serializer/anonymous-map-serializer/dataviews-serializer');
|
||||
var createEngine = require('../../../fixtures/engine.fixture.js');
|
||||
|
||||
describe('dataviews-serializer', function () {
|
||||
describe('.serialize', function () {
|
||||
var engineMock;
|
||||
var map;
|
||||
var layer;
|
||||
var analysis;
|
||||
|
||||
beforeEach(function () {
|
||||
engineMock = createEngine();
|
||||
map = new Backbone.Model();
|
||||
layer = new Backbone.Model();
|
||||
analysis = MockFactory.createAnalysisModel({ id: 'a0' });
|
||||
});
|
||||
|
||||
it('serialises histogram dataviews', function () {
|
||||
var histogramDataview = new HistogramDataviewModel({
|
||||
id: 'dataview1',
|
||||
column: 'column1',
|
||||
column_type: 'date',
|
||||
aggregation: 'week',
|
||||
source: analysis
|
||||
}, {
|
||||
map: map,
|
||||
engine: engineMock,
|
||||
layer: layer
|
||||
});
|
||||
|
||||
var dataviewsCollection = new Backbone.Collection([
|
||||
histogramDataview
|
||||
]);
|
||||
|
||||
expect(DataviewsSerializer.serialize(dataviewsCollection)).toEqual({
|
||||
dataview1: {
|
||||
type: 'histogram',
|
||||
source: {
|
||||
id: 'a0'
|
||||
},
|
||||
options: {
|
||||
column: 'column1',
|
||||
aggregation: 'week'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('serialises category dataviews', function () {
|
||||
var categoryDataview = new CategoryDataviewModel({
|
||||
id: 'dataview2',
|
||||
column: 'column2',
|
||||
aggregation: 'aggregation2',
|
||||
aggregation_column: 'aggregation_column2',
|
||||
source: analysis
|
||||
}, {
|
||||
map: map,
|
||||
engine: engineMock,
|
||||
layer: layer
|
||||
});
|
||||
|
||||
var dataviewsCollection = new Backbone.Collection([
|
||||
categoryDataview
|
||||
]);
|
||||
|
||||
expect(DataviewsSerializer.serialize(dataviewsCollection)).toEqual({
|
||||
dataview2: {
|
||||
type: 'aggregation',
|
||||
source: {
|
||||
id: 'a0'
|
||||
},
|
||||
options: {
|
||||
column: 'column2',
|
||||
aggregation: 'aggregation2',
|
||||
aggregationColumn: 'aggregation_column2'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('serialises formula dataviews', function () {
|
||||
var formulaDataview = new FormulaDataviewModel({
|
||||
id: 'dataview3',
|
||||
column: 'column3',
|
||||
operation: 'sum',
|
||||
source: analysis
|
||||
}, {
|
||||
map: map,
|
||||
engine: engineMock,
|
||||
layer: layer
|
||||
});
|
||||
|
||||
var dataviewsCollection = new Backbone.Collection([
|
||||
formulaDataview
|
||||
]);
|
||||
|
||||
expect(DataviewsSerializer.serialize(dataviewsCollection)).toEqual({
|
||||
dataview3: {
|
||||
type: 'formula',
|
||||
source: {
|
||||
id: 'a0'
|
||||
},
|
||||
options: {
|
||||
column: 'column3',
|
||||
operation: 'sum'
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
+214
@@ -0,0 +1,214 @@
|
||||
var Backbone = require('backbone');
|
||||
var CartoDBLayer = require('../../../../../src/geo/map/cartodb-layer');
|
||||
var PlainLayer = require('../../../../../src/geo/map/plain-layer');
|
||||
var TileLayer = require('../../../../../src/geo/map/tile-layer');
|
||||
var TorqueLayer = require('../../../../../src/geo/map/torque-layer');
|
||||
var GMapsBaseLayer = require('../../../../../src/geo/map/gmaps-base-layer');
|
||||
var LayersSerializer = require('../../../../../src/windshaft/map-serializer/anonymous-map-serializer/layers-serializer');
|
||||
var MockFactory = require('../../../../helpers/mockFactory');
|
||||
var createEngine = require('../../../fixtures/engine.fixture.js');
|
||||
|
||||
describe('layers-serializer', function () {
|
||||
describe('.serialize', function () {
|
||||
var engineMock;
|
||||
var sourceMock;
|
||||
var layersCollection;
|
||||
|
||||
// Create all test objects once
|
||||
beforeAll(function () {
|
||||
layersCollection = new Backbone.Collection();
|
||||
engineMock = createEngine();
|
||||
sourceMock = MockFactory.createAnalysisModel({ id: 'a1' });
|
||||
});
|
||||
|
||||
describe('mapnik layer', function () {
|
||||
it('should serialize a cartodb layer with no aggregation', function () {
|
||||
var cartoDBLayer = new CartoDBLayer({
|
||||
id: 'l1',
|
||||
source: sourceMock,
|
||||
cartocss: 'cartoCSS1',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
layersCollection.reset([cartoDBLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
var expected = [{
|
||||
'id': 'l1',
|
||||
'type': 'mapnik',
|
||||
'options': {
|
||||
'cartocss': 'cartoCSS1',
|
||||
'cartocss_version': '2.0',
|
||||
'interactivity': ['cartodb_id'],
|
||||
'source': { id: 'a1' }
|
||||
}
|
||||
}];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should serialize a cartodb layer with aggregation', function () {
|
||||
var cartoDBLayer = new CartoDBLayer({
|
||||
id: 'l1',
|
||||
source: sourceMock,
|
||||
cartocss: 'cartoCSS1',
|
||||
cartocss_version: '2.0'
|
||||
}, {
|
||||
engine: engineMock,
|
||||
aggregation: {
|
||||
threshold: 1000,
|
||||
resolution: 4,
|
||||
placement: 'point-sample',
|
||||
columns: {
|
||||
'population': {
|
||||
aggregate_function: 'sum',
|
||||
aggregated_column: 'pop_max'
|
||||
},
|
||||
'states': {
|
||||
aggregate_function: 'sum',
|
||||
aggregated_column: 'states'
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
layersCollection.reset([cartoDBLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
|
||||
var expected = [{
|
||||
'id': 'l1',
|
||||
'type': 'mapnik',
|
||||
'options': {
|
||||
'cartocss': 'cartoCSS1',
|
||||
'cartocss_version': '2.0',
|
||||
'interactivity': ['cartodb_id'],
|
||||
'source': { id: 'a1' },
|
||||
'aggregation': {
|
||||
'threshold': 1000,
|
||||
'resolution': 4,
|
||||
'placement': 'point-sample',
|
||||
'columns': {
|
||||
'population': {
|
||||
'aggregate_function': 'sum',
|
||||
'aggregated_column': 'pop_max'
|
||||
},
|
||||
'states': {
|
||||
'aggregate_function': 'sum',
|
||||
'aggregated_column': 'states'
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should serialize a cartodb layer with propper zoom options', function () {
|
||||
var cartoDBLayer = new CartoDBLayer({
|
||||
id: 'l1',
|
||||
source: sourceMock,
|
||||
cartocss: 'cartoCSS1',
|
||||
cartocss_version: '2.0',
|
||||
minzoom: 5,
|
||||
maxzoom: 9
|
||||
},
|
||||
{
|
||||
engine: engineMock
|
||||
});
|
||||
layersCollection.reset([cartoDBLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
var expected = [{
|
||||
'id': 'l1',
|
||||
'type': 'mapnik',
|
||||
'options': {
|
||||
'cartocss': 'cartoCSS1',
|
||||
'cartocss_version': '2.0',
|
||||
'interactivity': ['cartodb_id'],
|
||||
'source': { id: 'a1' },
|
||||
'minzoom': 5,
|
||||
'maxzoom': 9
|
||||
}
|
||||
}];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
|
||||
it('should serialize a plain layer', function () {
|
||||
var plainLayer = new PlainLayer({
|
||||
id: 'l2',
|
||||
color: 'COLOR',
|
||||
image: 'http://carto.com/image.png'
|
||||
}, { engine: engineMock });
|
||||
layersCollection.reset([plainLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
var expected = [{
|
||||
'id': 'l2',
|
||||
'type': 'plain',
|
||||
'options': {
|
||||
'color': 'COLOR',
|
||||
'imageUrl': 'http://carto.com/image.png'
|
||||
}
|
||||
}];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should serialize a torque layer', function () {
|
||||
var torqueLayer = new TorqueLayer({
|
||||
id: 'l3',
|
||||
source: sourceMock,
|
||||
cartocss: 'cartocss'
|
||||
}, {
|
||||
engine: engineMock
|
||||
});
|
||||
layersCollection.reset([torqueLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
var expected = [{
|
||||
'id': 'l3',
|
||||
'type': 'torque',
|
||||
'options': {
|
||||
'source': { id: 'a1' },
|
||||
'cartocss': 'cartocss',
|
||||
'cartocss_version': '2.1.0'
|
||||
}
|
||||
}];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should serialize a tile layer', function () {
|
||||
var tileLayer = new TileLayer({
|
||||
id: 'l4',
|
||||
urlTemplate: 'URL_TEMPLATE',
|
||||
subdomains: 'abc',
|
||||
tms: false
|
||||
}, { engine: engineMock });
|
||||
layersCollection.reset([tileLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
var expected = [{
|
||||
'id': 'l4',
|
||||
'type': 'http',
|
||||
'options': {
|
||||
'urlTemplate': 'URL_TEMPLATE',
|
||||
'subdomains': 'abc',
|
||||
'tms': false
|
||||
}
|
||||
}];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
|
||||
it('should not serialize GMapsBase layers', function () {
|
||||
var gmapsBaseLayer = new GMapsBaseLayer({
|
||||
id: 'l4',
|
||||
baseType: 'roadmap'
|
||||
}, { engine: engineMock });
|
||||
layersCollection.reset([gmapsBaseLayer]);
|
||||
|
||||
var actual = LayersSerializer.serialize(layersCollection);
|
||||
var expected = [];
|
||||
expect(actual).toEqual(expected);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user