2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2019-10-07 16:44:45 +08:00
|
|
|
require('../../support/test-helper');
|
2016-02-05 20:24:39 +08:00
|
|
|
|
2016-02-05 19:35:01 +08:00
|
|
|
var assert = require('../../support/assert');
|
2016-02-05 19:59:33 +08:00
|
|
|
var TestClient = require('../../support/test-client');
|
2015-10-07 01:47:44 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('widget filters', function () {
|
|
|
|
describe('combine widget filters', function () {
|
|
|
|
var combinedWidgetsMapConfig = {
|
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'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
country_places_histogram: {
|
|
|
|
type: 'histogram',
|
|
|
|
options: {
|
|
|
|
column: 'pop_max'
|
2015-10-27 20:18:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2016-02-05 20:32:38 +08:00
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
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: [
|
|
|
|
{
|
|
|
|
country_places_count: { reject: ['CHN'] }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
}
|
2015-10-28 02:08:46 +08:00
|
|
|
};
|
2016-02-05 20:32:38 +08:00
|
|
|
var testClient = new TestClient(combinedWidgetsMapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getWidget('country_places_count', params, function (err, res) {
|
2016-02-05 20:32:38 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2015-10-27 20:18:53 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
var aggregation = JSON.parse(res.body);
|
2015-10-27 20:18:53 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// first one would be CHN if reject filter wasn't applied
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.deepEqual(aggregation.categories[0], { value: 769, category: 'USA', agg: false });
|
2015-10-27 20:18:53 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// confirm 'CHN' was filtered out (reject)
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.equal(aggregation.categories.reduce(function (sum, row) {
|
2016-02-05 20:32:38 +08:00
|
|
|
return sum + (row.category === 'CHN' ? 1 : 0);
|
|
|
|
}, 0), 0);
|
2015-10-28 02:08:46 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
testClient.drain(done);
|
2015-10-27 20:18:53 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
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: [
|
|
|
|
{
|
|
|
|
country_places_count: { reject: ['CHN'] },
|
|
|
|
country_places_histogram: { min: 7000000 }
|
2015-10-28 19:21:43 +08:00
|
|
|
}
|
2016-02-05 20:32:38 +08:00
|
|
|
]
|
|
|
|
}
|
2015-10-28 19:21:43 +08:00
|
|
|
};
|
2016-02-05 20:32:38 +08:00
|
|
|
var testClient = new TestClient(combinedWidgetsMapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getWidget('country_places_count', params, function (err, res) {
|
2016-02-05 20:32:38 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2015-10-28 19:21:43 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
var aggregation = JSON.parse(res.body);
|
2015-10-29 23:25:56 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// first one would be CHN if reject filter wasn't applied
|
|
|
|
assert.deepEqual(aggregation.categories[0], { value: 4, category: 'IND', agg: false });
|
2015-10-29 23:25:56 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// confirm 'CHN' was filtered out (reject)
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.equal(aggregation.categories.reduce(function (sum, row) {
|
2016-02-05 20:32:38 +08:00
|
|
|
return sum + (row.category === 'CHN' ? 1 : 0);
|
|
|
|
}, 0), 0);
|
2015-10-29 23:25:56 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
testClient.drain(done);
|
2015-10-28 19:21:43 +08:00
|
|
|
});
|
2016-02-05 20:32:38 +08:00
|
|
|
});
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should allow to filter by bounding box a filtered aggregation', function (done) {
|
2016-02-05 20:32:38 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
country_places_histogram: { min: 50000 }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
bbox: '-20,0,45,60'
|
|
|
|
};
|
|
|
|
var testClient = new TestClient(combinedWidgetsMapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getWidget('country_places_count', params, function (err, res) {
|
2016-02-05 20:32:38 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
var aggregation = JSON.parse(res.body);
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// first one would be CHN if reject filter wasn't applied
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.deepEqual(aggregation.categories[0], { value: 96, category: 'RUS', agg: false });
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// confirm 'CHN' was filtered out (reject)
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.equal(aggregation.categories.reduce(function (sum, row) {
|
2016-02-05 20:32:38 +08:00
|
|
|
return sum + (row.category === 'CHN' ? 1 : 0);
|
|
|
|
}, 0), 0);
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
testClient.drain(done);
|
2015-10-30 00:18:14 +08:00
|
|
|
});
|
2016-02-05 20:32:38 +08:00
|
|
|
});
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should allow to filter by bounding box a filtered aggregation, with reject', function (done) {
|
2016-02-05 20:32:38 +08:00
|
|
|
var params = {
|
|
|
|
filters: {
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
country_places_count: { reject: ['RUS'] },
|
|
|
|
country_places_histogram: { min: 50000 }
|
|
|
|
}
|
|
|
|
]
|
|
|
|
},
|
|
|
|
bbox: '-20,0,45,60'
|
|
|
|
};
|
|
|
|
var testClient = new TestClient(combinedWidgetsMapConfig);
|
2019-10-22 01:07:24 +08:00
|
|
|
testClient.getWidget('country_places_count', params, function (err, res) {
|
2016-02-05 20:32:38 +08:00
|
|
|
if (err) {
|
|
|
|
return done(err);
|
|
|
|
}
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
var aggregation = JSON.parse(res.body);
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// first one would be CHN if reject filter wasn't applied
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.deepEqual(aggregation.categories[0], { value: 77, category: 'TUR', agg: false });
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
// confirm 'CHN' was filtered out (reject)
|
2019-10-22 01:07:24 +08:00
|
|
|
assert.equal(aggregation.categories.reduce(function (sum, row) {
|
2016-02-05 20:32:38 +08:00
|
|
|
return sum + (row.category === 'CHN' ? 1 : 0);
|
|
|
|
}, 0), 0);
|
2015-10-30 00:18:14 +08:00
|
|
|
|
2016-02-05 20:32:38 +08:00
|
|
|
testClient.drain(done);
|
2015-10-30 00:18:14 +08:00
|
|
|
});
|
2015-10-28 19:21:43 +08:00
|
|
|
});
|
2015-10-27 20:18:53 +08:00
|
|
|
});
|
2015-10-07 01:47:44 +08:00
|
|
|
});
|