aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/test/js
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-03-17 15:32:13 +0100
committerStas Vilchik <vilchiks@gmail.com>2015-03-17 15:32:22 +0100
commit083b9e143663fefdcf9ad0f71457bbbe70d60174 (patch)
tree11a92a1d0f7501ec011c13e73b78abe10aefb923 /server/sonar-web/src/test/js
parent12f6213141fbd03c9de2d2d377394299f39873bb (diff)
downloadsonarqube-083b9e143663fefdcf9ad0f71457bbbe70d60174.tar.gz
sonarqube-083b9e143663fefdcf9ad0f71457bbbe70d60174.zip
add some web tests
Diffstat (limited to 'server/sonar-web/src/test/js')
-rw-r--r--server/sonar-web/src/test/js/coding-rules-page-bulk-change.js273
-rw-r--r--server/sonar-web/src/test/js/coding-rules-page-header.js162
2 files changed, 435 insertions, 0 deletions
diff --git a/server/sonar-web/src/test/js/coding-rules-page-bulk-change.js b/server/sonar-web/src/test/js/coding-rules-page-bulk-change.js
new file mode 100644
index 00000000000..9d455734b08
--- /dev/null
+++ b/server/sonar-web/src/test/js/coding-rules-page-bulk-change.js
@@ -0,0 +1,273 @@
+/*
+ * 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', 'Bulk Change');
+
+lib.initMessages();
+lib.changeWorkingDirectory('coding-rules-page-bulk-change');
+lib.configureCasper();
+
+
+casper.test.begin(testName('Activate', 'Success'), 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.mockRequest('/api/qualityprofiles/activate_rules', '{ "succeeded": 225 }');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['/js/coding-rules/app.js']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.coding-rule');
+ })
+
+ .then(function () {
+ test.assertExists('.js-bulk-change');
+ casper.click('.js-bulk-change');
+ casper.waitForSelector('.bubble-popup');
+ })
+
+ .then(function () {
+ test.assertExists('.bubble-popup .js-bulk-change[data-action="activate"]');
+ casper.click('.js-bulk-change[data-action="activate"]');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ test.assertExists('.modal #coding-rules-bulk-change-profile');
+ test.assertExists('.modal #coding-rules-submit-bulk-change');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#coding-rules-bulk-change-profile').val('java-default-with-mojo-conventions-49307');
+ });
+ })
+
+ .then(function () {
+ casper.click('.modal #coding-rules-submit-bulk-change');
+ casper.waitForSelector('.modal .alert-success');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.modal', '225');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Activate', 'Failed'), 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.mockRequest('/api/qualityprofiles/activate_rules', '{ "succeeded": 225, "failed": 395 }');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['/js/coding-rules/app.js']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.coding-rule');
+ })
+
+ .then(function () {
+ test.assertExists('.js-bulk-change');
+ casper.click('.js-bulk-change');
+ casper.waitForSelector('.bubble-popup');
+ })
+
+ .then(function () {
+ test.assertExists('.bubble-popup .js-bulk-change[data-action="activate"]');
+ casper.click('.js-bulk-change[data-action="activate"]');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ test.assertExists('.modal #coding-rules-bulk-change-profile');
+ test.assertExists('.modal #coding-rules-submit-bulk-change');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#coding-rules-bulk-change-profile').val('java-default-with-mojo-conventions-49307');
+ });
+ })
+
+ .then(function () {
+ casper.click('.modal #coding-rules-submit-bulk-change');
+ casper.waitForSelector('.modal .alert-warning');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.modal', '225');
+ test.assertSelectorContains('.modal', '395');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Filter Profiles by Language'), 4, 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');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['/js/coding-rules/app.js']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.coding-rule');
+ })
+
+ .then(function () {
+ casper.click('.js-facet[data-value="java"]');
+ test.assertExists('.js-bulk-change');
+ casper.click('.js-bulk-change');
+ casper.waitForSelector('.bubble-popup');
+ })
+
+ .then(function () {
+ test.assertExists('.bubble-popup .js-bulk-change[data-action="activate"]');
+ casper.click('.js-bulk-change[data-action="activate"]');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ test.assertExists('.modal #coding-rules-bulk-change-profile');
+ test.assertEqual(8, casper.evaluate(function () {
+ return jQuery('.modal').find('#coding-rules-bulk-change-profile').find('option').length;
+ }));
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Change Selected Profile'), 4, 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-qprofile-active.json',
+ { data: { activation: true } });
+ lib.mockRequestFromFile('/api/rules/search', 'search.json');
+ lib.mockRequest('/api/qualityprofiles/deactivate_rules', '{ "succeeded": 7 }');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['/js/coding-rules/app.js']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.coding-rule');
+ })
+
+ .then(function () {
+ casper.click('[data-property="qprofile"] .js-facet-toggle');
+ casper.waitForSelector('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');
+ })
+
+ .then(function () {
+ casper.click('.js-facet[data-value="java-default-with-mojo-conventions-49307"]');
+ casper.waitForSelectorTextChange('#coding-rules-total');
+ })
+
+ .then(function () {
+ test.assertExists('.js-bulk-change');
+ casper.click('.js-bulk-change');
+ casper.waitForSelector('.bubble-popup');
+ })
+
+ .then(function () {
+ test.assertExists('.bubble-popup .js-bulk-change[data-param="java-default-with-mojo-conventions-49307"]');
+ casper.click('.js-bulk-change[data-param="java-default-with-mojo-conventions-49307"]');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.modal #coding-rules-bulk-change-profile');
+ casper.click('.modal #coding-rules-submit-bulk-change');
+ casper.waitForSelector('.modal .alert-success');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.modal', '7');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
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();
+ });
+});