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

148 lines
5.1 KiB
JavaScript
Raw Normal View History

'use strict';
require('../../support/test-helper');
2016-02-05 20:24:39 +08:00
var assert = require('../../support/assert');
var TestClient = require('../../support/test-client');
2019-10-22 01:07:24 +08:00
describe('histogram widgets', function () {
it('should expose layer histogram', function (done) {
var histogramMapConfig = {
2016-02-05 20:24:39 +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: {
pop_max: {
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
]
};
var testClient = new TestClient(histogramMapConfig);
2019-10-22 01:07:24 +08:00
testClient.getWidget('pop_max', function (err, res) {
2016-02-05 20:24:39 +08:00
if (err) {
return done(err);
}
var histogram = JSON.parse(res.body);
assert.ok(histogram.bins.length);
testClient.drain(done);
});
});
2019-10-22 01:07:24 +08:00
describe('filters', function () {
describe('range', function () {
var histogramMapConfig = {
2016-02-05 20:24:39 +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_histogram: {
type: 'histogram',
options: {
column: 'pop_max'
}
}
}
}
}
]
};
2019-10-22 01:07:24 +08:00
it('should expose an histogram', function (done) {
2016-02-05 20:24:39 +08:00
var testClient = new TestClient(histogramMapConfig);
2019-10-22 01:07:24 +08:00
testClient.getWidget('country_places_histogram', { own_filter: 0 }, function (err, res) {
2016-02-05 20:24:39 +08:00
if (err) {
return done(err);
}
var histogram = JSON.parse(res.body);
// notice min value
assert.deepStrictEqual(
2016-02-05 20:24:39 +08:00
histogram.bins[0],
{ bin: 0, freq: 6497, min: 0, max: 742572, avg: 113511.16823149147 }
);
testClient.drain(done);
});
});
2019-10-22 01:07:24 +08:00
it('should expose a filtered histogram', function (done) {
2016-02-05 20:24:39 +08:00
var params = {
filters: {
layers: [
{
country_places_histogram: { min: 4000000 }
}
]
}
};
var testClient = new TestClient(histogramMapConfig);
2019-10-22 01:07:24 +08:00
testClient.getWidget('country_places_histogram', params, function (err, res) {
2016-02-05 20:24:39 +08:00
if (err) {
return done(err);
}
var histogram = JSON.parse(res.body);
// notice min value
assert.deepStrictEqual(histogram.bins[0], {
2016-02-05 20:24:39 +08:00
bin: 0,
freq: 62,
min: 4000000,
max: 9276403,
avg: 5815009.596774193
});
testClient.drain(done);
});
});
2019-10-22 01:07:24 +08:00
it('should expose a filtered histogram using dataviews for filtering', function (done) {
var params = {
filters: {
dataviews: {
country_places_histogram: { min: 4000000 }
}
}
};
var testClient = new TestClient(histogramMapConfig);
2019-10-22 01:07:24 +08:00
testClient.getWidget('country_places_histogram', params, function (err, res) {
if (err) {
return done(err);
}
var histogram = JSON.parse(res.body);
// notice min value
assert.deepStrictEqual(histogram.bins[0], {
bin: 0,
freq: 62,
min: 4000000,
max: 9276403,
avg: 5815009.596774193
});
testClient.drain(done);
});
});
2016-02-05 20:24:39 +08:00
});
});
});