aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-07-02 16:37:58 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-07-02 17:19:20 +0200
commit9b9614ff7ed5153df2a2d7d2a1f40338c0c3f76f (patch)
tree6b1ff71dffbafc8bc4c29a711ac3be1d6471f4cd
parent2baae4090d4085aaadcae384bfe901e97a256cca (diff)
downloadsonarqube-9b9614ff7ed5153df2a2d7d2a1f40338c0c3f76f.tar.gz
sonarqube-9b9614ff7ed5153df2a2d7d2a1f40338c0c3f76f.zip
add issues web tests
-rw-r--r--server/sonar-web/test/helpers/test-page.js67
-rw-r--r--server/sonar-web/test/medium/issues.spec.js166
2 files changed, 217 insertions, 16 deletions
diff --git a/server/sonar-web/test/helpers/test-page.js b/server/sonar-web/test/helpers/test-page.js
index 978e09b05cf..4b6df7a9875 100644
--- a/server/sonar-web/test/helpers/test-page.js
+++ b/server/sonar-web/test/helpers/test-page.js
@@ -3,6 +3,7 @@ define(function (require) {
var assert = require('intern/chai!assert');
var fs = require('intern/dojo/node!fs');
var Command = require('intern/dojo/node!leadfoot/Command');
+ var pollUntil = require('intern/dojo/node!leadfoot/helpers/pollUntil');
Command.prototype.assertElementCount = function (selector, count) {
return new this.constructor(this, function () {
@@ -15,6 +16,28 @@ define(function (require) {
});
};
+ Command.prototype.assertElementExist = function (selector) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findAllByCssSelector(selector)
+ .then(function (elements) {
+ assert.ok(elements.length, selector + ' exists');
+ })
+ .end();
+ });
+ };
+
+ Command.prototype.assertElementNotExist = function (selector) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findAllByCssSelector(selector)
+ .then(function (elements) {
+ assert.equal(elements.length, 0, selector + ' does not exist');
+ })
+ .end();
+ });
+ };
+
Command.prototype.assertElementInclude = function (selector, text) {
return new this.constructor(this, function () {
return this.parent
@@ -39,12 +62,25 @@ define(function (require) {
});
};
+ Command.prototype.assertElementVisible = function (selector) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findAllByCssSelector(selector)
+ .isDisplayed()
+ .then(function (displayed) {
+ assert.ok(displayed, selector + ' is visible');
+ })
+ .end();
+ });
+ };
+
Command.prototype.clickElement = function (selector) {
return new this.constructor(this, function () {
return this.parent
.findByCssSelector(selector)
.click()
- .end();
+ .end()
+ .sleep(250);
});
};
@@ -57,22 +93,32 @@ define(function (require) {
});
};
- Command.prototype.mockFromFile = function (url, file) {
+ Command.prototype.waitForElementCount = function (selector, count) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .then(pollUntil(function (selector, count) {
+ var elements = document.querySelectorAll(selector);
+ return elements.length === count ? true : null;
+ }, [selector, count]));
+ });
+ };
+
+ Command.prototype.mockFromFile = function (url, file, options) {
var response = fs.readFileSync('src/test/json/' + file, 'utf-8');
return new this.constructor(this, function () {
return this.parent
- .execute(function (url, response) {
- return jQuery.mockjax(_.extend({ url: url, responseText: response }));
- }, [url, response]);
+ .execute(function (url, response, options) {
+ return jQuery.mockjax(_.extend({ url: url, responseText: response }, options));
+ }, [url, response, options]);
});
};
- Command.prototype.mockFromString = function (url, response) {
+ Command.prototype.mockFromString = function (url, response, options) {
return new this.constructor(this, function () {
return this.parent
- .execute(function (url, response) {
- return jQuery.mockjax(_.extend({ url: url, responseText: response }));
- }, [url, response]);
+ .execute(function (url, response, options) {
+ return jQuery.mockjax(_.extend({ url: url, responseText: response }, options));
+ }, [url, response, options]);
});
};
@@ -92,7 +138,8 @@ define(function (require) {
require(['apps/' + app + '/app'], function (App) {
App.start({ el: '#content' });
});
- }, [app]);
+ }, [app])
+ .sleep(2000);
});
};
diff --git a/server/sonar-web/test/medium/issues.spec.js b/server/sonar-web/test/medium/issues.spec.js
index 4987c91aa4c..eb990de1c8a 100644
--- a/server/sonar-web/test/medium/issues.spec.js
+++ b/server/sonar-web/test/medium/issues.spec.js
@@ -7,20 +7,18 @@ define(function (require) {
bdd.it('should show list of saved searches', function () {
return this.remote
.get(require.toUrl('test/medium/base.html'))
- .setFindTimeout(5000)
.mockFromString('/api/l10n/index', '{}')
.mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
.mockFromFile('/api/issues/search', 'issues-spec/search.json')
.startApp('issues')
- .assertElementCount('.js-filter', 2)
- .assertElementCount('.js-filter[data-id="31"]', 1)
- .assertElementCount('.js-filter[data-id="32"]', 1);
+ .waitForElementCount('.js-filter', 2)
+ .waitForElementCount('.js-filter[data-id="31"]', 1)
+ .waitForElementCount('.js-filter[data-id="32"]', 1);
});
bdd.it('should load a saved search', function () {
return this.remote
.get(require.toUrl('test/medium/base.html'))
- .setFindTimeout(5000)
.mockFromString('/api/l10n/index', '{}')
.mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
.mockFromFile('/api/issues/search', 'issues-spec/search.json')
@@ -39,7 +37,6 @@ define(function (require) {
bdd.it('should load a saved search and then resets it by new search', function () {
return this.remote
.get(require.toUrl('test/medium/base.html'))
- .setFindTimeout(5000)
.mockFromString('/api/l10n/index', '{}')
.mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
.mockFromFile('/api/issues/search', 'issues-spec/search.json')
@@ -60,6 +57,163 @@ define(function (require) {
.assertElementNotInclude('.issues-filters-name', 'Critical and Blocker Issues');
});
});
+
+ bdd.it('should load', function () {
+ return this.remote
+ .get(require.toUrl('test/medium/base.html'))
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
+ .mockFromFile('/api/issues/search', 'issues-spec/search.json')
+ .startApp('issues')
+ .clickElement('.js-new-search')
+ .assertElementExist('.facet[data-value=BLOCKER]')
+ .assertElementExist('.facet[data-value=CRITICAL]')
+ .assertElementExist('.facet[data-value=MAJOR]')
+ .assertElementExist('.facet[data-value=MINOR]')
+ .assertElementExist('.facet[data-value=INFO]')
+
+ .assertElementExist('.facet[data-value=OPEN]')
+ .assertElementExist('.facet[data-value=REOPENED]')
+ .assertElementExist('.facet[data-value=CONFIRMED]')
+ .assertElementExist('.facet[data-value=RESOLVED]')
+ .assertElementExist('.facet[data-value=CLOSED]')
+
+ .assertElementExist('.facet[data-unresolved]')
+ .assertElementExist('.facet[data-value=REMOVED]')
+ .assertElementExist('.facet[data-value=FIXED]')
+ .assertElementExist('.facet[data-value=FALSE-POSITIVE]')
+
+ .assertElementCount('.issue', 50)
+ .assertElementCount('.issue.selected', 1)
+ //.assertElementInclude('.issue', '1 more branches need to be covered by unit tests to reach')
+
+ .assertElementExist('.js-new-search')
+ .assertElementExist('.js-filter-save-as')
+
+ .assertElementInclude('#issues-total', '4623')
+ .assertElementExist('.js-prev')
+ .assertElementExist('.js-next')
+ .assertElementExist('.js-reload')
+ .assertElementExist('.js-bulk-change');
+ });
+
+ bdd.it('should show severity facet', function () {
+ return this.remote
+ .get(require.toUrl('test/medium/base.html'))
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
+ .mockFromFile('/api/issues/search', 'issues-spec/search.json')
+ .startApp('issues')
+ .clickElement('.js-new-search')
+ .waitForElementCount('.issue', 50)
+ .clearMocks()
+ .mockFromFile('/api/issues/search', 'issues-spec/search-reopened.json', { data: { severities: 'BLOCKER' } })
+ .clickElement('.facet[data-value=BLOCKER]')
+ .waitForElementCount('.issue', 4);
+ });
+
+ bdd.it('should select issues', function () {
+ var issueKey = '94357807-fcb4-40cc-9598-9a715f1eee6e',
+ issueSelector = '.issue[data-key="' + issueKey + '"]';
+
+ return this.remote
+ .get(require.toUrl('test/medium/base.html'))
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
+ .mockFromFile('/api/issues/search', 'issues-spec/search.json')
+ .startApp('issues')
+ .clickElement('.js-new-search')
+ .assertElementExist('.js-selection')
+ .assertElementNotExist('.js-selection.icon-checkbox-checked')
+ .assertElementExist('.issue .js-toggle')
+ .assertElementCount('.js-toggle', 50)
+ .assertElementNotExist(issueSelector + ' .js-toggle .icon-checkbox-checked')
+ .clickElement(issueSelector + ' .js-toggle')
+ .assertElementExist(issueSelector + ' .js-toggle .icon-checkbox-checked')
+ .assertElementExist('.js-selection.icon-checkbox-single.icon-checkbox-checked')
+ .clickElement('.js-selection')
+ .assertElementNotExist('.js-selection.icon-checkbox-checked')
+ .assertElementNotExist('.js-toggle .icon-checkbox-checked')
+ .clickElement('.js-selection')
+ .assertElementExist('.js-selection.icon-checkbox-checked')
+ .assertElementCount('.js-toggle .icon-checkbox-checked', 50);
+ });
+
+ bdd.it('should bulk change issues', function () {
+ return this.remote
+ .get(require.toUrl('test/medium/base.html'))
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
+ .mockFromFile('/api/issues/search', 'issues-spec/search.json')
+ .mockFromString('/issues/bulk_change_form*',
+ '<div id="bulk-change-form">bulk change form</div>', { contentType: 'text/plain' })
+ .startApp('issues')
+ .clickElement('.js-new-search')
+ .clickElement('#issues-bulk-change')
+ .clickElement('.js-bulk-change')
+ .assertElementExist('#bulk-change-form')
+ .assertElementInclude('#bulk-change-form', 'bulk change form');
+ });
+
+ bdd.it('should bulk change selected issues', function () {
+ var issueKey = '94357807-fcb4-40cc-9598-9a715f1eee6e',
+ issueSelector = '.issue[data-key="' + issueKey + '"]';
+
+ return this.remote
+ .get(require.toUrl('test/medium/base.html'))
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
+ .mockFromFile('/api/issues/search', 'issues-spec/search.json')
+ .mockFromString('/issues/bulk_change_form*',
+ '<div id="bulk-change-form">bulk change form</div>', { contentType: 'text/plain' })
+ .startApp('issues')
+ .clickElement('.js-new-search')
+ .assertElementExist('.js-selection')
+ .assertElementNotExist('.js-selection.icon-checkbox-checked')
+ .assertElementExist('.issue .js-toggle')
+ .assertElementNotExist(issueSelector + ' .js-toggle .icon-checkbox-checked')
+ .clickElement(issueSelector + ' .js-toggle')
+ .assertElementExist(issueSelector + ' .js-toggle .icon-checkbox-checked')
+ .assertElementExist('.js-selection.icon-checkbox-single.icon-checkbox-checked')
+ .clickElement('#issues-bulk-change')
+ .clickElement('.js-bulk-change-selected')
+ .assertElementExist('#bulk-change-form')
+ .assertElementInclude('#bulk-change-form', 'bulk change form')
+ .clearMocks()
+ .mockFromFile('/api/issues/search', 'issues-spec/search-changed.json')
+ .execute(function () {
+ window.onBulkIssues();
+ })
+ .assertElementExist(issueSelector + ' .js-issue-set-severity .icon-severity-blocker')
+ .assertElementExist(issueSelector + ' .js-toggle .icon-checkbox-checked');
+ });
+
+ bdd.it('should filter similar issues', function () {
+ return this.remote
+ .get(require.toUrl('test/medium/base.html'))
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/issue_filters/app', 'issues-spec/app.json')
+ .mockFromFile('/api/issues/search',
+ 'issues-spec/search-filter-similar-issues-severities.json', { data: { severities: 'MAJOR' } })
+ .mockFromFile('/api/issues/search', 'issues-spec/search-filter-similar-issues.json')
+ .startApp('issues')
+ .clickElement('.js-new-search')
+ .clickElement('.issue.selected .js-issue-filter')
+ .assertElementExist('.bubble-popup')
+ .assertElementExist('.bubble-popup [data-property="severities"][data-value="MAJOR"]')
+ .assertElementExist('.bubble-popup [data-property="statuses"][data-value="CONFIRMED"]')
+ .assertElementExist('.bubble-popup [data-property="resolved"][data-value="false"]')
+ .assertElementExist('.bubble-popup [data-property="rules"][data-value="squid:S1214"]')
+ .assertElementExist('.bubble-popup [data-property="assigned"][data-value="false"]')
+ .assertElementExist('.bubble-popup [data-property="planned"][data-value="false"]')
+ .assertElementExist('.bubble-popup [data-property="tags"][data-value="bad-practice"]')
+ .assertElementExist('.bubble-popup [data-property="tags"][data-value="brain-overload"]')
+ .assertElementExist('.bubble-popup [data-property="projectUuids"][data-value="69e57151-be0d-4157-adff-c06741d88879"]')
+ .assertElementExist('.bubble-popup [data-property="moduleUuids"][data-value="7feef7c3-11b9-4175-b5a7-527ca3c75cb7"]')
+ .assertElementExist('.bubble-popup [data-property="fileUuids"][data-value="b0517331-0aaf-4091-b5cf-8e305dd0337a"]')
+ .clickElement('.bubble-popup [data-property="severities"]')
+ .waitForElementCount('.issue', 17);
+ });
});
});