From f42d20f2c3250b2e2b8e3130bb8baf2d4fbd8432 Mon Sep 17 00:00:00 2001 From: Raul Ochoa Date: Fri, 5 Feb 2016 13:24:39 +0100 Subject: [PATCH] Histograms in their own file --- test/acceptance/widgets/histogram.js | 120 +++++++++++++++++++++++++++ test/acceptance/widgets/list.js | 4 +- test/acceptance/widgets/widgets.js | 111 +------------------------ 3 files changed, 125 insertions(+), 110 deletions(-) create mode 100644 test/acceptance/widgets/histogram.js diff --git a/test/acceptance/widgets/histogram.js b/test/acceptance/widgets/histogram.js new file mode 100644 index 00000000..0eeb4ca6 --- /dev/null +++ b/test/acceptance/widgets/histogram.js @@ -0,0 +1,120 @@ +require('../../support/test_helper'); + +var assert = require('../../support/assert'); +var TestClient = require('../../support/test-client'); + +describe('histogram widgets', function() { + + it("should expose layer histogram", function(done) { + var histogramMapConfig = { + 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); + + testClient.getWidget('pop_max', function(err, res) { + if (err) { + return done(err); + } + + var histogram = JSON.parse(res.body); + assert.ok(histogram.bins.length); + + testClient.drain(done); + }); + }); + + describe('filters', function() { + + describe('range', function() { + var histogramMapConfig = { + 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' + } + } + } + } + } + ] + }; + + it("should expose an histogram", function(done) { + var testClient = new TestClient(histogramMapConfig); + testClient.getWidget('country_places_histogram', { own_filter: 0 }, function(err, res) { + if (err) { + return done(err); + } + + var histogram = JSON.parse(res.body); + // notice min value + assert.deepEqual( + histogram.bins[0], + { bin: 0, freq: 6497, min: 0, max: 742572, avg: 113511.16823149147 } + ); + + testClient.drain(done); + }); + }); + + it("should expose a filtered histogram", function(done) { + var params = { + filters: { + layers: [ + { + country_places_histogram: { min: 4000000 } + } + ] + } + }; + var testClient = new TestClient(histogramMapConfig); + testClient.getWidget('country_places_histogram', params, function(err, res) { + if (err) { + return done(err); + } + + var histogram = JSON.parse(res.body); + // notice min value + assert.deepEqual(histogram.bins[0], { + bin: 0, + freq: 62, + min: 4000000, + max: 9276403, + avg: 5815009.596774193 + }); + + testClient.drain(done); + }); + }); + }); + }); + +}); diff --git a/test/acceptance/widgets/list.js b/test/acceptance/widgets/list.js index 8d5aab07..87fbf7df 100644 --- a/test/acceptance/widgets/list.js +++ b/test/acceptance/widgets/list.js @@ -1,7 +1,9 @@ +require('../../support/test_helper'); + var assert = require('../../support/assert'); var TestClient = require('../../support/test-client'); -describe('widget list', function() { +describe('list widgets', function() { it("should expose layer list", function(done) { diff --git a/test/acceptance/widgets/widgets.js b/test/acceptance/widgets/widgets.js index fc6263e8..7639561c 100644 --- a/test/acceptance/widgets/widgets.js +++ b/test/acceptance/widgets/widgets.js @@ -1,45 +1,10 @@ +require('../../support/test_helper'); + var assert = require('../../support/assert'); var TestClient = require('../../support/test-client'); describe('widgets', function() { - it("should expose layer histogram", function(done) { - var histogramMapConfig = { - 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); - - testClient.getWidget('pop_max', function(err, res) { - if (err) { - return done(err); - } - - var histogram = JSON.parse(res.body); - assert.ok(histogram.bins.length); - - testClient.drain(done); - }); - }); - describe('filters', function() { describe('category', function() { @@ -104,78 +69,6 @@ describe('widgets', function() { }); }); - describe('range', function() { - var histogramMapConfig = { - 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' - } - } - } - } - } - ] - }; - - it("should expose an histogram", function(done) { - var testClient = new TestClient(histogramMapConfig); - testClient.getWidget('country_places_histogram', { own_filter: 0 }, function(err, res) { - if (err) { - return done(err); - } - - var histogram = JSON.parse(res.body); - // notice min value - assert.deepEqual( - histogram.bins[0], - { bin: 0, freq: 6497, min: 0, max: 742572, avg: 113511.16823149147 } - ); - - testClient.drain(done); - }); - }); - - it("should expose a filtered histogram", function(done) { - var params = { - filters: { - layers: [ - { - country_places_histogram: { min: 4000000 } - } - ] - } - }; - var testClient = new TestClient(histogramMapConfig); - testClient.getWidget('country_places_histogram', params, function(err, res) { - if (err) { - return done(err); - } - - var histogram = JSON.parse(res.body); - // notice min value - assert.deepEqual(histogram.bins[0], { - bin: 0, - freq: 62, - min: 4000000, - max: 9276403, - avg: 5815009.596774193 - }); - - testClient.drain(done); - }); - }); - }); - describe('combine widget filters', function() { var combinedWidgetsMapConfig = { version: '1.5.0',