Windshaft-cartodb/test/acceptance/ported/multilayer-interactivity-test.js

366 lines
11 KiB
JavaScript
Raw Normal View History

'use strict';
var testHelper = require('../../support/test-helper');
2015-07-08 05:46:58 +08:00
var assert = require('../../support/assert');
2019-10-22 01:07:24 +08:00
var _ = require('underscore');
2019-10-07 15:40:50 +08:00
var cartodbServer = require('../../../lib/server');
2015-07-08 05:46:58 +08:00
var getLayerTypeFn = require('windshaft').model.MapConfig.prototype.getType;
var PortedServerOptions = require('./support/ported-server-options');
2019-10-07 15:40:50 +08:00
var LayergroupToken = require('../../../lib/models/layergroup-token');
2015-07-08 05:46:58 +08:00
2019-10-22 01:07:24 +08:00
describe('multilayer interactivity and layers order', function () {
var server;
2015-07-08 05:46:58 +08:00
before(function () {
server = cartodbServer(PortedServerOptions);
server.setMaxListeners(0);
});
2015-07-08 05:46:58 +08:00
2019-10-22 01:07:24 +08:00
function layerType (layer) {
2015-07-08 05:46:58 +08:00
return layer.type || 'undefined';
}
2019-10-22 01:07:24 +08:00
function testInteractivityLayersOrderScenario (testScenario) {
it(testScenario.desc, function (done) {
var layergroup = {
2015-07-08 05:46:58 +08:00
version: '1.3.0',
layers: testScenario.layers
};
assert.response(server,
{
2019-10-02 01:34:03 +08:00
url: '/api/v1/map',
2015-07-08 05:46:58 +08:00
method: 'POST',
headers: {
host: 'localhost',
2015-07-08 05:46:58 +08:00
'Content-Type': 'application/json'
},
data: JSON.stringify(layergroup)
},
{
2019-10-22 01:07:24 +08:00
// status: 200, don't use status here to have a more meaningful error message
2015-07-08 05:46:58 +08:00
headers: {
'content-type': 'application/json; charset=utf-8'
}
},
2019-10-22 01:07:24 +08:00
function (response) {
assert.strictEqual(
2015-07-08 05:46:58 +08:00
response.statusCode,
200,
2019-10-22 01:07:24 +08:00
'Expected status code 200, got ' + response.statusCode +
2015-07-08 05:46:58 +08:00
'\n\tResponse body: ' + response.body +
'\n\tLayer types: ' + layergroup.layers.map(layerType).join(', ')
);
var layergroupResponse = JSON.parse(response.body);
assert.ok(layergroupResponse);
var layergroupId = layergroupResponse.layergroupid;
assert.ok(layergroupId);
assert.strictEqual(layergroupResponse.metadata.layers.length, layergroup.layers.length);
2015-07-08 05:46:58 +08:00
// check layers metadata at least match in number
var layersMetadata = layergroupResponse.metadata.layers;
assert.strictEqual(layersMetadata.length, layergroup.layers.length);
2015-07-08 05:46:58 +08:00
for (var i = 0, len = layersMetadata.length; i < len; i++) {
assert.strictEqual(
2015-07-08 05:46:58 +08:00
getLayerTypeFn(layersMetadata[i].type),
getLayerTypeFn(layergroup.layers[i].type)
);
}
// check torque metadata at least match in number
2019-10-22 01:07:24 +08:00
var torqueLayers = layergroup.layers.filter(function (layer) { return layer.type === 'torque'; });
2015-07-08 05:46:58 +08:00
if (torqueLayers.length) {
assert.strictEqual(Object.keys(layergroupResponse.metadata.torque).length, torqueLayers.length);
2015-07-08 05:46:58 +08:00
}
2015-09-25 20:46:46 +08:00
var keysToDelete = {
'user:localhost:mapviews:global': 5
};
keysToDelete['map_cfg|' + LayergroupToken.parse(layergroupId).token] = 0;
testHelper.deleteRedisKeys(keysToDelete, done);
2015-07-08 05:46:58 +08:00
}
);
});
}
var cartocssVersion = '2.3.0';
var cartocss = '#layer { line-width:16; }';
var sql = "select 1 as i, st_setsrid('LINESTRING(0 0, 1 0)'::geometry, 4326) as the_geom";
var sqlWadus = "select 1 as wadus, st_setsrid('LINESTRING(0 0, 1 0)'::geometry, 4326) as the_geom";
var httpLayer = {
type: 'http',
options: {
urlTemplate: 'http://{s}.basemaps.cartocdn.com/dark_nolabels/{z}/{x}/{y}.png',
2019-10-22 01:07:24 +08:00
subdomains: ['a', 'b', 'c']
2015-07-08 05:46:58 +08:00
}
};
var torqueLayer = {
type: 'torque',
options: {
sql: "select 1 id, '1970-01-02'::date d, 'POINT(0 0)'::geometry the_geom_webmercator",
cartocss: [
2019-10-22 01:07:24 +08:00
'Map {',
'-torque-frame-count:2;',
'-torque-resolution:3;',
'-torque-time-attribute:d;',
"-torque-aggregation-function:'count(id)';",
'}'
2015-07-08 05:46:58 +08:00
].join(' '),
cartocss_version: '2.0.1'
}
};
var mapnikLayer = {
type: 'mapnik',
options: {
sql: sql,
cartocss_version: cartocssVersion,
cartocss: cartocss,
geom_column: 'the_geom'
}
};
var mapnikInteractivityLayer = {
type: 'mapnik',
options: {
sql: sql,
cartocss_version: cartocssVersion,
cartocss: cartocss,
interactivity: 'i',
geom_column: 'the_geom'
}
};
var cartodbLayer = {
type: 'cartodb',
options: {
sql: sql,
cartocss_version: cartocssVersion,
cartocss: cartocss,
geom_column: 'the_geom'
}
};
var cartodbInteractivityLayer = {
type: 'cartodb',
options: {
sql: sql,
cartocss_version: cartocssVersion,
cartocss: cartocss,
interactivity: 'i',
geom_column: 'the_geom'
}
};
var cartodbWadusInteractivityLayer = {
type: 'cartodb',
options: {
sql: sqlWadus,
cartocss_version: cartocssVersion,
cartocss: cartocss,
interactivity: 'wadus',
geom_column: 'the_geom'
}
};
var noTypeLayer = {
options: {
sql: sql,
cartocss_version: cartocssVersion,
cartocss: cartocss,
geom_column: 'the_geom'
}
};
var noTypeInteractivityLayer = {
options: {
sql: sql,
cartocss_version: cartocssVersion,
cartocss: cartocss,
interactivity: 'i',
geom_column: 'the_geom'
}
};
var allLayers = [
httpLayer,
torqueLayer,
mapnikLayer,
mapnikInteractivityLayer,
cartodbLayer,
cartodbInteractivityLayer,
cartodbWadusInteractivityLayer,
noTypeLayer,
noTypeInteractivityLayer
];
var testScenarios = [
{
desc: 'one layer, no interactivity',
layers: [cartodbLayer]
},
{
desc: 'one layer with interactivity',
layers: [cartodbInteractivityLayer]
},
{
desc: 'two layers, interactivity mix',
layers: [
cartodbLayer,
cartodbInteractivityLayer
]
},
{
desc: 'two layers, different interactivity columns',
layers: [
cartodbWadusInteractivityLayer,
cartodbInteractivityLayer
]
},
{
desc: 'mix of no interactivity with interactivity',
layers: [
cartodbInteractivityLayer,
cartodbLayer,
cartodbWadusInteractivityLayer
]
},
{
desc: 'interactivity layers + torque',
layers: [
cartodbWadusInteractivityLayer,
cartodbInteractivityLayer,
torqueLayer
]
},
{
desc: 'torque + interactivity layers',
layers: [
torqueLayer,
cartodbWadusInteractivityLayer,
cartodbInteractivityLayer
]
},
{
desc: 'interactivity + torque + interactivity',
layers: [
cartodbInteractivityLayer,
torqueLayer,
cartodbInteractivityLayer
]
},
{
desc: 'http + mix of [no] interactivity layers',
layers: [
httpLayer,
cartodbInteractivityLayer,
cartodbLayer,
cartodbInteractivityLayer
]
},
{
desc: 'http + interactivity + torque + interactivity',
layers: [
httpLayer,
cartodbInteractivityLayer,
torqueLayer,
cartodbInteractivityLayer
]
},
{
desc: 'http + interactivity + torque + no interactivity + torque + interactivity',
layers: [
httpLayer,
cartodbInteractivityLayer,
torqueLayer,
cartodbLayer,
torqueLayer,
cartodbWadusInteractivityLayer
]
},
{
desc: 'mapnik type two layers, interactivity mix',
layers: [
mapnikLayer,
mapnikInteractivityLayer
]
},
{
desc: 'mapnik type mix of no interactivity with interactivity',
layers: [
cartodbInteractivityLayer,
cartodbLayer,
mapnikInteractivityLayer
]
},
{
desc: 'mapnik type interactivity layers + torque',
layers: [
mapnikInteractivityLayer,
cartodbInteractivityLayer,
torqueLayer
]
},
{
desc: 'mapnik type http + interactivity + torque + interactivity',
layers: [
httpLayer,
mapnikInteractivityLayer,
torqueLayer,
cartodbInteractivityLayer
]
},
{
desc: 'no type two layers, interactivity mix',
layers: [
noTypeLayer,
noTypeInteractivityLayer
]
},
{
desc: 'no type mix of no interactivity with interactivity',
layers: [
noTypeInteractivityLayer,
noTypeLayer,
mapnikInteractivityLayer
]
},
{
desc: 'no type interactivity layers + torque',
layers: [
noTypeLayer,
noTypeInteractivityLayer,
torqueLayer
]
},
{
desc: 'no type http + interactivity + torque + interactivity',
layers: [
httpLayer,
noTypeInteractivityLayer,
torqueLayer,
noTypeInteractivityLayer
]
}
];
var chaosScenariosSize = 25;
var chaosScenarios = [];
for (var i = 0; i < chaosScenariosSize; i++) {
// Underscore.js' sample method uses Fisher-Yates shuffle internally, see http://bost.ocks.org/mike/shuffle/
var randomLayers = _.sample(allLayers, _.random(1, allLayers.length));
chaosScenarios.push({
desc: 'chaos scenario layer types: ' + randomLayers.map(layerType).join(', '),
layers: randomLayers
});
}
testScenarios.forEach(testInteractivityLayersOrderScenario);
chaosScenarios.forEach(testInteractivityLayersOrderScenario);
});