Windshaft-cartodb/test/acceptance/widgets/aggregation-test.js

73 lines
2.5 KiB
JavaScript
Raw Normal View History

'use strict';
require('../../support/test-helper');
2016-02-05 20:32:38 +08:00
var assert = require('../../support/assert');
var TestClient = require('../../support/test-client');
2019-10-22 01:07:24 +08:00
describe('aggregation widgets', function () {
var aggregationMapConfig = {
2016-02-05 20:32:38 +08:00
version: '1.5.0',
layers: [
{
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
it('should expose an aggregation', function (done) {
2016-02-05 20:32:38 +08:00
var testClient = new TestClient(aggregationMapConfig);
2019-10-22 01:07:24 +08:00
testClient.getWidget('country_places_count', { own_filter: 0 }, function (err, res) {
2016-02-05 20:32:38 +08:00
if (err) {
return done(err);
}
var aggregation = JSON.parse(res.body);
assert.strictEqual(aggregation.categories.length, 6);
2016-02-05 20:32:38 +08:00
assert.deepEqual(aggregation.categories[0], { value: 769, category: 'USA', agg: false });
testClient.drain(done);
});
});
2019-10-22 01:07:24 +08:00
describe('filters', function () {
2016-02-05 20:32:38 +08:00
describe('category', function () {
2019-10-22 01:07:24 +08:00
it('should expose a filtered aggregation', function (done) {
2016-02-05 20:32:38 +08:00
var params = {
filters: {
layers: [
2019-10-22 01:07:24 +08:00
{ country_places_count: { accept: ['CAN'] } }
2016-02-05 20:32:38 +08:00
]
}
};
var testClient = new TestClient(aggregationMapConfig);
testClient.getWidget('country_places_count', params, function (err, res) {
if (err) {
return done(err);
}
var aggregation = JSON.parse(res.body);
assert.strictEqual(aggregation.categories.length, 1);
2016-02-05 20:32:38 +08:00
assert.deepEqual(aggregation.categories[0], { value: 256, category: 'CAN', agg: false });
testClient.drain(done);
});
});
});
});
});