diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-03-04 16:36:56 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-03-04 16:41:30 +0100 |
commit | 0c69f6ba3bf838cea2737afae2852c1188afdde4 (patch) | |
tree | 4f1be46fe4864152e938fe06be60f3078f0d03bd /server/sonar-web/src/test/js | |
parent | 3ba61ff5e3a64abb4305cf43e2dcd8b7ea986645 (diff) | |
download | sonarqube-0c69f6ba3bf838cea2737afae2852c1188afdde4.tar.gz sonarqube-0c69f6ba3bf838cea2737afae2852c1188afdde4.zip |
SONAR-5726 SONAR-6234 cover some corner cases, add tests
Diffstat (limited to 'server/sonar-web/src/test/js')
-rw-r--r-- | server/sonar-web/src/test/js/global-issue-filter-widget.js | 853 | ||||
-rw-r--r-- | server/sonar-web/src/test/js/project-issue-filter-widget.js | 221 |
2 files changed, 1074 insertions, 0 deletions
diff --git a/server/sonar-web/src/test/js/global-issue-filter-widget.js b/server/sonar-web/src/test/js/global-issue-filter-widget.js new file mode 100644 index 00000000000..ac2f5f78acf --- /dev/null +++ b/server/sonar-web/src/test/js/global-issue-filter-widget.js @@ -0,0 +1,853 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +/* globals casper: false */ + +var lib = require('../lib'), + testName = lib.testName('Global Issue Filter Widget'); + + +lib.initMessages(); +lib.changeWorkingDirectory('global-issues-filter-widget'); +lib.configureCasper(); + + +casper.test.begin(testName('Unresolved Issues By Severity'), 13, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-severity.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'severities' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '1'); + test.assertSelectorContains('tr:nth-child(3)', '105'); + test.assertSelectorContains('tr:nth-child(4)', '5027'); + test.assertSelectorContains('tr:nth-child(5)', '540'); + test.assertSelectorContains('tr:nth-child(6)', '1178'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|severities=BLOCKER"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|severities=CRITICAL"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|severities=MAJOR"]'); + test.assertExists('tr:nth-child(5) a[href="/issues/search#resolved=false|severities=MINOR"]'); + test.assertExists('tr:nth-child(6) a[href="/issues/search#resolved=false|severities=INFO"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Red Issues By Severity'), 9, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'red-issues-by-severity.json', + { data: { resolved: 'false', severities: 'BLOCKER,CRITICAL,MAJOR' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false|severities=BLOCKER,CRITICAL,MAJOR', + distributionAxis: 'severities' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 4); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '1'); + test.assertSelectorContains('tr:nth-child(3)', '105'); + test.assertSelectorContains('tr:nth-child(4)', '5027'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false|severities=BLOCKER%2CCRITICAL%2CMAJOR"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|severities=BLOCKER"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|severities=CRITICAL"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|severities=MAJOR"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('All Issues By Status'), 9, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'all-issues-by-status.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: '', + distributionAxis: 'statuses' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '71571'); + test.assertSelectorContains('tr:nth-child(2)', '238'); + test.assertSelectorContains('tr:nth-child(3)', '4'); + test.assertSelectorContains('tr:nth-child(4)', '6609'); + test.assertSelectorContains('tr:nth-child(5)', '1307'); + test.assertSelectorContains('tr:nth-child(6)', '63.4k'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#statuses=OPEN"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('All Issues By Resolution'), 10, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'all-issues-by-resolution.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: '', + distributionAxis: 'resolutions' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '71571'); + test.assertSelectorContains('tr:nth-child(2)', '6851'); + test.assertSelectorContains('tr:nth-child(3)', '752'); + test.assertSelectorContains('tr:nth-child(4)', '550'); + test.assertSelectorContains('tr:nth-child(5)', '47.1k'); + test.assertSelectorContains('tr:nth-child(6)', '16.3k'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolutions=FALSE-POSITIVE"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Resolution'), 5, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-resolution.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'resolutions' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 2); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '6851'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Rule'), 15, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-rule.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'rules' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 16); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '879'); + test.assertSelectorContains('tr:nth-child(3)', '571'); + test.assertSelectorContains('tr:nth-child(15)', '113'); + test.assertSelectorContains('tr:nth-child(16)', '111'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|rules=squid%3AS1161"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|rules=squid%3AS1135"]'); + test.assertExists('tr:nth-child(15) a[href="/issues/search#resolved=false|rules=squid%3AS1134"]'); + test.assertExists('tr:nth-child(16) a[href="/issues/search#resolved=false|rules=squid%3AS1192"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', '@Override" annotation should be used'); + test.assertSelectorContains('tr:nth-child(3)', 'TODO tags should be handled'); + test.assertSelectorContains('tr:nth-child(15)', 'FIXME tags should be handled'); + test.assertSelectorContains('tr:nth-child(16)', 'String literals should not be duplicated'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Project'), 15, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-project.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'projectUuids' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 5); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '2598'); + test.assertSelectorContains('tr:nth-child(2)', '1766'); + test.assertSelectorContains('tr:nth-child(3)', '442'); + test.assertSelectorContains('tr:nth-child(4)', '283'); + test.assertSelectorContains('tr:nth-child(5)', '107'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|projectUuids=69e57151-be0d-4157-adff-c06741d88879"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|projectUuids=dd7c3556-ce3f-42d0-a348-914a582dc944"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|projectUuids=5eab015a-1f76-4ba4-bd89-bf547132d673"]'); + test.assertExists('tr:nth-child(5) a[href="/issues/search#resolved=false|projectUuids=c156940b-e3ec-43f6-9589-e3b75aa9ca32"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'SonarQube'); + test.assertSelectorContains('tr:nth-child(3)', 'SonarQube Java'); + test.assertSelectorContains('tr:nth-child(4)', 'JavaScript'); + test.assertSelectorContains('tr:nth-child(5)', 'Python'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Assignee'), 15, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-assignee.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'assignees' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 5); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '4134'); + test.assertSelectorContains('tr:nth-child(3)', '698'); + test.assertSelectorContains('tr:nth-child(4)', '504'); + test.assertSelectorContains('tr:nth-child(5)', '426'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|assigned=false"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|assignees=first.user"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|assignees=second.user"]'); + test.assertExists('tr:nth-child(5) a[href="/issues/search#resolved=false|assignees=third.user"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'unassigned'); + test.assertSelectorContains('tr:nth-child(3)', 'First User'); + test.assertSelectorContains('tr:nth-child(4)', 'Second User'); + test.assertSelectorContains('tr:nth-child(5)', 'Third User'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Unassigned Issues By Assignee'), 6, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-unassigned-issues-by-assignee.json', + { data: { resolved: 'false', assigned: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false|assigned=false', + distributionAxis: 'assignees' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 2); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '4134'); + test.assertSelectorContains('tr:nth-child(2)', '4134'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false|assigned=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|assigned=false"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'unassigned'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Language'), 15, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-language.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'languages' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 5); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '6336'); + test.assertSelectorContains('tr:nth-child(3)', '444'); + test.assertSelectorContains('tr:nth-child(4)', '22'); + test.assertSelectorContains('tr:nth-child(5)', '15'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|languages=java"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|languages=py"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|languages=php"]'); + test.assertExists('tr:nth-child(5) a[href="/issues/search#resolved=false|languages=js"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'Java'); + test.assertSelectorContains('tr:nth-child(3)', 'Python'); + test.assertSelectorContains('tr:nth-child(4)', 'PHP'); + test.assertSelectorContains('tr:nth-child(5)', 'JavaScript'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Action Plan'), 15, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-action-plan.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'actionPlans' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 5); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '5877'); + test.assertSelectorContains('tr:nth-child(3)', '532'); + test.assertSelectorContains('tr:nth-child(4)', '56'); + test.assertSelectorContains('tr:nth-child(5)', '52'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|planned=false"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|actionPlans=0cf48508-2fcd-4cb8-a50b-c5cd7c3decc0"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|actionPlans=1b9e7e52-ff58-40c1-80bf-f68429a3275e"]'); + test.assertExists('tr:nth-child(5) a[href="/issues/search#resolved=false|actionPlans=8c1d5d01-948e-4670-a0d9-17c512979486"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'unplanned'); + test.assertSelectorContains('tr:nth-child(3)', 'First Action Plan'); + test.assertSelectorContains('tr:nth-child(4)', 'Second Action Plan'); + test.assertSelectorContains('tr:nth-child(5)', 'Third Action Plan'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Unplanned Issues By Action Plan'), 6, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-unplanned-issues-by-action-plan.json', + { data: { resolved: 'false', planned: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false|planned=false', + distributionAxis: 'actionPlans' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 2); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '5877'); + test.assertSelectorContains('tr:nth-child(2)', '5877'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false|planned=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|planned=false"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'unplanned'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Date'), 18, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-date.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'createdAt' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '72'); + test.assertSelectorContains('tr:nth-child(3)', '64'); + test.assertSelectorContains('tr:nth-child(4)', '1262'); + test.assertSelectorContains('tr:nth-child(5)', '3729'); + test.assertSelectorContains('tr:nth-child(6)', '1724'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|createdAfter=2011-01-01|createdBefore=2011-12-31"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|createdAfter=2012-01-01|createdBefore=2012-12-31"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|createdAfter=2013-01-01|createdBefore=2013-12-31"]'); + test.assertExists('tr:nth-child(5) a[href="/issues/search#resolved=false|createdAfter=2014-01-01|createdBefore=2014-12-31"]'); + // do not check createdBefore value, because it is set dynamically to *now* + test.assertExists('tr:nth-child(6) a[href^="/issues/search#resolved=false|createdAfter=2015-01-01|createdBefore="]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'January 1 2011 – December 31 2011'); + test.assertSelectorContains('tr:nth-child(3)', 'January 1 2012 – December 31 2012'); + test.assertSelectorContains('tr:nth-child(4)', 'January 1 2013 – December 31 2013'); + test.assertSelectorContains('tr:nth-child(5)', 'January 1 2014 – December 31 2014'); + // do not check label fully, because it is set dynamically using *now* + test.assertSelectorContains('tr:nth-child(6)', 'January 1 2015 – '); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues on a Limited Period By Date'), 12, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-date-limited.json', + { data: { resolved: 'false', createdAfter: '2015-02-16', createdBefore: '2015-02-18' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false|createdAfter=2015-02-16|createdBefore=2015-02-18', + distributionAxis: 'createdAt' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 4); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '49'); + test.assertSelectorContains('tr:nth-child(3)', '48'); + test.assertSelectorContains('tr:nth-child(4)', '47'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/issues/search#resolved=false|createdAfter=2015-02-16|createdBefore=2015-02-18"]'); + test.assertExists('tr:nth-child(2) a[href="/issues/search#resolved=false|createdAfter=2015-02-16|createdBefore=2015-02-17"]'); + test.assertExists('tr:nth-child(3) a[href="/issues/search#resolved=false|createdAfter=2015-02-17|createdBefore=2015-02-18"]'); + test.assertExists('tr:nth-child(4) a[href="/issues/search#resolved=false|createdAfter=2015-02-18|createdBefore=2015-02-19"]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'February 16 2015'); + test.assertSelectorContains('tr:nth-child(3)', 'February 17 2015'); + test.assertSelectorContains('tr:nth-child(4)', 'February 18 2015'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); diff --git a/server/sonar-web/src/test/js/project-issue-filter-widget.js b/server/sonar-web/src/test/js/project-issue-filter-widget.js new file mode 100644 index 00000000000..25e69cdeff8 --- /dev/null +++ b/server/sonar-web/src/test/js/project-issue-filter-widget.js @@ -0,0 +1,221 @@ +/* + * SonarQube, open source software quality management tool. + * Copyright (C) 2008-2014 SonarSource + * mailto:contact AT sonarsource DOT com + * + * SonarQube is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * SonarQube is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +/* globals casper: false */ + +var lib = require('../lib'), + testName = lib.testName('Project Issue Filter Widget'); + + +lib.initMessages(); +lib.changeWorkingDirectory('project-issues-filter-widget'); +lib.configureCasper(); + + +casper.test.begin(testName('Unresolved Issues By Severity'), 13, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-severity.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'severities', + componentUuid: '69e57151-be0d-4157-adff-c06741d88879', + componentKey: 'org.codehaus.sonar:sonar' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '1'); + test.assertSelectorContains('tr:nth-child(3)', '105'); + test.assertSelectorContains('tr:nth-child(4)', '5027'); + test.assertSelectorContains('tr:nth-child(5)', '540'); + test.assertSelectorContains('tr:nth-child(6)', '1178'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|severities=BLOCKER"]'); + test.assertExists('tr:nth-child(3) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|severities=CRITICAL"]'); + test.assertExists('tr:nth-child(4) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|severities=MAJOR"]'); + test.assertExists('tr:nth-child(5) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|severities=MINOR"]'); + test.assertExists('tr:nth-child(6) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|severities=INFO"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Date'), 18, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-date.json', + { data: { resolved: 'false' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'createdAt', + componentUuid: '69e57151-be0d-4157-adff-c06741d88879', + componentKey: 'org.codehaus.sonar:sonar' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '6851'); + test.assertSelectorContains('tr:nth-child(2)', '72'); + test.assertSelectorContains('tr:nth-child(3)', '64'); + test.assertSelectorContains('tr:nth-child(4)', '1262'); + test.assertSelectorContains('tr:nth-child(5)', '3729'); + test.assertSelectorContains('tr:nth-child(6)', '1724'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false"]'); + test.assertExists('tr:nth-child(2) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2011-01-01|createdBefore=2011-12-31"]'); + test.assertExists('tr:nth-child(3) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2012-01-01|createdBefore=2012-12-31"]'); + test.assertExists('tr:nth-child(4) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2013-01-01|createdBefore=2013-12-31"]'); + test.assertExists('tr:nth-child(5) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-01-01|createdBefore=2014-12-31"]'); + // do not check createdBefore value, because it is set dynamically to *now* + test.assertExists('tr:nth-child(6) a[href^="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2015-01-01|createdBefore="]'); + + // check labels + test.assertSelectorContains('tr:nth-child(2)', 'January 1 2011 – December 31 2011'); + test.assertSelectorContains('tr:nth-child(3)', 'January 1 2012 – December 31 2012'); + test.assertSelectorContains('tr:nth-child(4)', 'January 1 2013 – December 31 2013'); + test.assertSelectorContains('tr:nth-child(5)', 'January 1 2014 – December 31 2014'); + // do not check label fully, because it is set dynamically using *now* + test.assertSelectorContains('tr:nth-child(6)', 'January 1 2015 – '); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Unresolved Issues By Severity With Differential Period'), 13, function (test) { + casper + .start(lib.buildUrl('issue-filter-widget'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/issues/search', 'unresolved-issues-by-severity-with-differential-period.json', + { data: { resolved: 'false', createdAfter: '2014-12-09T17:12:38+0100' } }); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/widgets/issue-filter.js'], function (IssueFilter) { + window.requestMessages().done(function () { + new IssueFilter({ + el: '#issue-filter-widget', + query: 'resolved=false', + distributionAxis: 'severities', + periodDate: '2014-12-09T17:12:38+0100', + componentUuid: '69e57151-be0d-4157-adff-c06741d88879', + componentKey: 'org.codehaus.sonar:sonar' + }); + }); + }); + }); + }) + + .then(function () { + casper.waitForSelector('#issue-filter-widget > table'); + }) + + .then(function () { + // check count + test.assertElementCount('tr', 6); + + // check order and values + test.assertSelectorContains('tr:nth-child(1)', '+549'); + test.assertSelectorContains('tr:nth-child(2)', '+0'); + test.assertSelectorContains('tr:nth-child(3)', '+59'); + test.assertSelectorContains('tr:nth-child(4)', '+306'); + test.assertSelectorContains('tr:nth-child(5)', '+135'); + test.assertSelectorContains('tr:nth-child(6)', '+49'); + + // check links + test.assertExists('tr:nth-child(1) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-12-09T17%3A12%3A38%2B0100"]'); + test.assertExists('tr:nth-child(2) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-12-09T17%3A12%3A38%2B0100|severities=BLOCKER"]'); + test.assertExists('tr:nth-child(3) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-12-09T17%3A12%3A38%2B0100|severities=CRITICAL"]'); + test.assertExists('tr:nth-child(4) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-12-09T17%3A12%3A38%2B0100|severities=MAJOR"]'); + test.assertExists('tr:nth-child(5) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-12-09T17%3A12%3A38%2B0100|severities=MINOR"]'); + test.assertExists('tr:nth-child(6) a[href="/component_issues/index?id=org.codehaus.sonar%3Asonar#resolved=false|createdAfter=2014-12-09T17%3A12%3A38%2B0100|severities=INFO"]'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); |