diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-06-26 12:57:35 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-06-26 12:57:44 +0200 |
commit | 543bc8609867032eb8e4c4ecc0466ead2fa0d31e (patch) | |
tree | a05adb958c8061a3edc87b0c87c73f976c6df57b /server/sonar-web/src/test | |
parent | 7593e2b973f61022d24d3e53f4323986ee3acf19 (diff) | |
download | sonarqube-543bc8609867032eb8e4c4ecc0466ead2fa0d31e.tar.gz sonarqube-543bc8609867032eb8e4c4ecc0466ead2fa0d31e.zip |
add histogram widget web tests
Diffstat (limited to 'server/sonar-web/src/test')
4 files changed, 280 insertions, 0 deletions
diff --git a/server/sonar-web/src/test/js/histogram-spec.js b/server/sonar-web/src/test/js/histogram-spec.js new file mode 100644 index 00000000000..78f2d650755 --- /dev/null +++ b/server/sonar-web/src/test/js/histogram-spec.js @@ -0,0 +1,130 @@ +/* global describe:false, it:false */ +var lib = require('../lib'); + +describe('Histogram Widget', function () { + + it('should be displayed', 7, function (casper, test) { + return casper + .start(lib.buildUrl('base'), function () { + lib.setDefaultViewport(); + lib.fmock('/measures/search_filter', 'search-filter.json'); + }) + + .then(function () { + casper.evaluate(function () { + d3.json = function (url, callback) { + return jQuery.get(url).done(function (r) { + callback(null, r); + }); + }; + + var widget = new window.SonarWidgets.Widget(); + var metrics = ['sqale_index']; + + widget + .type('Histogram') + .source(baseUrl + '/measures/search_filter') + .metricsPriority(metrics) + .options({ + baseUrl: baseUrl + '/dashboard/index', + relativeScale: false, + maxItemsReachedMessage: '', + noData: '', + noMainMetric: false + }) + .render('#content'); + }); + }) + + .then(function () { + casper.waitForSelector('.sonar-d3'); + }) + + .then(function () { + test.assertElementCount('.sonar-d3 .bar', 3); + test.assertSelectorContains('.sonar-d3 .bar:nth-child(1)', 'A'); + test.assertSelectorContains('.sonar-d3 .bar:nth-child(1)', '17d'); + test.assertSelectorContains('.sonar-d3 .bar:nth-child(2)', 'B'); + test.assertSelectorContains('.sonar-d3 .bar:nth-child(2)', '5d 1h'); + test.assertSelectorContains('.sonar-d3 .bar:nth-child(3)', 'C'); + test.assertSelectorContains('.sonar-d3 .bar:nth-child(3)', '7h 15min'); + }); + }); + + it('should display a message when no data', 0, function (casper, test) { + return casper + .start(lib.buildUrl('base'), function () { + lib.setDefaultViewport(); + lib.fmock('/measures/search_filter', 'search-filter-no-data.json'); + }) + + .then(function () { + casper.evaluate(function () { + d3.json = function (url, callback) { + return jQuery.get(url).done(function (r) { + callback(null, r); + }); + }; + + var widget = new window.SonarWidgets.Widget(); + var metrics = ['sqale_index']; + + widget + .type('Histogram') + .source(baseUrl + '/measures/search_filter') + .metricsPriority(metrics) + .options({ + baseUrl: baseUrl + '/dashboard/index', + relativeScale: false, + maxItemsReachedMessage: '', + noData: '', + noMainMetric: 'NO_MAIN_METRIC' + }) + .render('#content'); + }); + }) + + .then(function () { + casper.waitForText('NO_MAIN_METRIC'); + }); + }); + + it('should display a "max results reached" message', 0, function (casper, test) { + return casper + .start(lib.buildUrl('base'), function () { + lib.setDefaultViewport(); + lib.fmock('/measures/search_filter', 'search-filter-max-results-reached.json'); + }) + + .then(function () { + casper.evaluate(function () { + d3.json = function (url, callback) { + return jQuery.get(url).done(function (r) { + callback(null, r); + }); + }; + + var widget = new window.SonarWidgets.Widget(); + var metrics = ['sqale_index']; + + widget + .type('Histogram') + .source(baseUrl + '/measures/search_filter') + .metricsPriority(metrics) + .options({ + baseUrl: baseUrl + '/dashboard/index', + relativeScale: false, + maxItemsReachedMessage: 'MAX_RESULTS_REACHED', + noData: '', + noMainMetric: '' + }) + .render('#content'); + }); + }) + + .then(function () { + casper.waitForText('MAX_RESULTS_REACHED'); + }); + }); + +}); diff --git a/server/sonar-web/src/test/json/histogram-spec/search-filter-max-results-reached.json b/server/sonar-web/src/test/json/histogram-spec/search-filter-max-results-reached.json new file mode 100644 index 00000000000..182fda3fad8 --- /dev/null +++ b/server/sonar-web/src/test/json/histogram-spec/search-filter-max-results-reached.json @@ -0,0 +1,55 @@ +{ + "metrics": { + "sqale_index": { + "name": "Technical Debt", + "type": "WORK_DUR", + "direction": -1, + "bestValue": 0 + } + }, + "components": [ + { + "key": "a", + "name": "A", + "longName": "A", + "qualifier": "TRK", + "measures": { + "sqale_index": { + "val": 8600, + "fval": "17d" + } + } + }, + { + "key": "b", + "name": "B", + "longName": "B", + "qualifier": "TRK", + "measures": { + "sqale_index": { + "val": 2465, + "fval": "5d 1h" + } + } + }, + { + "key": "c", + "name": "C", + "longName": "C", + "qualifier": "TRK", + "measures": { + "sqale_index": { + "val": 435, + "fval": "7h 15min" + } + } + } + ], + "maxResultsReached": true, + "paging": { + "page": 1, + "pages": 10, + "pageSize": 3, + "total": 30 + } +} diff --git a/server/sonar-web/src/test/json/histogram-spec/search-filter-no-data.json b/server/sonar-web/src/test/json/histogram-spec/search-filter-no-data.json new file mode 100644 index 00000000000..ca64689619f --- /dev/null +++ b/server/sonar-web/src/test/json/histogram-spec/search-filter-no-data.json @@ -0,0 +1,40 @@ +{ + "metrics": { + "sqale_index": { + "name": "Technical Debt", + "type": "WORK_DUR", + "direction": -1, + "bestValue": 0 + } + }, + "components": [ + { + "key": "a", + "name": "A", + "longName": "A", + "qualifier": "TRK", + "measures": {} + }, + { + "key": "b", + "name": "B", + "longName": "B", + "qualifier": "TRK", + "measures": {} + }, + { + "key": "c", + "name": "C", + "longName": "C", + "qualifier": "TRK", + "measures": {} + } + ], + "maxResultsReached": false, + "paging": { + "page": 1, + "pages": 1, + "pageSize": 40, + "total": 3 + } +} diff --git a/server/sonar-web/src/test/json/histogram-spec/search-filter.json b/server/sonar-web/src/test/json/histogram-spec/search-filter.json new file mode 100644 index 00000000000..aa2bd6876c4 --- /dev/null +++ b/server/sonar-web/src/test/json/histogram-spec/search-filter.json @@ -0,0 +1,55 @@ +{ + "metrics": { + "sqale_index": { + "name": "Technical Debt", + "type": "WORK_DUR", + "direction": -1, + "bestValue": 0 + } + }, + "components": [ + { + "key": "a", + "name": "A", + "longName": "A", + "qualifier": "TRK", + "measures": { + "sqale_index": { + "val": 8600, + "fval": "17d" + } + } + }, + { + "key": "b", + "name": "B", + "longName": "B", + "qualifier": "TRK", + "measures": { + "sqale_index": { + "val": 2465, + "fval": "5d 1h" + } + } + }, + { + "key": "c", + "name": "C", + "longName": "C", + "qualifier": "TRK", + "measures": { + "sqale_index": { + "val": 435, + "fval": "7h 15min" + } + } + } + ], + "maxResultsReached": false, + "paging": { + "page": 1, + "pages": 1, + "pageSize": 40, + "total": 3 + } +} |