Windshaft-cartodb/test/acceptance/analysis/analysis-layers-dataviews-test.js

150 lines
4.3 KiB
JavaScript
Raw Normal View History

'use strict';
require('../../support/test-helper');
var assert = require('../../support/assert');
var TestClient = require('../../support/test-client');
var dot = require('dot');
2019-10-22 01:07:24 +08:00
describe('analysis-layers-dataviews', function () {
var multitypeStyleTemplate = dot.template([
"#points['mapnik::geometry_type'=1] {",
2019-10-22 01:07:24 +08:00
' marker-fill-opacity: {{=it._opacity}};',
' marker-line-color: #FFF;',
' marker-line-width: 0.5;',
' marker-line-opacity: {{=it._opacity}};',
' marker-placement: point;',
' marker-type: ellipse;',
' marker-width: 8;',
' marker-fill: {{=it._color}};',
' marker-allow-overlap: true;',
'}',
"#lines['mapnik::geometry_type'=2] {",
2019-10-22 01:07:24 +08:00
' line-color: {{=it._color}};',
' line-width: 2;',
' line-opacity: {{=it._opacity}};',
'}',
"#polygons['mapnik::geometry_type'=3] {",
2019-10-22 01:07:24 +08:00
' polygon-fill: {{=it._color}};',
' polygon-opacity: {{=it._opacity}};',
' line-color: #FFF;',
' line-width: 0.5;',
' line-opacity: {{=it._opacity}};',
'}'
].join('\n'));
2019-10-22 01:07:24 +08:00
function cartocss (color, opacity) {
return multitypeStyleTemplate({
_color: color || '#F11810',
_opacity: Number.isFinite(opacity) ? opacity : 1
});
}
2019-10-22 01:07:24 +08:00
function createMapConfig (layers, dataviews, analysis) {
return {
version: '1.5.0',
layers: layers,
dataviews: dataviews || {},
analyses: analysis || []
};
}
var DEFAULT_MULTITYPE_STYLE = cartocss();
var mapConfig = createMapConfig(
[
{
2019-10-22 01:07:24 +08:00
type: 'cartodb',
options: {
source: {
id: '2570e105-7b37-40d2-bdf4-1af889598745'
},
2019-10-22 01:07:24 +08:00
cartocss: DEFAULT_MULTITYPE_STYLE,
cartocss_version: '2.3.0'
}
}
],
{
pop_max_histogram: {
source: {
id: '2570e105-7b37-40d2-bdf4-1af889598745'
},
type: 'histogram',
options: {
column: 'pop_max'
}
}
},
[
{
2019-10-22 01:07:24 +08:00
id: '2570e105-7b37-40d2-bdf4-1af889598745',
type: 'source',
params: {
query: 'select * from populated_places_simple_reduced'
}
}
]
);
2019-10-22 01:07:24 +08:00
it('should get histogram dataview', function (done) {
var testClient = new TestClient(mapConfig, 1234);
2019-10-22 01:07:24 +08:00
testClient.getDataview('pop_max_histogram', function (err, dataview) {
assert.ok(!err, err);
assert.strictEqual(dataview.type, 'histogram');
assert.strictEqual(dataview.bins_start, 0);
testClient.drain(done);
});
});
2019-10-22 01:07:24 +08:00
it('should get a filtered histogram dataview', function (done) {
var testClient = new TestClient(mapConfig, 1234);
var params = {
filters: {
dataviews: {
pop_max_histogram: {
min: 2e6
}
}
2017-12-13 17:43:43 +08:00
},
own_filter: 1
};
2019-10-22 01:07:24 +08:00
testClient.getDataview('pop_max_histogram', params, function (err, dataview) {
assert.ok(!err, err);
assert.strictEqual(dataview.type, 'histogram');
assert.strictEqual(dataview.bins_start, 2008000);
testClient.drain(done);
});
});
2016-03-19 00:49:20 +08:00
2019-10-22 01:07:24 +08:00
it('should skip the filter when sending own_filter=0 for histogram dataview', function (done) {
2016-03-19 00:49:20 +08:00
var testClient = new TestClient(mapConfig, 1234);
var params = {
filters: {
dataviews: {
pop_max_histogram: {
min: 2e6
}
}
},
own_filter: 0
};
2019-10-22 01:07:24 +08:00
testClient.getDataview('pop_max_histogram', params, function (err, dataview) {
2016-03-19 00:49:20 +08:00
assert.ok(!err, err);
assert.strictEqual(dataview.type, 'histogram');
assert.strictEqual(dataview.bins_start, 0);
2016-03-19 00:49:20 +08:00
testClient.drain(done);
});
});
});