aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/test/js/quality-gates-spec.js
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-05-27 12:48:41 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-05-27 12:49:16 +0200
commit14316c4e9fa4efe86b0b0a57fbbdadc2fcd96a9c (patch)
tree3727f1fc87239ed40e7a78461c1a68d6c1b383ae /server/sonar-web/src/test/js/quality-gates-spec.js
parent75812512ce0a0f1b8b946796bacb548c96980663 (diff)
downloadsonarqube-14316c4e9fa4efe86b0b0a57fbbdadc2fcd96a9c.tar.gz
sonarqube-14316c4e9fa4efe86b0b0a57fbbdadc2fcd96a9c.zip
add web tests for quality gates page
Diffstat (limited to 'server/sonar-web/src/test/js/quality-gates-spec.js')
-rw-r--r--server/sonar-web/src/test/js/quality-gates-spec.js570
1 files changed, 561 insertions, 9 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 ec78d267a17..6c1d34cd6f5 100644
--- a/server/sonar-web/src/test/js/quality-gates-spec.js
+++ b/server/sonar-web/src/test/js/quality-gates-spec.js
@@ -19,50 +19,602 @@
*/
/* global casper:false */
-var lib = require('../lib');
+var lib = require('../lib'),
+ testName = lib.testName('Quality Gates');
lib.initMessages();
lib.changeWorkingDirectory('quality-gates-spec');
lib.configureCasper();
-casper.test.begin('Quality Gates', function suite (test) {
+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-gate/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.quality-gates-results .list-group-item');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gates-results .list-group-item', 3);
+ test.assertSelectorContains('.quality-gates-results .list-group-item', 'SonarQube way');
+ test.assertSelectorContains('.quality-gates-results .list-group-item', 'Simple Gate');
+ test.assertSelectorContains('.quality-gates-results .list-group-item', 'Another Gate');
+
+ test.assertElementCount('.quality-gates-results .badge', 1);
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Show Details', 'Anonymous'), 12, function (test) {
+ 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?id=1', 'show.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.quality-gates-results .list-group-item');
+ })
+
+ .then(function () {
+ // FIXME use better selector
+ casper.click('.quality-gates-results .list-group-item:last-child');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gates-results .list-group-item.active', 1);
+ test.assertSelectorContains('.quality-gates-results .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('.quality-gate-conditions');
+ test.assertElementCount('.quality-gate-conditions tbody tr', 8);
+ test.assertDoesntExist('.quality-gate-conditions .update-condition');
+ test.assertDoesntExist('.quality-gate-conditions .delete-condition');
+
+ test.assertExists('.quality-gate-default-message');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Show Details', 'Admin'), 12, 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');
+ lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.quality-gates-results .list-group-item');
+ })
+
+ .then(function () {
+ // FIXME use better selector
+ casper.click('.quality-gates-results .list-group-item:last-child');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gates-results .list-group-item.active', 1);
+ test.assertSelectorContains('.quality-gates-results .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-unset-as-default');
+ test.assertExists('#quality-gate-delete');
+
+ test.assertExists('.quality-gate-conditions');
+ test.assertElementCount('.quality-gate-conditions tbody tr', 8);
+ test.assertElementCount('.quality-gate-conditions .update-condition', 8);
+ test.assertElementCount('.quality-gate-conditions .delete-condition', 8);
+
+ test.assertExists('.quality-gate-default-message');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Rename'), 2, function (test) {
+ casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
+ lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
+ lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
+ lib.mockRequestFromFile('/api/qualitygates/rename', 'rename.json', { data: { id: '1', name: 'New Name' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ casper.click('#quality-gate-rename');
+ casper.waitUntilVisible('#quality-gate-edit-name');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-edit-name').val('New Name');
+ });
+ casper.click('.modal-foot button');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'New Name');
+ test.assertSelectorContains('.quality-gates-results .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();
+ lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
+ lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
+ lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
+ lib.mockRequestFromFile('/api/qualitygates/copy', 'copy.json', { data: { id: '1', name: 'New Name' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ casper.click('#quality-gate-copy');
+ casper.waitUntilVisible('#quality-gate-edit-name');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-edit-name').val('New Name');
+ });
+ casper.click('.modal-foot button');
+ casper.waitForSelectorTextChange('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'New Name');
+ test.assertSelectorContains('.quality-gates-results .list-group-item.active', 'New Name');
+ test.assertSelectorContains('.quality-gates-results .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?id=5', 'show-another.json');
+ lib.mockRequest('/api/qualitygates/set_as_default', '{}', { data: { id: '5' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.quality-gates-results .list-group-item.active .badge');
+ test.assertDoesntExist('.quality-gate-default-message');
+ casper.click('#quality-gate-set-as-default');
+ casper.waitForSelector('.quality-gates-results .list-group-item.active .badge');
+ })
+
+ .then(function () {
+ test.assertExists('.quality-gate-default-message');
+ test.assertElementCount('.quality-gates-results .badge', 1);
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Unset As Default'), 4, function (test) {
+ casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
+ lib.mockRequest('/api/qualitygates/unset_default', '{}');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertExists('.quality-gates-results .list-group-item.active .badge');
+ test.assertExists('.quality-gate-default-message');
+ casper.click('#quality-gate-unset-as-default');
+ casper.waitWhileSelector('.quality-gates-results .list-group-item.active .badge');
+ })
+
+ .then(function () {
+ test.assertDoesntExist('.quality-gate-default-message');
+ test.assertDoesntExist('.quality-gates-results .badge');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Create'), 2, 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');
+ lib.mockRequestFromFile('/api/qualitygates/create', 'create.json', { data: { name: 'New Name' } });
+ lib.mockRequestFromFile('/api/qualitygates/show?id=6', 'show-created.json');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.quality-gates-results .list-group-item');
+ })
+
+ .then(function () {
+ casper.click('#quality-gate-add');
+ casper.waitUntilVisible('#quality-gate-edit-name');
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ jQuery('#quality-gate-edit-name').val('New Name');
+ });
+ casper.click('.modal-foot button');
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertSelectorContains('.search-navigator-header-component', 'New Name');
+ test.assertSelectorContains('.quality-gates-results .list-group-item.active', 'New Name');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Delete'), 2, 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?id=5', 'show-another.json');
+ lib.mockRequest('/api/qualitygates/destroy', '{}', { data: { id: '5' } });
+ })
+
+ .then(function () {
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gates-results .list-group-item', 3);
+ casper.click('#quality-gate-delete');
+ casper.waitForSelector('button[data-confirm="yes"]');
+ })
+
+ .then(function () {
+ casper.click('button[data-confirm="yes"]');
+ casper.waitWhileSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gates-results .list-group-item', 2);
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Add Condition'), 6, 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?id=5', 'show-another.json');
+ lib.mockRequestFromFile('/api/qualitygates/create_condition', 'create-condition.json',
+ { data: { metric: 'complexity', op: 'GT', period: '1', warning: '3', error: '4' } });
})
.then(function () {
casper.evaluate(function () {
require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
+ });
+ })
+
+ .then(function () {
+ casper.waitForSelector('.search-navigator-header-component');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gate-conditions [name="error"]', 0);
+
+ casper.evaluate(function () {
+ jQuery('#quality-gate-new-condition-metric').val('complexity').change();
+ });
+ test.assertElementCount('.quality-gate-conditions [name="error"]', 1);
+ })
+
+ .then(function () {
+ casper.click('.cancel-add-condition');
+ casper.waitWhileSelector('.cancel-add-condition');
+ })
+
+ .then(function () {
+ test.assertElementCount('.quality-gate-conditions [name="error"]', 0);
+
+ casper.evaluate(function () {
+ jQuery('#quality-gate-new-condition-metric').val('complexity').change();
});
+ test.assertElementCount('.quality-gate-conditions [name="error"]', 1);
+
+ 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.test.begin(testName('Should Update Condition'), 3, function (test) {
+ casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
+ lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
+ lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
+ lib.mockRequestFromFile('/api/qualitygates/update_condition', 'update-condition.json',
+ { data: { id: '1', warning: '173' } });
})
.then(function () {
- casper.waitForSelector('.active', function () {
- test.assertElementCount('.active', 1);
- test.assertSelectorHasText('.search-navigator-side .active', 'Default Gate');
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
});
})
.then(function () {
- casper.waitForSelector('.search-navigator-workspace-header', function () {
- test.assertSelectorHasText('.search-navigator-workspace-header', 'Default Gate');
+ casper.waitForSelector('.update-condition');
+ })
+
+ .then(function () {
+ test.assertExists('.quality-gate-conditions tr:first-child .update-condition[disabled]');
+ casper.evaluate(function () {
+ jQuery('.quality-gate-conditions tr:first-child [name="warning"]').val('173').change();
});
+ test.assertDoesntExist('.quality-gate-conditions tr:first-child .update-condition[disabled]');
+ casper.click('.quality-gate-conditions tr:first-child .update-condition');
+ casper.waitWhileSelector('.quality-gate-conditions tr:first-child .update-condition:not([disabled])');
+ })
+
+ .then(function () {
+ test.assertExists('.quality-gate-conditions tr:first-child .update-condition[disabled]');
+ })
+
+ .then(function () {
+ lib.sendCoverage();
+ })
+
+ .run(function () {
+ test.done();
+ });
+});
+
+
+casper.test.begin(testName('Should Delete Condition'), 2, function (test) {
+ casper
+ .start(lib.buildUrl('quality_gates#show/1'), function () {
+ lib.setDefaultViewport();
+
+ lib.mockRequestFromFile('/api/qualitygates/app', 'app.json');
+ lib.mockRequestFromFile('/api/qualitygates/list', 'list.json');
+ lib.mockRequestFromFile('/api/qualitygates/show?id=1', 'show.json');
+ lib.mockRequest('/api/qualitygates/delete_condition', '{}', { data: { id: '1' } });
})
.then(function () {
- casper.waitForSelector('table.quality-gate-conditions tbody tr:nth-child(9)', function () {
- test.assertElementCount('table.quality-gate-conditions tbody tr', 9);
+ casper.evaluate(function () {
+ require(['apps/quality-gate/app']);
+ jQuery.ajaxSetup({ dataType: 'json' });
});
})
.then(function () {
+ casper.waitForSelector('.delete-condition');
+ })
+
+ .then(function () {
+ test.assertElementCount('.delete-condition', 8);
+
+ casper.click('.quality-gate-conditions tr:first-child .delete-condition');
+ casper.waitForSelector('button[data-confirm="yes"]');
+ })
+
+ .then(function () {
+ casper.click('button[data-confirm="yes"]');
+ lib.waitForElementCount('.delete-condition', 7);
+ })
+
+ .then(function () {
+ test.assert(true);
+ })
+
+ .then(function () {
lib.sendCoverage();
})