aboutsummaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2015-06-30 12:26:58 +0200
committerStas Vilchik <vilchiks@gmail.com>2015-06-30 13:20:16 +0200
commit382ddfe2f15a9e8da17717ed974d142166f1da8e (patch)
tree22ff7bb8e3fb860de035d0731c50dcffbf0b696a /server
parent5d1f1383a52b3b94bb4a747ec20900b62f377281 (diff)
downloadsonarqube-382ddfe2f15a9e8da17717ed974d142166f1da8e.tar.gz
sonarqube-382ddfe2f15a9e8da17717ed974d142166f1da8e.zip
improve the functional web tests
Diffstat (limited to 'server')
-rw-r--r--server/sonar-web/test/helpers/test-page.js81
-rw-r--r--server/sonar-web/test/medium/users.spec.js112
2 files changed, 100 insertions, 93 deletions
diff --git a/server/sonar-web/test/helpers/test-page.js b/server/sonar-web/test/helpers/test-page.js
new file mode 100644
index 00000000000..d40c323f698
--- /dev/null
+++ b/server/sonar-web/test/helpers/test-page.js
@@ -0,0 +1,81 @@
+define(function (require) {
+
+ var assert = require('intern/chai!assert');
+ var fs = require('intern/dojo/node!fs');
+ var Command = require('intern/dojo/node!leadfoot/Command');
+
+ Command.prototype.assertElementCount = function (selector, count) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findAllByCssSelector(selector)
+ .then(function (elements) {
+ assert.equal(count, elements.length, count + ' elements were found by ' + selector);
+ })
+ .end();
+ });
+ };
+
+ Command.prototype.assertElementInclude = function (selector, text) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findAllByCssSelector(selector)
+ .getVisibleText()
+ .then(function (texts) {
+ assert.include(texts.join(''), text, selector + ' contains "' + text + '"');
+ })
+ .end();
+ });
+ };
+
+ Command.prototype.assertElementNotInclude = function (selector, text) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findAllByCssSelector(selector)
+ .getVisibleText()
+ .then(function (texts) {
+ assert.notInclude(texts.join(''), text, selector + ' does not contain "' + text + '"');
+ })
+ .end();
+ });
+ };
+
+ Command.prototype.clickElement = function (selector) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .findByCssSelector(selector)
+ .click()
+ .end();
+ });
+ };
+
+ Command.prototype.mockFromFile = function (url, file) {
+ 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]);
+ });
+ };
+
+ Command.prototype.mockFromString = function (url, response) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .execute(function (url, response) {
+ return jQuery.mockjax(_.extend({ url: url, responseText: response }));
+ }, [url, response]);
+ });
+ };
+
+ Command.prototype.startApp = function (app) {
+ return new this.constructor(this, function () {
+ return this.parent
+ .execute(function (app) {
+ require(['apps/' + app + '/app'], function (App) {
+ App.start({ el: '#content' });
+ });
+ }, [app]);
+ });
+ };
+
+});
diff --git a/server/sonar-web/test/medium/users.spec.js b/server/sonar-web/test/medium/users.spec.js
index 5337eb3a52d..f30ef2384b6 100644
--- a/server/sonar-web/test/medium/users.spec.js
+++ b/server/sonar-web/test/medium/users.spec.js
@@ -1,104 +1,30 @@
define(function (require) {
- var intern = require('intern');
var bdd = require('intern!bdd');
- var assert = require('intern/chai!assert');
- var fs = require('intern/dojo/node!fs');
+ require('../helpers/test-page');
bdd.describe('Users Page', function () {
-
bdd.it('should show list of users', function () {
- var searchResponse = fs.readFileSync('src/test/json/users-spec/search.json', 'utf-8');
-
return this.remote
.get(require.toUrl('test/medium/base.html'))
.setFindTimeout(5000)
- .findByCssSelector('#content')
- .execute(function () {
- return jQuery.mockjax(_.extend({ url: '/api/l10n/index', responseText: {} }));
- })
- .execute(function (searchResponse) {
- return jQuery.mockjax(_.extend({ url: '/api/users/search', responseText: searchResponse }));
- }, [searchResponse])
- .execute(function () {
- require(['apps/users/app'], function (App) {
- App.start({ el: '#content' });
- });
- })
- .findByCssSelector('#users-list ul')
- .findAllByCssSelector('#users-list li[data-login]')
- .then(function (elements) {
- assert.equal(3, elements.length);
- })
- .end()
- .findAllByCssSelector('#users-list .js-user-login')
- .getVisibleText()
- .then(function (text) {
- assert.include(text, 'smith');
- })
- .end()
- .findAllByCssSelector('#users-list .js-user-name')
- .getVisibleText()
- .then(function (text) {
- assert.include(text, 'Bob');
- })
- .end()
- .findAllByCssSelector('#users-list .js-user-email')
- .getVisibleText()
- .then(function (text) {
- assert.include(text, 'bob@example.com');
- })
- .end()
- .findAllByCssSelector('#users-list .js-user-update')
- .then(function (elements) {
- assert.equal(3, elements.length);
- })
- .end()
- .findAllByCssSelector('#users-list .js-user-change-password')
- .then(function (elements) {
- assert.equal(3, elements.length);
- })
- .end()
- .findAllByCssSelector('#users-list .js-user-deactivate')
- .then(function (elements) {
- assert.equal(3, elements.length);
- })
- .end()
- //.findByCssSelector('#users-list-footer')
- //.getVisibleText()
- //.then(function (text) {
- // assert.include(text, '3/3');
- //})
- //.end()
- .findByCssSelector('[data-login="ryan"]')
- .getVisibleText()
- .then(function (text) {
- assert.notInclude(text, 'another@example.com');
- })
- .end()
- .findByCssSelector('[data-login="ryan"] .js-user-more-scm')
- .click()
- .end()
- .findByCssSelector('[data-login="ryan"]')
- .getVisibleText()
- .then(function (text) {
- assert.include(text, 'another@example.com');
- })
- .end()
- .findByCssSelector('[data-login="ryan"]')
- .getVisibleText()
- .then(function (text) {
- assert.notInclude(text, 'four');
- })
- .end()
- .findByCssSelector('[data-login="ryan"] .js-user-more-groups')
- .click()
- .end()
- .findByCssSelector('[data-login="ryan"]')
- .getVisibleText()
- .then(function (text) {
- assert.include(text, 'four');
- });
+ .mockFromString('/api/l10n/index', '{}')
+ .mockFromFile('/api/users/search', 'users-spec/search.json')
+ .startApp('users')
+ .assertElementCount('#users-list ul', 1)
+ .assertElementCount('#users-list li[data-login]', 3)
+ .assertElementInclude('#users-list .js-user-login', 'smith')
+ .assertElementInclude('#users-list .js-user-name', 'Bob')
+ .assertElementInclude('#users-list .js-user-email', 'bob@example.com')
+ .assertElementCount('#users-list .js-user-update', 3)
+ .assertElementCount('#users-list .js-user-change-password', 3)
+ .assertElementCount('#users-list .js-user-deactivate', 3)
+ //.assertElementInclude('#users-list-footer', '3/3')
+ .assertElementNotInclude('[data-login="ryan"]', 'another@example.com')
+ .clickElement('[data-login="ryan"] .js-user-more-scm')
+ .assertElementInclude('[data-login="ryan"]', 'another@example.com')
+ .assertElementNotInclude('[data-login="ryan"]', 'four')
+ .clickElement('[data-login="ryan"] .js-user-more-groups')
+ .assertElementInclude('[data-login="ryan"]', 'four');
});
-
});
});