aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/test
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-06-10 12:43:45 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-06-10 14:22:07 +0200
commitd9e351a65dd68d82dca35af28b5123dfdedc7527 (patch)
tree3071ad909e7943600df1af98d4301a59f6d816d2 /server/sonar-web/src/test
parentd79eadbb3ce3a0986d62c19846838e6ac5b11687 (diff)
downloadsonarqube-d9e351a65dd68d82dca35af28b5123dfdedc7527.tar.gz
sonarqube-d9e351a65dd68d82dca35af28b5123dfdedc7527.zip
improve web tests suite
Diffstat (limited to 'server/sonar-web/src/test')
-rw-r--r--server/sonar-web/src/test/js/quality-gates-spec.js1150
-rw-r--r--server/sonar-web/src/test/js/quality-profiles.js2236
-rw-r--r--server/sonar-web/src/test/lib.js130
3 files changed, 1594 insertions, 1922 deletions
diff --git a/server/sonar-web/src/test/js/quality-gates-spec.js b/server/sonar-web/src/test/js/quality-gates-spec.js
index 207e8a2cbec..5d5885c1975 100644
--- a/server/sonar-web/src/test/js/quality-gates-spec.js
+++ b/server/sonar-web/src/test/js/quality-gates-spec.js
@@ -1,718 +1,588 @@
-/*
- * 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('Quality Gates');
-
-lib.initMessages();
-lib.changeWorkingDirectory('quality-gates-spec');
-lib.configureCasper();
-
-
-casper.test.begin(testName('Should Show List'), 5, function (test) {
- casper
- .start(lib.buildUrl('quality_gates'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
- });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 3);
- test.assertSelectorContains('.js-list .list-group-item', 'SonarQube way');
- test.assertSelectorContains('.js-list .list-group-item', 'Simple Gate');
- test.assertSelectorContains('.js-list .list-group-item', 'Another Gate');
-
- test.assertElementCount('.js-list .badge', 1);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+/* global describe:false, it:false */
+var lib = require('../lib');
+describe('Quality Gates App', function () {
-casper.test.begin(testName('Should Show Details', 'Anonymous'), 14, function (test) {
- casper
- .start(lib.buildUrl('quality_gates'), function () {
- lib.setDefaultViewport();
+ it('should show list', 5, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates'), function () {
+ lib.setDefaultViewport();
- lib.mockRequestFromFile('/api/qualitygates/app', 'app-anonymous.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- })
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
});
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-id="1"]');
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item.active', 1);
- test.assertSelectorContains('.js-list .list-group-item.active', 'SonarQube way');
-
- test.assertSelectorContains('.search-navigator-workspace-header', 'SonarQube way');
- test.assertDoesntExist('#quality-gate-rename');
- test.assertDoesntExist('#quality-gate-copy');
- test.assertDoesntExist('#quality-gate-unset-as-default');
- test.assertDoesntExist('#quality-gate-delete');
-
- test.assertExists('.js-conditions');
- test.assertElementCount('.js-conditions tbody tr', 8);
- test.assertDoesntExist('.js-conditions .update-condition');
- test.assertDoesntExist('.js-conditions .delete-condition');
-
- test.assertExists('.quality-gate-default-message');
- })
-
- .then(function () {
- test.assertNotVisible('.js-more');
- casper.click('.js-show-more');
- test.assertVisible('.js-more');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ })
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
-casper.test.begin(testName('Should Show Details', 'Admin'), 12, function (test) {
- casper
- .start(lib.buildUrl('quality_gates'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 3);
+ test.assertSelectorContains('.js-list .list-group-item', 'SonarQube way');
+ test.assertSelectorContains('.js-list .list-group-item', 'Simple Gate');
+ test.assertSelectorContains('.js-list .list-group-item', 'Another Gate');
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
- });
+ test.assertElementCount('.js-list .badge', 1);
});
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-id="1"]');
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item.active', 1);
- test.assertSelectorContains('.js-list .list-group-item.active', 'SonarQube way');
-
- test.assertSelectorContains('.search-navigator-workspace-header', 'SonarQube way');
- test.assertExists('#quality-gate-rename');
- test.assertExists('#quality-gate-copy');
- test.assertExists('#quality-gate-toggle-default');
- test.assertExists('#quality-gate-delete');
-
- test.assertExists('.js-conditions');
- test.assertElementCount('.js-conditions tbody tr', 8);
- test.assertElementCount('.js-conditions .update-condition', 8);
- test.assertElementCount('.js-conditions .delete-condition', 8);
-
- test.assertExists('.quality-gate-default-message');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ });
-casper.test.begin(testName('Should Show Projects'), 2, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/5'), function () {
- lib.setDefaultViewport();
+ it('should show details for anonymous', 14, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates'), function () {
+ lib.setDefaultViewport();
- lib.mockRequestFromFile('/api/qualitygates/app', 'app-anonymous.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
- lib.mockRequestFromFile('/api/qualitygates/search?gateId=5', 'projects.json');
- })
+ lib.fmock('/api/qualitygates/app', 'app-anonymous.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
});
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-id="1"]');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item.active', 1);
+ test.assertSelectorContains('.js-list .list-group-item.active', 'SonarQube way');
+
+ test.assertSelectorContains('.search-navigator-workspace-header', 'SonarQube way');
+ test.assertDoesntExist('#quality-gate-rename');
+ test.assertDoesntExist('#quality-gate-copy');
+ test.assertDoesntExist('#quality-gate-unset-as-default');
+ test.assertDoesntExist('#quality-gate-delete');
+
+ test.assertExists('.js-conditions');
+ test.assertElementCount('.js-conditions tbody tr', 8);
+ test.assertDoesntExist('.js-conditions .update-condition');
+ test.assertDoesntExist('.js-conditions .delete-condition');
+
+ test.assertExists('.quality-gate-default-message');
+ })
+
+ .then(function () {
+ test.assertNotVisible('.js-more');
+ casper.click('.js-show-more');
+ test.assertVisible('.js-more');
});
- })
-
- .then(function () {
- casper.waitForSelector('.select-list-list li');
- })
+ });
- .then(function () {
- test.assertElementCount('.select-list-list li', 1);
- test.assertSelectorContains('.select-list-list li', 'SonarQube');
- })
- .then(function () {
- lib.sendCoverage();
- })
+ it('should show details for admin', 12, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates'), function () {
+ lib.setDefaultViewport();
- .run(function () {
- test.done();
- });
-});
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ })
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ });
+ })
-casper.test.begin(testName('Should Rename'), 2, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/1'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- lib.mockRequestFromFile('/api/qualitygates/rename', 'rename.json', { data: { id: '1', name: 'New Name' } });
- })
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-id="1"]');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
- });
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item.active', 1);
+ test.assertSelectorContains('.js-list .list-group-item.active', 'SonarQube way');
- .then(function () {
- casper.waitForSelector('.search-navigator-header-component');
- })
+ test.assertSelectorContains('.search-navigator-workspace-header', 'SonarQube way');
+ test.assertExists('#quality-gate-rename');
+ test.assertExists('#quality-gate-copy');
+ test.assertExists('#quality-gate-toggle-default');
+ test.assertExists('#quality-gate-delete');
- .then(function () {
- casper.click('#quality-gate-rename');
- casper.waitUntilVisible('#quality-gate-form-name');
- })
+ test.assertExists('.js-conditions');
+ test.assertElementCount('.js-conditions tbody tr', 8);
+ test.assertElementCount('.js-conditions .update-condition', 8);
+ test.assertElementCount('.js-conditions .delete-condition', 8);
- .then(function () {
- casper.evaluate(function () {
- jQuery('#quality-gate-form-name').val('New Name');
+ test.assertExists('.quality-gate-default-message');
});
- casper.click('.modal-foot button');
- casper.waitForSelectorTextChange('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertSelectorContains('.search-navigator-header-component', 'New Name');
- test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ });
-casper.test.begin(testName('Should Copy'), 3, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/1'), function () {
- lib.setDefaultViewport();
+ it('should show projects', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/5'), function () {
+ lib.setDefaultViewport();
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- lib.mockRequestFromFile('/api/qualitygates/show', 'show-created.json', { data: { id: '6' } });
- lib.mockRequestFromFile('/api/qualitygates/copy', 'copy.json', { data: { id: '1', name: 'New Name' } });
- })
+ lib.fmock('/api/qualitygates/app', 'app-anonymous.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
+ lib.fmock('/api/qualitygates/search?gateId=5', 'projects.json');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
});
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
+ })
- .then(function () {
- casper.waitForSelector('.search-navigator-header-component');
- })
+ .then(function () {
+ casper.waitForSelector('.select-list-list li');
+ })
- .then(function () {
- casper.click('#quality-gate-copy');
- casper.waitUntilVisible('#quality-gate-form-name');
- })
-
- .then(function () {
- casper.evaluate(function () {
- jQuery('#quality-gate-form-name').val('New Name');
+ .then(function () {
+ test.assertElementCount('.select-list-list li', 1);
+ test.assertSelectorContains('.select-list-list li', 'SonarQube');
});
- casper.click('.modal-foot button');
- casper.waitForSelectorTextChange('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertSelectorContains('.search-navigator-header-component', 'New Name');
- test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');
- test.assertSelectorContains('.js-list .list-group-item', 'SonarQube way');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Set As Default'), 4, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/5'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
- lib.mockRequest('/api/qualitygates/set_as_default', '{}', { data: { id: '5' } });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ });
+
+
+ it('should rename', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ lib.fmock('/api/qualitygates/rename', 'rename.json', { data: { id: '1', name: 'New Name' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
});
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertDoesntExist('.js-list .list-group-item.active .badge');
- test.assertDoesntExist('.quality-gate-default-message');
- casper.click('#quality-gate-toggle-default');
- casper.waitForSelector('.js-list .list-group-item.active .badge');
- })
-
- .then(function () {
- test.assertExists('.quality-gate-default-message');
- test.assertElementCount('.js-list .badge', 1);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ })
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
-casper.test.begin(testName('Should Unset As Default'), 4, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/1'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ casper.click('#quality-gate-rename');
+ casper.waitUntilVisible('#quality-gate-form-name');
+ })
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- lib.mockRequest('/api/qualitygates/unset_default', '{}', { data: { id: '1' } });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-form-name').val('New Name');
});
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertExists('.js-list .list-group-item.active .badge');
- test.assertExists('.quality-gate-default-message');
- casper.click('#quality-gate-toggle-default');
- casper.waitWhileSelector('.js-list .list-group-item.active .badge');
- })
-
- .then(function () {
- test.assertDoesntExist('.quality-gate-default-message');
- test.assertDoesntExist('.js-list .badge');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ casper.click('.modal-foot button');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'New Name');
+ test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');
+ });
+ });
+
+
+ it('should copy', 3, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ lib.fmock('/api/qualitygates/show', 'show-created.json', { data: { id: '6' } });
+ lib.fmock('/api/qualitygates/copy', 'copy.json', { data: { id: '1', name: 'New Name' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
-casper.test.begin(testName('Should Create'), 2, function (test) {
- casper
- .start(lib.buildUrl('quality_gates'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequest('/api/qualitygates/create', '{"errors":[{"msg": "error"}]}',
- { status: 400, data: { name: 'Bad' } });
- lib.mockRequestFromFile('/api/qualitygates/create', 'create.json', { data: { name: 'New Name' } });
- lib.mockRequestFromFile('/api/qualitygates/show', 'show-created.json', { data: { id: '6' } });
- })
+ .then(function () {
+ casper.click('#quality-gate-copy');
+ casper.waitUntilVisible('#quality-gate-form-name');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-form-name').val('New Name');
});
- jQuery.ajaxSetup({ dataType: 'json' });
+ casper.click('.modal-foot button');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'New Name');
+ test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');
+ test.assertSelectorContains('.js-list .list-group-item', 'SonarQube way');
});
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('#quality-gate-add');
- casper.waitUntilVisible('#quality-gate-form-name');
- })
-
- .then(function () {
- casper.evaluate(function () {
- jQuery('#quality-gate-form-name').val('Bad');
+ });
+
+
+ it('should set as default', 4, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/5'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
+ lib.smock('/api/qualitygates/set_as_default', '{}', { data: { id: '5' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.js-list .list-group-item.active .badge');
+ test.assertDoesntExist('.quality-gate-default-message');
+ casper.click('#quality-gate-toggle-default');
+ casper.waitForSelector('.js-list .list-group-item.active .badge');
+ })
+
+ .then(function () {
+ test.assertExists('.quality-gate-default-message');
+ test.assertElementCount('.js-list .badge', 1);
});
- casper.click('.modal-foot button');
- casper.waitForSelector('.alert-danger');
- })
-
- .then(function () {
- casper.evaluate(function () {
- jQuery('#quality-gate-form-name').val('New Name');
+ });
+
+
+ it('should unset as default', 4, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ lib.smock('/api/qualitygates/unset_default', '{}', { data: { id: '1' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertExists('.js-list .list-group-item.active .badge');
+ test.assertExists('.quality-gate-default-message');
+ casper.click('#quality-gate-toggle-default');
+ casper.waitWhileSelector('.js-list .list-group-item.active .badge');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.quality-gate-default-message');
+ test.assertDoesntExist('.js-list .badge');
});
- casper.click('.modal-foot button');
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertSelectorContains('.search-navigator-header-component', 'New Name');
- test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ });
+
+
+ it('should create', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.smock('/api/qualitygates/create', '{"errors":[{"msg": "error"}]}',
+ { status: 400, data: { name: 'Bad' } });
+ lib.fmock('/api/qualitygates/create', 'create.json', { data: { name: 'New Name' } });
+ lib.fmock('/api/qualitygates/show', 'show-created.json', { data: { id: '6' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
-casper.test.begin(testName('Should Delete'), 2, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/5'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ casper.click('#quality-gate-add');
+ casper.waitUntilVisible('#quality-gate-form-name');
+ })
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
- this.deleteMock = lib.mockRequest('/api/qualitygates/destroy', '{"errors":[{"msg": "error"}]}',
- { status: 400 });
- })
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-form-name').val('Bad');
+ });
+ casper.click('.modal-foot button');
+ casper.waitForSelector('.alert-danger');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-form-name').val('New Name');
});
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 3);
- casper.click('#quality-gate-delete');
- casper.waitForSelector('#delete-gate-submit');
- })
-
- .then(function () {
- casper.click('#delete-gate-submit');
- casper.waitForSelector('.alert-danger');
- })
-
- .then(function () {
- lib.clearRequestMock(this.deleteMock);
- lib.mockRequest('/api/qualitygates/destroy', '{}', { data: { id: '5' } });
-
- casper.click('#delete-gate-submit');
- casper.waitWhileSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 2);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ casper.click('.modal-foot button');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'New Name');
+ test.assertSelectorContains('.js-list .list-group-item.active', 'New Name');
+ });
+ });
+
+
+ it('should delete', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/5'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
+ this.deleteMock = lib.smock('/api/qualitygates/destroy', '{"errors":[{"msg": "error"}]}',
+ { status: 400 });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
-casper.test.begin(testName('Should Add Condition'), 6, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/5'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
- lib.mockRequestFromFile('/api/qualitygates/create_condition', 'create-condition.json',
- { data: { gateId: '5', metric: 'complexity', op: 'GT', period: '1', warning: '3', error: '4' } });
- })
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 3);
+ casper.click('#quality-gate-delete');
+ casper.waitForSelector('#delete-gate-submit');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
- });
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
+ .then(function () {
+ casper.click('#delete-gate-submit');
+ casper.waitForSelector('.alert-danger');
+ })
- .then(function () {
- casper.waitForSelector('.search-navigator-header-component');
- })
+ .then(function () {
+ lib.clearRequestMock(this.deleteMock);
+ lib.smock('/api/qualitygates/destroy', '{}', { data: { id: '5' } });
- .then(function () {
- test.assertElementCount('.js-conditions [name="error"]', 0);
+ casper.click('#delete-gate-submit');
+ casper.waitWhileSelector('.search-navigator-header-component');
+ })
- casper.evaluate(function () {
- jQuery('#quality-gate-new-condition-metric').val('complexity').change();
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 2);
});
- test.assertElementCount('.js-conditions [name="error"]', 1);
- })
-
- .then(function () {
- casper.click('.cancel-add-condition');
- casper.waitWhileSelector('.cancel-add-condition');
- })
+ });
+
+
+ it('should add condition', 6, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/5'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show-another.json', { data: { id: '5' } });
+ lib.fmock('/api/qualitygates/create_condition', 'create-condition.json',
+ { data: { gateId: '5', metric: 'complexity', op: 'GT', period: '1', warning: '3', error: '4' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
- .then(function () {
- test.assertElementCount('.js-conditions [name="error"]', 0);
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
- casper.evaluate(function () {
- jQuery('#quality-gate-new-condition-metric').val('complexity').change();
- });
- test.assertElementCount('.js-conditions [name="error"]', 1);
+ .then(function () {
+ test.assertElementCount('.js-conditions [name="error"]', 0);
- casper.evaluate(function () {
- jQuery('[name="period"]').val('1');
- jQuery('[name="operator"]').val('GT');
- jQuery('[name="warning"]').val('3');
- jQuery('[name="error"]').val('4');
- });
- casper.click('.add-condition');
- casper.waitForSelector('.update-condition');
- })
-
- .then(function () {
- test.assertExists('.update-condition[disabled]');
- test.assertExists('.delete-condition');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ casper.evaluate(function () {
+ jQuery('#quality-gate-new-condition-metric').val('complexity').change();
+ });
+ test.assertElementCount('.js-conditions [name="error"]', 1);
+ })
+ .then(function () {
+ casper.click('.cancel-add-condition');
+ casper.waitWhileSelector('.cancel-add-condition');
+ })
-casper.test.begin(testName('Should Update Condition'), 3, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/1'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ test.assertElementCount('.js-conditions [name="error"]', 0);
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- lib.mockRequestFromFile('/api/qualitygates/update_condition', 'update-condition.json',
- { data: { id: '1', warning: '173' } });
- })
+ casper.evaluate(function () {
+ jQuery('#quality-gate-new-condition-metric').val('complexity').change();
+ });
+ test.assertElementCount('.js-conditions [name="error"]', 1);
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
+ casper.evaluate(function () {
+ jQuery('[name="period"]').val('1');
+ jQuery('[name="operator"]').val('GT');
+ jQuery('[name="warning"]').val('3');
+ jQuery('[name="error"]').val('4');
});
- jQuery.ajaxSetup({ dataType: 'json' });
+ casper.click('.add-condition');
+ casper.waitForSelector('.update-condition');
+ })
+
+ .then(function () {
+ test.assertExists('.update-condition[disabled]');
+ test.assertExists('.delete-condition');
});
- })
+ });
+
+
+ it('should update condition', 3, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ lib.fmock('/api/qualitygates/update_condition', 'update-condition.json',
+ { data: { id: '1', warning: '173' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.update-condition');
+ })
- .then(function () {
- casper.waitForSelector('.update-condition');
- })
+ .then(function () {
+ test.assertExists('.js-conditions tr:first-child .update-condition[disabled]');
+ casper.evaluate(function () {
+ jQuery('.js-conditions tr:first-child [name="warning"]').val('173').change();
+ });
+ test.assertDoesntExist('.js-conditions tr:first-child .update-condition[disabled]');
+ casper.click('.js-conditions tr:first-child .update-condition');
+ casper.waitWhileSelector('.js-conditions tr:first-child .update-condition:not([disabled])');
+ })
- .then(function () {
- test.assertExists('.js-conditions tr:first-child .update-condition[disabled]');
- casper.evaluate(function () {
- jQuery('.js-conditions tr:first-child [name="warning"]').val('173').change();
+ .then(function () {
+ test.assertExists('.js-conditions tr:first-child .update-condition[disabled]');
});
- test.assertDoesntExist('.js-conditions tr:first-child .update-condition[disabled]');
- casper.click('.js-conditions tr:first-child .update-condition');
- casper.waitWhileSelector('.js-conditions tr:first-child .update-condition:not([disabled])');
- })
-
- .then(function () {
- test.assertExists('.js-conditions tr:first-child .update-condition[disabled]');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
+ });
+
+
+ it('should delete condition', 1, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/qualitygates/app', 'app.json');
+ lib.fmock('/api/qualitygates/list', 'list.json');
+ lib.fmock('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
+ this.deleteMock = lib.smock('/api/qualitygates/delete_condition', '{"errors":[{"msg": "error"}]}',
+ { status: 400 });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gates/app'], function (App) {
+ App.start({ el: '#quality-gates' });
+ });
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+ .then(function () {
+ casper.waitForSelector('.delete-condition');
+ })
-casper.test.begin(testName('Should Delete Condition'), 2, function (test) {
- casper
- .start(lib.buildUrl('quality_gates#show/1'), function () {
- lib.setDefaultViewport();
+ .then(function () {
+ test.assertElementCount('.delete-condition', 8);
- lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
- lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
- lib.mockRequestFromFile('/api/qualitygates/show', 'show.json', { data: { id: '1' } });
- this.deleteMock = lib.mockRequest('/api/qualitygates/delete_condition', '{"errors":[{"msg": "error"}]}',
- { status: 400 });
- })
+ casper.click('.js-conditions tr:first-child .delete-condition');
+ casper.waitForSelector('#delete-condition-submit');
+ })
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-gates/app'], function (App) {
- App.start({ el: '#quality-gates' });
- });
- jQuery.ajaxSetup({ dataType: 'json' });
+ .then(function () {
+ casper.click('#delete-condition-submit');
+ casper.waitForSelector('.alert-danger');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.deleteMock);
+ lib.smock('/api/qualitygates/delete_condition', '{}', { data: { id: '1' } });
+ casper.click('#delete-condition-submit');
+ lib.waitForElementCount('.delete-condition', 7);
});
- })
-
- .then(function () {
- casper.waitForSelector('.delete-condition');
- })
-
- .then(function () {
- test.assertElementCount('.delete-condition', 8);
-
- casper.click('.js-conditions tr:first-child .delete-condition');
- casper.waitForSelector('#delete-condition-submit');
- })
-
- .then(function () {
- casper.click('#delete-condition-submit');
- casper.waitForSelector('.alert-danger');
- })
-
- .then(function () {
- lib.clearRequestMock(this.deleteMock);
- lib.mockRequest('/api/qualitygates/delete_condition', '{}', { data: { id: '1' } });
- casper.click('#delete-condition-submit');
- lib.waitForElementCount('.delete-condition', 7);
- })
-
- .then(function () {
- test.assert(true);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
+ });
+
});
diff --git a/server/sonar-web/src/test/js/quality-profiles.js b/server/sonar-web/src/test/js/quality-profiles.js
index 2200aa97b67..365206bb87c 100644
--- a/server/sonar-web/src/test/js/quality-profiles.js
+++ b/server/sonar-web/src/test/js/quality-profiles.js
@@ -1,1229 +1,1011 @@
-/*
- * 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('Quality Profiles');
-
-lib.initMessages();
-lib.changeWorkingDirectory('quality-profiles');
-lib.configureCasper();
-
-
-casper.test.begin(testName('Should Show List'), 9, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 5);
- test.assertSelectorContains('.js-list .list-group-item', 'Sonar way');
- test.assertSelectorContains('.js-list .list-group-item', 'PSR-2');
-
- test.assertElementCount('.js-list-language', 4);
- test.assertSelectorContains('.js-list-language', 'Java');
- test.assertSelectorContains('.js-list-language', 'JavaScript');
- test.assertSelectorContains('.js-list-language', 'PHP');
- test.assertSelectorContains('.js-list-language', 'Python');
-
- test.assertElementCount('.js-list .badge', 4);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Filter List By Language'), 15, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 5);
- test.assertVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');
-
- test.assertElementCount('.js-list-language', 4);
- test.assertVisible('.js-list-language[data-language="java"]');
- test.assertVisible('.js-list-language[data-language="js"]');
- })
-
- .then(function () {
- test.assertExists('#quality-profiles-filter-by-language');
- casper.click('.js-filter-by-language[data-language="js"]');
- })
-
- .then(function () {
- test.assertNotVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');
- test.assertNotVisible('.js-list-language[data-language="java"]');
- test.assertVisible('.js-list-language[data-language="js"]');
- })
-
- .then(function () {
- casper.click('.js-filter-by-language:nth-child(1)');
- })
-
- .then(function () {
- test.assertVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');
- test.assertVisible('.js-list-language[data-language="java"]');
- test.assertVisible('.js-list-language[data-language="js"]');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Show Details'), 10, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json',
- { data: { qprofile: 'java-sonar-way-67887', activation: 'true' }});
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json', {
- data: { profileKey: 'java-sonar-way-67887' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item.active', 1);
- test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');
-
- test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');
- test.assertSelectorContains('.search-navigator-workspace-header', 'Java');
- test.assertExists('#quality-profile-backup');
- test.assertDoesntExist('#quality-profile-rename');
- test.assertDoesntExist('#quality-profile-copy');
- test.assertDoesntExist('#quality-profile-delete');
- test.assertDoesntExist('#quality-profile-set-as-default');
- test.assertDoesntExist('#quality-profile-change-parent');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Show Details', 'Admin'), 10, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json',
- { data: { qprofile: 'java-sonar-way-67887', activation: 'true' }});
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json', {
- data: { profileKey: 'java-sonar-way-67887' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item.active', 1);
- test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');
-
- test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');
- test.assertSelectorContains('.search-navigator-workspace-header', 'Java');
- test.assertExists('#quality-profile-backup');
- test.assertExists('#quality-profile-rename');
- test.assertExists('#quality-profile-copy');
- test.assertDoesntExist('#quality-profile-delete');
- test.assertDoesntExist('#quality-profile-set-as-default');
- test.assertExists('#quality-profile-change-parent');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Show Inheritance Details'), 10, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance-plus.json', {
- data: { profileKey: 'java-inherited-profile-85155' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');
- casper.waitForSelector('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('#quality-profile-ancestors li', 1);
- test.assertSelectorContains('#quality-profile-ancestors', 'Sonar way');
- test.assertSelectorContains('#quality-profile-ancestors', '161');
-
- test.assertElementCount('#quality-profile-inheritance-current', 1);
- test.assertSelectorContains('#quality-profile-inheritance-current', 'Inherited Profile');
- test.assertSelectorContains('#quality-profile-inheritance-current', '163');
- test.assertSelectorContains('#quality-profile-inheritance-current', '7');
-
- test.assertElementCount('#quality-profile-children li', 1);
- test.assertSelectorContains('#quality-profile-children', 'Second Level Inherited Profile');
- test.assertSelectorContains('#quality-profile-children', '165');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Show Selected Projects'), 2, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/projects?key=php-psr-2-46772', 'projects.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]');
- casper.waitForSelector('#quality-profile-projects');
- })
-
- .then(function () {
- lib.waitForElementCount('#quality-profile-projects .select-list-list li', 2);
- })
-
- .then(function () {
- test.assertSelectorContains('#quality-profile-projects .select-list-list li', 'CSS');
- test.assertSelectorContains('#quality-profile-projects .select-list-list li', 'http-request-parent');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Should Move Between Profiles'), 1, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- this.rulesMock = lib.mockRequestFromFile('/api/rules/search', 'rules.json',
- { data: { qprofile: 'java-inherited-profile-85155', activation: 'true' }});
- this.inheritanceMock = lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance-plus.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');
- casper.waitForSelector('#quality-profile-ancestors');
- })
-
- .then(function () {
- lib.clearRequestMock(this.rulesMock);
- lib.clearRequestMock(this.inheritanceMock);
- lib.mockRequestFromFile('/api/rules/search', 'rules.json',
- { data: { qprofile: 'java-sonar-way-67887', activation: 'true' }});
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
-
- casper.click('#quality-profile-ancestors .js-profile[data-key="java-sonar-way-67887"]');
- casper.waitForSelectorTextChange('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertSelectorContains('.search-navigator-header-component', 'Sonar way');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Copy Profile'), 5, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/copy', 'copy.json', {
- data: { fromKey: 'java-sonar-way-67887', toName: 'Copied Profile' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 5);
- casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- casper.waitForSelector('#quality-profile-copy');
- })
-
- .then(function () {
- casper.click('#quality-profile-copy');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- casper.evaluate(function () {
- jQuery('#copy-profile-name').val('Copied Profile');
- });
- casper.click('#copy-profile-submit');
- casper.waitForSelectorTextChange('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 6);
- test.assertSelectorContains('.js-list .list-group-item.active', 'Copied Profile');
- test.assertSelectorContains('.search-navigator-header-component', 'Copied Profile');
- test.assertSelectorContains('.search-navigator-header-component', 'Java');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Rename Profile'), 2, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequest('/api/qualityprofiles/rename', '{}', {
- data: { key: 'java-sonar-way-67887', name: 'Renamed Profile' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
- casper.waitForSelector('#quality-profile-rename');
- })
-
- .then(function () {
- casper.click('#quality-profile-rename');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- lib.clearRequestMock(this.searchMock);
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-renamed.json');
-
- casper.evaluate(function () {
- jQuery('#rename-profile-name').val('Renamed Profile');
- });
- casper.click('#rename-profile-submit');
- casper.waitForSelectorTextChange('.search-navigator-header-component');
- })
-
- .then(function () {
- test.assertSelectorContains('.js-list .list-group-item.active', 'Renamed Profile');
- test.assertSelectorContains('.search-navigator-header-component', 'Renamed Profile');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Make Profile Default'), 4, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequest('/api/qualityprofiles/set_default', '{}', {
- data: { profileKey: 'php-psr-2-46772' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertDoesntExist('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge');
- test.assertExists('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge');
- casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]');
- casper.waitForSelector('#quality-profile-set-as-default');
- })
-
- .then(function () {
- lib.clearRequestMock(this.searchMock);
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-another-default.json');
-
- casper.click('#quality-profile-set-as-default');
- casper.waitWhileSelector('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge');
- })
-
- .then(function () {
- test.assertDoesntExist('#quality-profile-set-as-default');
- test.assertExists('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Delete Profile'), 2, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-with-copy.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequest('/api/qualityprofiles/delete', '{}', {
- data: { profileKey: 'java-copied-profile-11711' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 6);
- casper.click('.js-list .list-group-item[data-key="java-copied-profile-11711"]');
- casper.waitForSelector('#quality-profile-delete');
- })
-
- .then(function () {
- casper.click('#quality-profile-delete');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- lib.clearRequestMock(this.searchMock);
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
-
- casper.click('#delete-profile-submit');
- lib.waitForElementCount('.js-list .list-group-item', 5);
- })
-
- .then(function () {
- test.assertSelectorDoesntContain('.js-list .list-group-item', 'Copied Profile');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Create Profile'), 2, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/qualityprofiles/importers', 'importers-empty.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
+/* global describe:false, it:false */
+var lib = require('../lib');
+
+describe('Quality Profiles App', function () {
+
+ it('should show list', 9, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 5);
+ test.assertSelectorContains('.js-list .list-group-item', 'Sonar way');
+ test.assertSelectorContains('.js-list .list-group-item', 'PSR-2');
+
+ test.assertElementCount('.js-list-language', 4);
+ test.assertSelectorContains('.js-list-language', 'Java');
+ test.assertSelectorContains('.js-list-language', 'JavaScript');
+ test.assertSelectorContains('.js-list-language', 'PHP');
+ test.assertSelectorContains('.js-list-language', 'Python');
+
+ test.assertElementCount('.js-list .badge', 4);
+ });
+ });
+
+ it('should filter list by language', 15, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 5);
+ test.assertVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');
+
+ test.assertElementCount('.js-list-language', 4);
+ test.assertVisible('.js-list-language[data-language="java"]');
+ test.assertVisible('.js-list-language[data-language="js"]');
+ })
+
+ .then(function () {
+ test.assertExists('#quality-profiles-filter-by-language');
+ casper.click('.js-filter-by-language[data-language="js"]');
+ })
+
+ .then(function () {
+ test.assertNotVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');
+ test.assertNotVisible('.js-list-language[data-language="java"]');
+ test.assertVisible('.js-list-language[data-language="js"]');
+ })
+
+ .then(function () {
+ casper.click('.js-filter-by-language:nth-child(1)');
+ })
+
+ .then(function () {
+ test.assertVisible('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ test.assertVisible('.js-list .list-group-item[data-key="js-sonar-way-71566"]');
+ test.assertVisible('.js-list-language[data-language="java"]');
+ test.assertVisible('.js-list-language[data-language="js"]');
+ });
+ });
+
+ it('should show details', 10, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json',
+ { data: { qprofile: 'java-sonar-way-67887', activation: 'true' } });
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json', {
+ data: { profileKey: 'java-sonar-way-67887' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item.active', 1);
+ test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');
+
+ test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');
+ test.assertSelectorContains('.search-navigator-workspace-header', 'Java');
+ test.assertExists('#quality-profile-backup');
+ test.assertDoesntExist('#quality-profile-rename');
+ test.assertDoesntExist('#quality-profile-copy');
+ test.assertDoesntExist('#quality-profile-delete');
+ test.assertDoesntExist('#quality-profile-set-as-default');
+ test.assertDoesntExist('#quality-profile-change-parent');
+ });
+ });
+
+ it('should show details for admin', 10, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json',
+ { data: { qprofile: 'java-sonar-way-67887', activation: 'true' } });
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json', {
+ data: { profileKey: 'java-sonar-way-67887' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item.active', 1);
+ test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');
+
+ test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');
+ test.assertSelectorContains('.search-navigator-workspace-header', 'Java');
+ test.assertExists('#quality-profile-backup');
+ test.assertExists('#quality-profile-rename');
+ test.assertExists('#quality-profile-copy');
+ test.assertDoesntExist('#quality-profile-delete');
+ test.assertDoesntExist('#quality-profile-set-as-default');
+ test.assertExists('#quality-profile-change-parent');
+ });
+ });
+
+ it('should show inheritance details', 10, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ lib.fmock('/api/qualityprofiles/search', 'search-inheritance.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance-plus.json', {
+ data: { profileKey: 'java-inherited-profile-85155' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('#quality-profile-ancestors li', 1);
+ test.assertSelectorContains('#quality-profile-ancestors', 'Sonar way');
+ test.assertSelectorContains('#quality-profile-ancestors', '161');
+
+ test.assertElementCount('#quality-profile-inheritance-current', 1);
+ test.assertSelectorContains('#quality-profile-inheritance-current', 'Inherited Profile');
+ test.assertSelectorContains('#quality-profile-inheritance-current', '163');
+ test.assertSelectorContains('#quality-profile-inheritance-current', '7');
+
+ test.assertElementCount('#quality-profile-children li', 1);
+ test.assertSelectorContains('#quality-profile-children', 'Second Level Inherited Profile');
+ test.assertSelectorContains('#quality-profile-children', '165');
+ });
+ });
+
+ it('should show selected projects', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/projects?key=php-psr-2-46772', 'projects.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]');
+ casper.waitForSelector('#quality-profile-projects');
+ })
+
+ .then(function () {
+ lib.waitForElementCount('#quality-profile-projects .select-list-list li', 2);
+ })
+
+ .then(function () {
+ test.assertSelectorContains('#quality-profile-projects .select-list-list li', 'CSS');
+ test.assertSelectorContains('#quality-profile-projects .select-list-list li', 'http-request-parent');
+ });
+ });
+
+ it('should move between profiles', 1, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search-inheritance.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ this.rulesMock = lib.fmock('/api/rules/search', 'rules.json',
+ { data: { qprofile: 'java-inherited-profile-85155', activation: 'true' } });
+ this.inheritanceMock = lib.fmock('/api/qualityprofiles/inheritance', 'inheritance-plus.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');
+ casper.waitForSelector('#quality-profile-ancestors');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.rulesMock);
+ lib.clearRequestMock(this.inheritanceMock);
+ lib.fmock('/api/rules/search', 'rules.json',
+ { data: { qprofile: 'java-sonar-way-67887', activation: 'true' } });
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+
+ casper.click('#quality-profile-ancestors .js-profile[data-key="java-sonar-way-67887"]');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'Sonar way');
+ });
+ });
+
+ it('should copy profile', 5, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/qualityprofiles/copy', 'copy.json', {
+ data: { fromKey: 'java-sonar-way-67887', toName: 'Copied Profile' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 5);
+ casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ casper.waitForSelector('#quality-profile-copy');
+ })
+
+ .then(function () {
+ casper.click('#quality-profile-copy');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#copy-profile-name').val('Copied Profile');
+ });
+ casper.click('#copy-profile-submit');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 6);
+ test.assertSelectorContains('.js-list .list-group-item.active', 'Copied Profile');
+ test.assertSelectorContains('.search-navigator-header-component', 'Copied Profile');
+ test.assertSelectorContains('.search-navigator-header-component', 'Java');
+ });
+ });
+
+ it('should rename profile', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.smock('/api/qualityprofiles/rename', '{}', {
+ data: { key: 'java-sonar-way-67887', name: 'Renamed Profile' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="java-sonar-way-67887"]');
+ casper.waitForSelector('#quality-profile-rename');
+ })
+
+ .then(function () {
+ casper.click('#quality-profile-rename');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.searchMock);
+ lib.fmock('/api/qualityprofiles/search', 'search-renamed.json');
+
+ casper.evaluate(function () {
+ jQuery('#rename-profile-name').val('Renamed Profile');
+ });
+ casper.click('#rename-profile-submit');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.js-list .list-group-item.active', 'Renamed Profile');
+ test.assertSelectorContains('.search-navigator-header-component', 'Renamed Profile');
+ });
+ });
+
+ it('should make profile default', 4, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.smock('/api/qualityprofiles/set_default', '{}', {
+ data: { profileKey: 'php-psr-2-46772' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge');
+ test.assertExists('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge');
+ casper.click('.js-list .list-group-item[data-key="php-psr-2-46772"]');
+ casper.waitForSelector('#quality-profile-set-as-default');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.searchMock);
+ lib.fmock('/api/qualityprofiles/search', 'search-another-default.json');
+
+ casper.click('#quality-profile-set-as-default');
+ casper.waitWhileSelector('.js-list .list-group-item[data-key="php-sonar-way-10778"] .badge');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('#quality-profile-set-as-default');
+ test.assertExists('.js-list .list-group-item[data-key="php-psr-2-46772"] .badge');
+ });
+ });
+
+ it('should delete profile', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.smock('/api/qualityprofiles/delete', '{}', {
+ data: { profileKey: 'java-copied-profile-11711' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 6);
+ casper.click('.js-list .list-group-item[data-key="java-copied-profile-11711"]');
+ casper.waitForSelector('#quality-profile-delete');
+ })
+
+ .then(function () {
+ casper.click('#quality-profile-delete');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.searchMock);
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+
+ casper.click('#delete-profile-submit');
+ lib.waitForElementCount('.js-list .list-group-item', 5);
+ })
+
+ .then(function () {
+ test.assertSelectorDoesntContain('.js-list .list-group-item', 'Copied Profile');
+ });
+ });
+
+ it('should create profile', 1, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/qualityprofiles/importers', 'importers-empty.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 5);
+ casper.click('#quality-profiles-create');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.searchMock);
+ lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');
+
+ casper.evaluate(function () {
+ jQuery('#create-profile-name').val('Copied Profile');
+ jQuery('#create-profile-language').val('java');
+ });
+ casper.click('#create-profile-submit');
+ lib.waitForElementCount('.js-list .list-group-item', 6);
+ });
+ });
+
+ it('should restore profile', 1, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 5);
+ casper.click('#quality-profiles-restore');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ casper.click('#restore-profile-submit');
+ lib.waitForElementCount('.js-list .list-group-item', 6);
+ });
+ });
+
+ it('should show importers', 6, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/qualityprofiles/importers', 'importers.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('#quality-profiles-create');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ test.assertVisible('.js-importer[data-key="pmd"]');
+ test.assertVisible('.js-importer[data-key="random"]');
+
+ casper.evaluate(function () {
+ jQuery('#create-profile-language').val('js').change();
+ });
+ })
+
+ .then(function () {
+ test.assertNotVisible('.js-importer[data-key="pmd"]');
+ test.assertVisible('.js-importer[data-key="random"]');
+
+ casper.evaluate(function () {
+ jQuery('#create-profile-language').val('py').change();
+ });
+ })
+
+ .then(function () {
+ test.assertNotVisible('.js-importer[data-key="pmd"]');
+ test.assertNotVisible('.js-importer[data-key="random"]');
+ });
+ });
+
+ it('should restore built-in profiles', 3, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search-modified.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.smock('/api/qualityprofiles/restore_built_in', '{}', {
+ data: { language: 'java' }
+ });
+ lib.fmock('/api/languages/list', 'languages.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item', 1);
+ casper.click('#quality-profiles-restore-built-in');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.searchMock);
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+
+ casper.evaluate(function () {
+ jQuery('#restore-built-in-profiles-language').val('java');
+ });
+ casper.click('#restore-built-in-profiles-submit');
+ lib.waitForElementCount('.js-list .list-group-item', 5);
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.js-list .list-group-item', 'Sonar way');
+ test.assertDoesntExist('.search-navigator-header-component');
+ });
+ });
+
+ it('should change profile\'s parent', 1, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ this.searchMock = lib.fmock('/api/qualityprofiles/search', 'search-change-parent.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ this.inheritanceMock = lib.fmock('/api/qualityprofiles/inheritance',
+ 'inheritance-change-parent.json');
+ lib.smock('/api/qualityprofiles/change_parent', '{}', {
+ data: { profileKey: 'java-inherited-profile-85155', parentKey: 'java-another-profile-00609' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-list .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');
+ casper.waitForSelector('#quality-profile-change-parent');
+ })
+
+ .then(function () {
+ casper.click('#quality-profile-change-parent');
+ casper.waitForSelector('.modal');
+ })
+
+ .then(function () {
+ lib.clearRequestMock(this.searchMock);
+ lib.fmock('/api/qualityprofiles/search', 'search-changed-parent.json');
+ lib.clearRequestMock(this.inheritanceMock);
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance-changed-parent.json');
+
+ casper.evaluate(function () {
+ jQuery('#change-profile-parent').val('java-another-profile-00609');
+ });
+ casper.click('#change-profile-parent-submit');
+ casper.waitForSelectorTextChange('#quality-profile-ancestors');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('#quality-profile-ancestors', 'Another Profile');
+ });
+ });
+
+ it('should open permalink', 9, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles#show?key=java-sonar-way-67887'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user-admin.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('#quality-profile-rename');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-list .list-group-item.active', 1);
+ test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');
+
+ test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');
+ test.assertSelectorContains('.search-navigator-workspace-header', 'Java');
+ test.assertExists('#quality-profile-backup');
+ test.assertExists('#quality-profile-rename');
+ test.assertExists('#quality-profile-copy');
+ test.assertDoesntExist('#quality-profile-delete');
+ test.assertDoesntExist('#quality-profile-set-as-default');
+ });
+ });
+
+ it('should show changelog', 22, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles#show?key=java-sonar-way-67887'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/qualityprofiles/changelog', 'changelog2.json', {
+ data: { p: '2', profileKey: 'java-sonar-way-67887' }
+ });
+ lib.fmock('/api/qualityprofiles/changelog', 'changelog.json', {
+ data: { profileKey: 'java-sonar-way-67887' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('#quality-profile-changelog-form-submit');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.js-show-more-changelog');
+
+ casper.click('#quality-profile-changelog-form-submit');
+ casper.waitForSelector('#quality-profile-changelog table');
+ })
+
+ .then(function () {
+ test.assertExists('.js-show-more-changelog');
+ test.assertElementCount('#quality-profile-changelog tbody tr', 2);
+
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'April 13 2015');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'System');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'ACTIVATED');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'Synchronisation should not');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'BLOCKER');
+
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'April 13 2015');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'Anakin Skywalker');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'ACTIVATED');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'Double.longBitsToDouble');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'threshold');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', '3');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'emptyParameter');
+
+ casper.click('.js-show-more-changelog');
+ lib.waitForElementCount('#quality-profile-changelog tbody tr', 3);
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.js-show-changelog');
+ test.assertDoesntExist('.js-show-more-changelog');
+
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'April 13 2015');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'System');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'DEACTIVATED');
+ test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'runFinalizersOnExit');
+ })
+
+ .then(function () {
+ casper.click('.js-hide-changelog');
+ test.assertDoesntExist('#quality-profile-changelog tbody tr');
+ });
+ });
+
+ it('should open changelog permalink', 2, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles#changelog?since=2015-03-25&key=java-sonar-way-67887&to=2015-03-26'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/qualityprofiles/changelog', 'changelog2.json', {
+ data: {
+ p: '2',
+ since: '2015-03-25',
+ to: '2015-03-26',
+ profileKey: 'java-sonar-way-67887'
+ }
+ });
+ lib.fmock('/api/qualityprofiles/changelog', 'changelog.json', {
+ data: {
+ since: '2015-03-25',
+ to: '2015-03-26',
+ profileKey: 'java-sonar-way-67887'
+ }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.js-show-more-changelog');
+ })
+
+ .then(function () {
+ test.assertElementCount('#quality-profile-changelog tbody tr', 2);
+
+ casper.click('.js-show-more-changelog');
+ lib.waitForElementCount('#quality-profile-changelog tbody tr', 3);
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.js-show-more-changelog');
+ });
+ });
+
+ it('should show comparison', 12, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles#show?key=java-sonar-way-67887'), function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/qualityprofiles/compare', 'compare.json', {
+ data: { leftKey: 'java-sonar-way-67887', rightKey: 'java-copied-profile-11711' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('#quality-profile-comparison-form-submit');
+ })
+
+ .then(function () {
+ test.assertElementCount('#quality-profile-comparison-with-key option', 1);
+ casper.click('#quality-profile-comparison-form-submit');
+ casper.waitForSelector('#quality-profile-comparison table');
+ })
+
+ .then(function () {
+ test.assertElementCount('.js-comparison-in-left', 2);
+ test.assertElementCount('.js-comparison-in-right', 2);
+ test.assertElementCount('.js-comparison-modified', 2);
+
+ test.assertSelectorContains('.js-comparison-in-left', '".equals()" should not be used to test');
+ test.assertSelectorContains('.js-comparison-in-left', '"@Override" annotation should be used on');
+
+ test.assertSelectorContains('.js-comparison-in-right', '"ConcurrentLinkedQueue.size()" should not be used');
+ test.assertSelectorContains('.js-comparison-in-right', '"compareTo" results should not be checked');
+
+ test.assertSelectorContains('.js-comparison-modified', 'Control flow statements');
+ test.assertSelectorContains('.js-comparison-modified', '"Cloneables" should implement "clone"');
+ test.assertSelectorContains('.js-comparison-modified', 'max: 5');
+ test.assertSelectorContains('.js-comparison-modified', 'max: 3');
+ });
+ });
+
+ it('should open comparison permalink', 4, function (casper, test) {
+ return casper
+ .start(lib.buildUrl('profiles#compare?key=java-sonar-way-67887&withKey=java-copied-profile-11711'),
+ function () {
+ lib.setDefaultViewport();
+
+ lib.fmock('/api/users/current', 'user.json');
+ lib.fmock('/api/qualityprofiles/search', 'search-with-copy.json');
+ lib.fmock('/api/qualityprofiles/exporters', 'exporters.json');
+ lib.fmock('/api/languages/list', 'languages.json');
+ lib.fmock('/api/rules/search', 'rules.json');
+ lib.fmock('/api/qualityprofiles/inheritance', 'inheritance.json');
+ lib.fmock('/api/qualityprofiles/compare', 'compare.json', {
+ data: { leftKey: 'java-sonar-way-67887', rightKey: 'java-copied-profile-11711' }
+ });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-profiles/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('#quality-profile-comparison table');
+ })
+
+ .then(function () {
+ test.assertElementCount('#quality-profile-comparison-with-key option', 1);
+ test.assertElementCount('.js-comparison-in-left', 2);
+ test.assertElementCount('.js-comparison-in-right', 2);
+ test.assertElementCount('.js-comparison-modified', 2);
+ });
+ });
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 5);
- casper.click('#quality-profiles-create');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- lib.clearRequestMock(this.searchMock);
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-with-copy.json');
-
- casper.evaluate(function () {
- jQuery('#create-profile-name').val('Copied Profile');
- jQuery('#create-profile-language').val('java');
- });
- casper.click('#create-profile-submit');
- lib.waitForElementCount('.js-list .list-group-item', 6);
- })
-
- .then(function () {
- test.assert(true);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Restore Profile'), 2, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 5);
- casper.click('#quality-profiles-restore');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- casper.click('#restore-profile-submit');
- lib.waitForElementCount('.js-list .list-group-item', 6);
- })
-
- .then(function () {
- test.assert(true);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Importers'), 6, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/qualityprofiles/importers', 'importers.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('#quality-profiles-create');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- test.assertVisible('.js-importer[data-key="pmd"]');
- test.assertVisible('.js-importer[data-key="random"]');
-
- casper.evaluate(function () {
- jQuery('#create-profile-language').val('js').change();
- });
- })
-
- .then(function () {
- test.assertNotVisible('.js-importer[data-key="pmd"]');
- test.assertVisible('.js-importer[data-key="random"]');
-
- casper.evaluate(function () {
- jQuery('#create-profile-language').val('py').change();
- });
- })
-
- .then(function () {
- test.assertNotVisible('.js-importer[data-key="pmd"]');
- test.assertNotVisible('.js-importer[data-key="random"]');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Restore Built-in Profiles'), 3, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-modified.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequest('/api/qualityprofiles/restore_built_in', '{}', {
- data: { language: 'java' }
- });
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item', 1);
- casper.click('#quality-profiles-restore-built-in');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- lib.clearRequestMock(this.searchMock);
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
-
- casper.evaluate(function () {
- jQuery('#restore-built-in-profiles-language').val('java');
- });
- casper.click('#restore-built-in-profiles-submit');
- lib.waitForElementCount('.js-list .list-group-item', 5);
- })
-
- .then(function () {
- test.assertSelectorContains('.js-list .list-group-item', 'Sonar way');
- test.assertDoesntExist('.search-navigator-header-component');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Change Parent'), 1, function (test) {
- casper
- .start(lib.buildUrl('profiles'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- this.searchMock = lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-change-parent.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- this.inheritanceMock = lib.mockRequestFromFile('/api/qualityprofiles/inheritance',
- 'inheritance-change-parent.json');
- lib.mockRequest('/api/qualityprofiles/change_parent', '{}', {
- data: { profileKey: 'java-inherited-profile-85155', parentKey: 'java-another-profile-00609' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- jQuery.ajaxSetup({ dataType: 'json' });
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-list .list-group-item');
- })
-
- .then(function () {
- casper.click('.js-list .list-group-item[data-key="java-inherited-profile-85155"]');
- casper.waitForSelector('#quality-profile-change-parent');
- })
-
- .then(function () {
- casper.click('#quality-profile-change-parent');
- casper.waitForSelector('.modal');
- })
-
- .then(function () {
- lib.clearRequestMock(this.searchMock);
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-changed-parent.json');
- lib.clearRequestMock(this.inheritanceMock);
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance-changed-parent.json');
-
- casper.evaluate(function () {
- jQuery('#change-profile-parent').val('java-another-profile-00609');
- });
- casper.click('#change-profile-parent-submit');
- casper.waitForSelectorTextChange('#quality-profile-ancestors');
- })
-
- .then(function () {
- test.assertSelectorContains('#quality-profile-ancestors', 'Another Profile');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Permalink'), 9, function (test) {
- casper
- .start(lib.buildUrl('profiles#show?key=java-sonar-way-67887'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user-admin.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('#quality-profile-rename');
- })
-
- .then(function () {
- test.assertElementCount('.js-list .list-group-item.active', 1);
- test.assertSelectorContains('.js-list .list-group-item.active', 'Sonar way');
-
- test.assertSelectorContains('.search-navigator-workspace-header', 'Sonar way');
- test.assertSelectorContains('.search-navigator-workspace-header', 'Java');
- test.assertExists('#quality-profile-backup');
- test.assertExists('#quality-profile-rename');
- test.assertExists('#quality-profile-copy');
- test.assertDoesntExist('#quality-profile-delete');
- test.assertDoesntExist('#quality-profile-set-as-default');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Changelog'), 22, function (test) {
- casper
- .start(lib.buildUrl('profiles#show?key=java-sonar-way-67887'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog2.json', {
- data: { p: '2', profileKey: 'java-sonar-way-67887' }
- });
- lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog.json', {
- data: { profileKey: 'java-sonar-way-67887' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('#quality-profile-changelog-form-submit');
- })
-
- .then(function () {
- test.assertDoesntExist('.js-show-more-changelog');
-
- casper.click('#quality-profile-changelog-form-submit');
- casper.waitForSelector('#quality-profile-changelog table');
- })
-
- .then(function () {
- test.assertExists('.js-show-more-changelog');
- test.assertElementCount('#quality-profile-changelog tbody tr', 2);
-
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'April 13 2015');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'System');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'ACTIVATED');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'Synchronisation should not');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(1)', 'BLOCKER');
-
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'April 13 2015');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'Anakin Skywalker');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'ACTIVATED');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'Double.longBitsToDouble');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'threshold');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', '3');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(2)', 'emptyParameter');
-
- casper.click('.js-show-more-changelog');
- lib.waitForElementCount('#quality-profile-changelog tbody tr', 3);
- })
-
- .then(function () {
- test.assertDoesntExist('.js-show-changelog');
- test.assertDoesntExist('.js-show-more-changelog');
-
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'April 13 2015');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'System');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'DEACTIVATED');
- test.assertSelectorContains('#quality-profile-changelog tbody tr:nth-child(3)', 'runFinalizersOnExit');
- })
-
- .then(function () {
- casper.click('.js-hide-changelog');
- test.assertDoesntExist('#quality-profile-changelog tbody tr');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Changelog Permalink'), 2, function (test) {
- casper
- .start(lib.buildUrl('profiles#changelog?since=2015-03-25&key=java-sonar-way-67887&to=2015-03-26'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog2.json', {
- data: {
- p: '2',
- since: '2015-03-25',
- to: '2015-03-26',
- profileKey: 'java-sonar-way-67887'
- }
- });
- lib.mockRequestFromFile('/api/qualityprofiles/changelog', 'changelog.json', {
- data: {
- since: '2015-03-25',
- to: '2015-03-26',
- profileKey: 'java-sonar-way-67887'
- }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('.js-show-more-changelog');
- })
-
- .then(function () {
- test.assertElementCount('#quality-profile-changelog tbody tr', 2);
-
- casper.click('.js-show-more-changelog');
- lib.waitForElementCount('#quality-profile-changelog tbody tr', 3);
- })
-
- .then(function () {
- test.assertDoesntExist('.js-show-more-changelog');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Comparison'), 12, function (test) {
- casper
- .start(lib.buildUrl('profiles#show?key=java-sonar-way-67887'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-with-copy.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/compare', 'compare.json', {
- data: { leftKey: 'java-sonar-way-67887', rightKey: 'java-copied-profile-11711' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('#quality-profile-comparison-form-submit');
- })
-
- .then(function () {
- test.assertElementCount('#quality-profile-comparison-with-key option', 1);
- casper.click('#quality-profile-comparison-form-submit');
- casper.waitForSelector('#quality-profile-comparison table');
- })
-
- .then(function () {
- test.assertElementCount('.js-comparison-in-left', 2);
- test.assertElementCount('.js-comparison-in-right', 2);
- test.assertElementCount('.js-comparison-modified', 2);
-
- test.assertSelectorContains('.js-comparison-in-left', '".equals()" should not be used to test');
- test.assertSelectorContains('.js-comparison-in-left', '"@Override" annotation should be used on');
-
- test.assertSelectorContains('.js-comparison-in-right', '"ConcurrentLinkedQueue.size()" should not be used');
- test.assertSelectorContains('.js-comparison-in-right', '"compareTo" results should not be checked');
-
- test.assertSelectorContains('.js-comparison-modified', 'Control flow statements');
- test.assertSelectorContains('.js-comparison-modified', '"Cloneables" should implement "clone"');
- test.assertSelectorContains('.js-comparison-modified', 'max: 5');
- test.assertSelectorContains('.js-comparison-modified', 'max: 3');
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
-});
-
-
-casper.test.begin(testName('Comparison Permalink'), 4, function (test) {
- casper
- .start(lib.buildUrl('profiles#compare?key=java-sonar-way-67887&withKey=java-copied-profile-11711'), function () {
- lib.setDefaultViewport();
-
- lib.mockRequestFromFile('/api/users/current', 'user.json');
- lib.mockRequestFromFile('/api/qualityprofiles/search', 'search-with-copy.json');
- lib.mockRequestFromFile('/api/qualityprofiles/exporters', 'exporters.json');
- lib.mockRequestFromFile('/api/languages/list', 'languages.json');
- lib.mockRequestFromFile('/api/rules/search', 'rules.json');
- lib.mockRequestFromFile('/api/qualityprofiles/inheritance', 'inheritance.json');
- lib.mockRequestFromFile('/api/qualityprofiles/compare', 'compare.json', {
- data: { leftKey: 'java-sonar-way-67887', rightKey: 'java-copied-profile-11711' }
- });
- })
-
- .then(function () {
- casper.evaluate(function () {
- require(['apps/quality-profiles/app']);
- });
- })
-
- .then(function () {
- casper.waitForSelector('#quality-profile-comparison table');
- })
-
- .then(function () {
- test.assertElementCount('#quality-profile-comparison-with-key option', 1);
- test.assertElementCount('.js-comparison-in-left', 2);
- test.assertElementCount('.js-comparison-in-right', 2);
- test.assertElementCount('.js-comparison-modified', 2);
- })
-
- .then(function () {
- lib.sendCoverage();
- })
-
- .run(function () {
- test.done();
- });
});
diff --git a/server/sonar-web/src/test/lib.js b/server/sonar-web/src/test/lib.js
index f1bec2eb442..b0dde173ef9 100644
--- a/server/sonar-web/src/test/lib.js
+++ b/server/sonar-web/src/test/lib.js
@@ -1,24 +1,5 @@
-/*
- * 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, exports: false */
-
+/* jshint node:true */
+/* globals casper: false */
var fs = require('fs');
var getPort = function () {
@@ -31,7 +12,7 @@ var BASE_URL = 'http://localhost:' + getPort() + '/pages/',
WINDOW_HEIGHT = 800;
-exports.initMessages = function () {
+var initMessages = function () {
if (casper.cli.options.verbose) {
// Dump log messages
casper.removeAllListeners('remote.message');
@@ -46,13 +27,23 @@ exports.initMessages = function () {
});
}
};
+exports.initMessages = initMessages;
+
+function getFileName(path) {
+ var idx = path.lastIndexOf(fs.separator),
+ dotIdx = path.lastIndexOf('.');
+ return path.substr(idx + 1, dotIdx - idx - 1);
+}
-exports.changeWorkingDirectory = function (dir) {
+var changeWorkingDirectory = exports.changeWorkingDirectory = function (dir) {
var commandLineArgs = require('system').args;
// Since Casper has control, the invoked script is deep in the argument stack
// commandLineArgs = casper/bin/bootstrap.js,--casper-path=.../casperjs,--cli,--test,[file(s) under test],[options]
var currentFile = commandLineArgs[4];
+ if (!dir) {
+ dir = getFileName(currentFile);
+ }
var curFilePath = currentFile.split(fs.separator);
if (curFilePath.length > 1) {
curFilePath.pop(); // test name
@@ -82,27 +73,27 @@ exports.testName = function () {
var mockRequest = function (url, response, options) {
return casper.evaluate(function (url, response, options) {
- return jQuery.mockjax(_.extend({ url: url, responseText: response}, options));
+ return jQuery.mockjax(_.extend({ url: url, responseText: response }, options));
}, url, response, options || {});
};
-exports.mockRequest = mockRequest;
+exports.mockRequest = exports.smock = mockRequest;
-exports.mockRequestFromFile = function (url, fileName, options) {
+exports.mockRequestFromFile = exports.fmock = function (url, fileName, options) {
var response = fs.read(fileName);
return mockRequest(url, response, options);
};
exports.clearRequestMocks = function () {
- casper.evaluate(function() {
+ casper.evaluate(function () {
jQuery.mockjaxClear();
});
};
exports.clearRequestMock = function (mockId) {
- casper.evaluate(function(mockId) {
+ casper.evaluate(function (mockId) {
jQuery.mockjaxClear(mockId);
}, mockId);
};
@@ -111,7 +102,7 @@ exports.clearRequestMock = function (mockId) {
function patchWithTimestamp(url) {
var t = Date.now(),
hashStart = url.indexOf('#'),
- hash = hashStart !== -1 ? url.substr(hashStart) : '',
+ hash = hashStart !== -1 ? url.substr(hashStart) : '',
base = hashStart !== -1 ? url.substr(0, hashStart) : url;
return base + '?' + t + hash;
}
@@ -136,7 +127,9 @@ exports.capture = function (fileName) {
if (!fileName) {
fileName = 'screenshot.png';
}
- casper.capture(fileName, { top: 0, left: 0, width: WINDOW_WIDTH, height: WINDOW_HEIGHT });
+ casper.wait(500, function () {
+ casper.capture(fileName, { top: 0, left: 0, width: WINDOW_WIDTH, height: WINDOW_HEIGHT });
+ });
};
@@ -158,35 +151,62 @@ exports.waitWhileElementCount = function (selector, count, callback) {
};
-exports.assertLinkHref = function assertElementCount(selector, href, message) {
- var linkHref = this.casper.evaluate(function(selector) {
- return document.querySelector(selector);
- }, selector);
- return this.assert(elementCount === count, message, {
- type: "assertElementCount",
- standard: f('%d element%s matching selector "%s" found',
- count,
- count > 1 ? 's' : '',
- selector),
- values: {
- selector: selector,
- expected: count,
- obtained: elementCount
+var sendCoverage = exports.sendCoverage = function () {
+ return casper.evaluate(function () {
+ if (window.__coverage__) {
+ jQuery.ajax({
+ type: 'POST',
+ url: '/coverage/client',
+ data: JSON.stringify(window.__coverage__),
+ processData: false,
+ contentType: 'application/json; charset=UTF-8',
+ async: false
+ });
}
});
};
-exports.sendCoverage = function () {
- return casper.evaluate(function () {
- jQuery.ajax({
- type: 'POST',
- url: '/coverage/client',
- data: JSON.stringify(window.__coverage__),
- processData: false,
- contentType: 'application/json; charset=UTF-8',
- async: false
- });
+var describe = global.describe = function (name, fn) {
+ this._extraName = name;
+ casper.options.waitTimeout = 20000;
+ initMessages();
+ changeWorkingDirectory();
+ fn();
+};
+
+
+var it = global.it = function (name, testCount, fn) {
+ var testName = this._extraName + ' ' + name;
+ var patchedFn = function (test) {
+ var startTime = new Date().getTime();
+ fn(casper, test)
+ .then(function () {
+ var endTime = new Date().getTime();
+ test.assert(true, '✓ done within ' + (endTime - startTime) + 'ms');
+ })
+ .then(function () {
+ sendCoverage();
+ })
+ .run(function () {
+ test.done();
+ });
+ };
+
+ // increase test count by 1 for the additional `test.assert()` statement
+ testCount++;
+
+ return casper.test.begin(testName, testCount, patchedFn);
+};
+
+
+var xit = global.xit = function (name) {
+ var testName = this._extraName + ' ' + name;
+ return casper.test.begin(testName, function (test) {
+ casper
+ .echo('IGNORED', 'WARNING')
+ .run(function () {
+ test.done();
+ });
});
- casper.wait(500);
};