2018-10-24 00:39:02 +08:00
|
|
|
'use strict';
|
|
|
|
|
2017-05-18 02:16:43 +08:00
|
|
|
var assert = require('assert');
|
2019-10-07 17:29:07 +08:00
|
|
|
var MapnikLayerStats = require('../../../../lib/backends/layer-stats/mapnik-layer-stats');
|
2017-05-18 02:16:43 +08:00
|
|
|
var MapConfig = require('windshaft').model.MapConfig;
|
|
|
|
|
|
|
|
function getDbConnectionMock () {
|
|
|
|
return {
|
2019-10-22 01:07:24 +08:00
|
|
|
query: function (sql, callback) {
|
2017-05-18 02:16:43 +08:00
|
|
|
return callback(null, {
|
2019-10-22 01:07:24 +08:00
|
|
|
rows: [{ rows: 1 }]
|
2017-05-18 02:16:43 +08:00
|
|
|
});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
describe('mapnik-layer-stats', function () {
|
2017-05-18 02:16:43 +08:00
|
|
|
beforeEach(function () {
|
|
|
|
this.dbConnectionMock = getDbConnectionMock();
|
|
|
|
this.rendererCacheMock = {};
|
|
|
|
this.params = {};
|
|
|
|
});
|
|
|
|
|
|
|
|
var testMapConfigOneLayer = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
var testMapConfigTwoLayers = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.3.0'
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-05-18 02:16:43 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
var testMapConfigOneLayerTwoTables = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
affected_tables: ['test_table_1', 'test_table_2']
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-05-18 02:16:43 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
|
|
|
var testMapConfigTwoLayerTwoTables = {
|
|
|
|
version: '1.5.0',
|
|
|
|
layers: [
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
affected_tables: ['test_table_1', 'test_table_2']
|
|
|
|
}
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'mapnik',
|
|
|
|
options: {
|
|
|
|
sql: 'select * from test_table limit 2',
|
|
|
|
cartocss: '#layer { marker-fill:red; marker-width:32; marker-allow-overlap:true; }',
|
|
|
|
cartocss_version: '2.3.0',
|
|
|
|
affected_tables: ['test_table_3', 'test_table_4']
|
|
|
|
}
|
2019-10-22 01:07:24 +08:00
|
|
|
}
|
2017-05-18 02:16:43 +08:00
|
|
|
]
|
|
|
|
};
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return 1 feature for one layer', function (done) {
|
2017-05-18 02:16:43 +08:00
|
|
|
var mapConfig = MapConfig.create(testMapConfigOneLayer);
|
|
|
|
var layer = mapConfig.getLayer(0);
|
|
|
|
var testSubject = new MapnikLayerStats();
|
2019-10-22 01:07:24 +08:00
|
|
|
testSubject.getStats(layer, this.dbConnectionMock, function (err, result) {
|
2017-05-18 02:16:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.estimatedFeatureCount, 1);
|
2017-05-18 02:16:43 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return 1 feature for two layers', function (done) {
|
2017-05-18 02:16:43 +08:00
|
|
|
var self = this;
|
|
|
|
var mapConfig = MapConfig.create(testMapConfigTwoLayers);
|
|
|
|
var layer0 = mapConfig.getLayer(0);
|
|
|
|
var layer1 = mapConfig.getLayer(1);
|
|
|
|
var testSubject = new MapnikLayerStats();
|
2019-10-22 01:07:24 +08:00
|
|
|
testSubject.getStats(layer0, self.dbConnectionMock, function (err, result) {
|
2017-05-18 02:16:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.estimatedFeatureCount, 1);
|
2019-10-22 01:07:24 +08:00
|
|
|
testSubject.getStats(layer1, self.dbConnectionMock, function (err, result) {
|
2017-05-18 02:16:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.estimatedFeatureCount, 1);
|
2017-05-18 02:16:43 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return 1 feature for one layers with two tables', function (done) {
|
2017-05-18 02:16:43 +08:00
|
|
|
var mapConfig = MapConfig.create(testMapConfigOneLayerTwoTables);
|
|
|
|
var layer = mapConfig.getLayer(0);
|
|
|
|
var testSubject = new MapnikLayerStats();
|
2019-10-22 01:07:24 +08:00
|
|
|
testSubject.getStats(layer, this.dbConnectionMock, function (err, result) {
|
2017-05-18 02:16:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.estimatedFeatureCount, 1);
|
2017-05-18 02:16:43 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2019-10-22 01:07:24 +08:00
|
|
|
it('should return 1 feature for two layers and two tables', function (done) {
|
2017-05-18 02:16:43 +08:00
|
|
|
var self = this;
|
|
|
|
var mapConfig = MapConfig.create(testMapConfigTwoLayerTwoTables);
|
|
|
|
var layer0 = mapConfig.getLayer(0);
|
|
|
|
var layer1 = mapConfig.getLayer(1);
|
|
|
|
var testSubject = new MapnikLayerStats();
|
2019-10-22 01:07:24 +08:00
|
|
|
testSubject.getStats(layer0, self.dbConnectionMock, function (err, result) {
|
2017-05-18 02:16:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.estimatedFeatureCount, 1);
|
2019-10-22 01:07:24 +08:00
|
|
|
testSubject.getStats(layer1, self.dbConnectionMock, function (err, result) {
|
2017-05-18 02:16:43 +08:00
|
|
|
assert.ifError(err);
|
2019-10-22 01:41:03 +08:00
|
|
|
assert.strictEqual(result.estimatedFeatureCount, 1);
|
2017-05-18 02:16:43 +08:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|