Windshaft-cartodb/test/unit/mapconfig/dataviews-widgets-adapter-test.js

260 lines
9.6 KiB
JavaScript
Raw Normal View History

'use strict';
2019-10-22 01:07:24 +08:00
// require('../../../support/test-helper');
var assert = require('assert');
2019-10-07 17:29:07 +08:00
var DataviewsMapConfigAdapter = require('../../../lib/models/mapconfig/adapter/dataviews-widgets-adapter');
2019-10-22 01:07:24 +08:00
describe('dataviews-widgets-adapter', function () {
var widgetsMapConfigs = [
{
2019-10-22 01:07:24 +08:00
input: {
version: '1.4.0',
layers: [
{
2019-10-22 01:07:24 +08:00
type: 'mapnik',
options: {
sql: 'select * from populated_places_simple_reduced',
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
cartocss_version: '2.3.0',
widgets: {
country_places_count: {
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
}
}
}
}
]
},
2019-10-22 01:07:24 +08:00
expected: {
version: '1.4.0',
layers: [
{
2019-10-22 01:07:24 +08:00
type: 'mapnik',
options: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
cartocss_version: '2.3.0',
// keep them for now
2019-10-22 01:07:24 +08:00
widgets: {
country_places_count: {
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
}
}
}
}
],
2019-10-22 01:07:24 +08:00
analyses: [
{
2019-10-22 01:07:24 +08:00
id: 'cdb-layer-source-0',
type: 'source',
params: {
query: 'select * from populated_places_simple_reduced'
}
}
],
2019-10-22 01:07:24 +08:00
dataviews: {
country_places_count: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
}
}
}
},
{
2019-10-22 01:07:24 +08:00
input: {
version: '1.4.0',
layers: [
{
2019-10-22 01:07:24 +08:00
type: 'mapnik',
options: {
sql: 'select * from populated_places_simple_reduced',
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
cartocss_version: '2.3.0',
widgets: {
pop_max: {
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
]
},
2019-10-22 01:07:24 +08:00
expected: {
version: '1.4.0',
layers: [
{
2019-10-22 01:07:24 +08:00
type: 'mapnik',
options: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
cartocss_version: '2.3.0',
// keep them for now
2019-10-22 01:07:24 +08:00
widgets: {
pop_max: {
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
],
2019-10-22 01:07:24 +08:00
analyses: [
{
2019-10-22 01:07:24 +08:00
id: 'cdb-layer-source-0',
type: 'source',
params: {
query: 'select * from populated_places_simple_reduced'
}
}
],
2019-10-22 01:07:24 +08:00
dataviews: {
pop_max: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
},
{
2019-10-22 01:07:24 +08:00
input: {
version: '1.4.0',
layers: [
{
2019-10-22 01:07:24 +08:00
type: 'mapnik',
options: {
sql: 'select * from populated_places_simple_reduced',
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
cartocss_version: '2.3.0',
widgets: {
country_places_count: {
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
},
2019-10-22 01:07:24 +08:00
country_places_histogram: {
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
]
},
2019-10-22 01:07:24 +08:00
expected: {
version: '1.4.0',
layers: [
{
2019-10-22 01:07:24 +08:00
type: 'mapnik',
options: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
cartocss: '#layer { marker-fill: red; marker-width: 32; marker-allow-overlap: true; }',
cartocss_version: '2.3.0',
// keep them for now
2019-10-22 01:07:24 +08:00
widgets: {
country_places_count: {
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
},
2019-10-22 01:07:24 +08:00
country_places_histogram: {
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
],
2019-10-22 01:07:24 +08:00
analyses: [
{
2019-10-22 01:07:24 +08:00
id: 'cdb-layer-source-0',
type: 'source',
params: {
query: 'select * from populated_places_simple_reduced'
}
}
],
2019-10-22 01:07:24 +08:00
dataviews: {
country_places_count: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
type: 'aggregation',
options: {
column: 'adm0_a3',
aggregation: 'count'
}
},
2019-10-22 01:07:24 +08:00
country_places_histogram: {
source: {
id: 'cdb-layer-source-0'
},
2019-10-22 01:07:24 +08:00
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
];
var user = 'wadus';
2019-10-22 01:07:24 +08:00
function params () {
return {};
}
2019-10-22 01:07:24 +08:00
function context () {
return {};
}
var dataviewsMapConfigAdapter = new DataviewsMapConfigAdapter();
2019-10-22 01:07:24 +08:00
widgetsMapConfigs.forEach(function (mapConfig, index) {
it('should adapt widgets ' + index, function (done) {
dataviewsMapConfigAdapter.getMapConfig(user, mapConfig.input, params(), context(), function (err, result) {
2019-10-25 00:38:37 +08:00
assert.ifError(err);
assert.deepStrictEqual(result, mapConfig.expected);
done();
});
});
});
});