Windshaft-cartodb/test/acceptance/widgets/ported/formula-test.js

88 lines
3.0 KiB
JavaScript
Raw Normal View History

'use strict';
require('../../../support/test-helper');
2019-10-22 01:07:24 +08:00
var assert = require('../../../support/assert');
var TestClient = require('../../../support/test-client');
2019-10-22 01:07:24 +08:00
describe('widgets', function () {
describe('formula', function () {
afterEach(function (done) {
if (this.testClient) {
this.testClient.drain(done);
} else {
done();
}
});
2019-10-22 01:07:24 +08:00
function widgetsMapConfig (widgets) {
return {
version: '1.5.0',
layers: [
{
type: 'mapnik',
options: {
sql: 'select * from populated_places_simple_reduced where pop_max > 0 and pop_max < 600000',
cartocss: '#layer0 { marker-fill: red; marker-width: 10; }',
cartocss_version: '2.0.1',
widgets: widgets
}
}
]
};
}
var operations = {
min: [10, 0],
max: [599579, 0],
count: [5822, 0],
avg: [112246.00893163861, 0],
sum: [653496264, 0]
};
2019-10-22 01:07:24 +08:00
Object.keys(operations).forEach(function (operation) {
it('should do ' + operation + ' over column', function (done) {
var widgets = {
pop_max_f: {
type: 'formula',
options: {
column: 'pop_max',
operation: operation
}
}
};
this.testClient = new TestClient(widgetsMapConfig(widgets));
this.testClient.getWidget('pop_max_f', function (err, res, result) {
assert.ok(!err, err);
assert.strictEqual(result.operation, operation);
assert.strictEqual(result.result, operations[operation][0]);
assert.strictEqual(result.nulls, operations[operation][1]);
done();
});
});
});
2019-10-22 01:07:24 +08:00
it('does not require column for count formula', function (done) {
var operation = 'count';
var widgets = {
pop_max_count_f: {
type: 'formula',
options: {
operation: operation
}
}
};
this.testClient = new TestClient(widgetsMapConfig(widgets));
this.testClient.getWidget('pop_max_count_f', function (err, res, result) {
assert.ok(!err, err);
assert.strictEqual(result.operation, operation);
assert.strictEqual(result.result, operations[operation][0]);
assert.strictEqual(result.nulls, operations[operation][1]);
done();
});
});
});
});