diff options
Diffstat (limited to 'server/sonar-web/src/test/js/coding-rules-page-header.js')
-rw-r--r-- | server/sonar-web/src/test/js/coding-rules-page-header.js | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/server/sonar-web/src/test/js/coding-rules-page-header.js b/server/sonar-web/src/test/js/coding-rules-page-header.js new file mode 100644 index 00000000000..0cd140a460e --- /dev/null +++ b/server/sonar-web/src/test/js/coding-rules-page-header.js @@ -0,0 +1,162 @@ +/* + * 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. + */ +/* global casper:false */ + +var lib = require('../lib'), + testName = lib.testName('Coding Rules', 'Header'); + +lib.initMessages(); +lib.changeWorkingDirectory('coding-rules-page-header'); +lib.configureCasper(); + + +casper.test.begin(testName('Reload'), 2, function (test) { + casper + .start(lib.buildUrl('coding-rules'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/rules/app', 'app.json'); + this.searchMock = lib.mockRequestFromFile('/api/rules/search', 'search.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/coding-rules/app.js']); + jQuery.ajaxSetup({ dataType: 'json' }); + }); + }) + + .then(function () { + casper.waitForSelector('.coding-rule'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', 609); + lib.clearRequestMock(this.searchMock); + lib.mockRequestFromFile('/api/rules/search', 'search2.json'); + casper.click('.js-reload'); + casper.waitForSelectorTextChange('#coding-rules-total'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', 413); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('New Search'), 3, function (test) { + casper + .start(lib.buildUrl('coding-rules'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/rules/app', 'app.json'); + lib.mockRequestFromFile('/api/rules/search', 'search2.json', { data: { languages: 'java' } }); + lib.mockRequestFromFile('/api/rules/search', 'search.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/coding-rules/app.js']); + jQuery.ajaxSetup({ dataType: 'json' }); + }); + }) + + .then(function () { + casper.waitForSelector('.coding-rule'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', 609); + casper.click('.js-facet[data-value="java"]'); + casper.waitForSelectorTextChange('#coding-rules-total'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', 413); + casper.click('.js-new-search'); + casper.waitForSelectorTextChange('#coding-rules-total'); + }) + + .then(function () { + test.assertSelectorContains('#coding-rules-total', 609); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); + + +casper.test.begin(testName('Go Back'), 2, function (test) { + casper + .start(lib.buildUrl('coding-rules'), function () { + lib.setDefaultViewport(); + + lib.mockRequest('/api/l10n/index', '{}'); + lib.mockRequestFromFile('/api/rules/app', 'app.json'); + lib.mockRequestFromFile('/api/rules/search', 'search.json'); + lib.mockRequestFromFile('/api/rules/show', 'show.json'); + }) + + .then(function () { + casper.evaluate(function () { + require(['/js/coding-rules/app.js']); + jQuery.ajaxSetup({ dataType: 'json' }); + }); + }) + + .then(function () { + casper.waitForSelector('.coding-rule.selected', function () { + casper.click('.coding-rule.selected .js-rule'); + }); + }) + + .then(function () { + casper.waitForSelector('.coding-rules-detail-header'); + }) + + .then(function () { + casper.click('.js-back'); + test.assertDoesntExist('.js-back'); + test.assertDoesntExist('.coding-rules-detail-header'); + }) + + .then(function () { + lib.sendCoverage(); + }) + + .run(function () { + test.done(); + }); +}); |