diff options
author | Stas Vilchik <vilchiks@gmail.com> | 2015-06-30 13:20:02 +0200 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2015-06-30 13:20:16 +0200 |
commit | 240bf864954e3e34245f8b91fd9889d9aba2c154 (patch) | |
tree | c2c9e4812b2b8c2aea4121fc55838ea29a90a83c /server/sonar-web | |
parent | 382ddfe2f15a9e8da17717ed974d142166f1da8e (diff) | |
download | sonarqube-240bf864954e3e34245f8b91fd9889d9aba2c154.tar.gz sonarqube-240bf864954e3e34245f8b91fd9889d9aba2c154.zip |
translate users page web tests
Diffstat (limited to 'server/sonar-web')
-rw-r--r-- | server/sonar-web/src/test/js/users-spec.js | 412 | ||||
-rw-r--r-- | server/sonar-web/test/helpers/test-page.js | 18 | ||||
-rw-r--r-- | server/sonar-web/test/medium/users.spec.js | 141 |
3 files changed, 159 insertions, 412 deletions
diff --git a/server/sonar-web/src/test/js/users-spec.js b/server/sonar-web/src/test/js/users-spec.js deleted file mode 100644 index 009adfce00d..00000000000 --- a/server/sonar-web/src/test/js/users-spec.js +++ /dev/null @@ -1,412 +0,0 @@ -/* globals casper: false */ -var lib = require('../lib'), - testName = lib.testName('Users'); - -lib.initMessages(); -lib.changeWorkingDirectory('users-spec'); -lib.configureCasper(); - -casper.test.begin(testName('List'), 13, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - lib.mockRequestFromFile('/api/users/search', 'search.json'); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - test.assertExists('#users-list ul'); - test.assertElementCount('#users-list li[data-login]', 3); - test.assertSelectorContains('#users-list .js-user-login', 'smith'); - test.assertSelectorContains('#users-list .js-user-name', 'Bob'); - test.assertSelectorContains('#users-list .js-user-email', 'bob@example.com'); - test.assertElementCount('#users-list .js-user-update', 3); - test.assertElementCount('#users-list .js-user-change-password', 3); - test.assertElementCount('#users-list .js-user-deactivate', 3); - test.assertSelectorContains('#users-list-footer', '3/3'); - }) - - .then(function () { - test.assertSelectorDoesntContain('[data-login="ryan"]', 'another@example.com'); - casper.click('[data-login="ryan"] .js-user-more-scm'); - test.assertSelectorContains('[data-login="ryan"]', 'another@example.com'); - }) - - .then(function () { - test.assertSelectorDoesntContain('[data-login="ryan"]', 'four'); - casper.click('[data-login="ryan"] .js-user-more-groups'); - test.assertSelectorContains('[data-login="ryan"]', 'four'); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); - - -casper.test.begin(testName('Search'), 4, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search.json'); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 3); - lib.clearRequestMock(this.searchMock); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search-filtered.json', { data: { q: 'ryan' } }); - casper.evaluate(function () { - jQuery('#users-search-query').val('ryan'); - }); - casper.click('#users-search-submit'); - casper.waitForSelectorTextChange('#users-list-footer'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 1); - lib.clearRequestMock(this.searchMock); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search.json'); - casper.evaluate(function () { - jQuery('#users-search-query').val(''); - }); - casper.click('#users-search-submit'); - casper.waitForSelectorTextChange('#users-list-footer'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 3); - test.assert(casper.evaluate(function () { - return jQuery('#users-search-query').val() === ''; - })); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); - - -casper.test.begin(testName('Show More'), 4, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search-big-1.json'); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 2); - test.assertSelectorContains('#users-list-footer', '2/3'); - lib.clearRequestMock(this.searchMock); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search-big-2.json', { data: { p: '2' } }); - casper.click('#users-fetch-more'); - casper.waitForSelectorTextChange('#users-list-footer'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 3); - test.assertSelectorContains('#users-list-footer', '3/3'); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); - - -casper.test.begin(testName('Create'), 5, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search.json'); - this.createMock = lib.mockRequestFromFile('/api/users/create', 'error.json', { status: 400 }); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - jQuery.ajaxSetup({ dataType: 'json' }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 3); - casper.click('#users-create'); - casper.waitForSelector('#create-user-form'); - }) - - .then(function () { - casper.click('#create-user-submit'); - casper.waitForSelector('.alert.alert-danger'); - }) - - .then(function () { - lib.clearRequestMock(this.searchMock); - lib.mockRequestFromFile('/api/users/search', 'search-created.json'); - lib.clearRequestMock(this.createMock); - lib.mockRequest('/api/users/create', '{}', - { data: { login: 'login', name: 'name', email: 'email@example.com', scmAccounts: 'scm1,scm2' } }); - casper.click('#create-user-add-scm-account'); - casper.click('#create-user-add-scm-account'); - casper.evaluate(function () { - jQuery('#create-user-login').val('login'); - jQuery('#create-user-name').val('name'); - jQuery('#create-user-email').val('email@example.com'); - jQuery('[name="scmAccounts"]').first().val('scm1'); - jQuery('[name="scmAccounts"]').last().val('scm2'); - }); - casper.click('#create-user-submit'); - casper.waitForSelectorTextChange('#users-list-footer'); - }) - - .then(function () { - test.assertElementCount('#users-list li[data-login]', 4); - test.assertSelectorContains('#users-list .js-user-login', 'login'); - test.assertSelectorContains('#users-list .js-user-name', 'name'); - test.assertSelectorContains('#users-list .js-user-email', 'email@example.com'); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); - - -casper.test.begin(testName('Update'), 3, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search.json'); - this.updateMock = lib.mockRequestFromFile('/api/users/update', 'error.json', { status: 400 }); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - jQuery.ajaxSetup({ dataType: 'json' }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - casper.click('[data-login="smith"] .js-user-update'); - casper.waitForSelector('#create-user-form'); - }) - - .then(function () { - casper.click('#create-user-submit'); - casper.waitForSelector('.alert.alert-danger'); - }) - - .then(function () { - lib.clearRequestMock(this.searchMock); - lib.mockRequestFromFile('/api/users/search', 'search-updated.json'); - lib.clearRequestMock(this.updateMock); - lib.mockRequest('/api/users/update', '{}', - { data: { login: 'smith', name: 'Mike', email: 'mike@example.com', scmAccounts: 'scm5,scm6' } }); - casper.click('#create-user-add-scm-account'); - casper.evaluate(function () { - jQuery('#create-user-name').val('Mike'); - jQuery('#create-user-email').val('mike@example.com'); - jQuery('[name="scmAccounts"]').first().val('scm5'); - jQuery('[name="scmAccounts"]').last().val('scm6'); - }); - casper.click('#create-user-submit'); - casper.waitForText('Mike'); - }) - - .then(function () { - test.assertSelectorContains('[data-login="smith"] .js-user-login', 'smith'); - test.assertSelectorContains('[data-login="smith"] .js-user-name', 'Mike'); - test.assertSelectorContains('[data-login="smith"] .js-user-email', 'mike@example.com'); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); - - -casper.test.begin(testName('Change Password'), 1, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search.json'); - this.updateMock = lib.mockRequestFromFile('/api/users/change_password', 'error.json', { status: 400 }); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - jQuery.ajaxSetup({ dataType: 'json' }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - casper.click('[data-login="smith"] .js-user-change-password'); - casper.waitForSelector('#change-user-password-form'); - }) - - .then(function () { - casper.click('#change-user-password-submit'); - casper.waitForSelector('.alert.alert-danger'); - }) - - .then(function () { - casper.click('#change-user-password-cancel'); - casper.waitWhileSelector('#change-user-password-form'); - }) - - .then(function () { - casper.click('[data-login="smith"] .js-user-change-password'); - casper.waitForSelector('#change-user-password-form'); - }) - - .then(function () { - lib.clearRequestMock(this.updateMock); - lib.mockRequest('/api/users/change_password', '{}', { data: { login: 'smith', password: 'secret' } }); - casper.evaluate(function () { - jQuery('#change-user-password-password').val('secret'); - jQuery('#change-user-password-password-confirmation').val('another'); - }); - casper.click('#change-user-password-submit'); - casper.waitForSelector('.alert.alert-danger'); - }) - - .then(function () { - casper.evaluate(function () { - jQuery('#change-user-password-password').val('secret'); - jQuery('#change-user-password-password-confirmation').val('secret'); - }); - casper.click('#change-user-password-submit'); - casper.waitWhileSelector('#change-user-password-form'); - }) - - .then(function () { - test.assert(true); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); - - -casper.test.begin(testName('Deactivate'), 1, function (test) { - casper - .start(lib.buildUrl('base'), function () { - lib.setDefaultViewport(); - this.searchMock = lib.mockRequestFromFile('/api/users/search', 'search.json'); - this.updateMock = lib.mockRequestFromFile('/api/users/deactivate', 'error.json', { status: 400 }); - }) - - .then(function () { - casper.evaluate(function () { - require(['apps/users/app'], function (App) { - App.start({ el: '#content' }); - }); - jQuery.ajaxSetup({ dataType: 'json' }); - }); - }) - - .then(function () { - casper.waitForText('Bob'); - }) - - .then(function () { - casper.click('[data-login="smith"] .js-user-deactivate'); - casper.waitForSelector('#deactivate-user-form'); - }) - - .then(function () { - casper.click('#deactivate-user-submit'); - casper.waitForSelector('.alert.alert-danger'); - }) - - .then(function () { - lib.clearRequestMock(this.updateMock); - lib.mockRequest('/api/users/deactivate', '{}', { data: { login: 'smith'} }); - casper.click('#deactivate-user-submit'); - casper.waitWhileSelector('[data-login="smith"]'); - }) - - .then(function () { - test.assert(true); - }) - - .then(function () { - lib.sendCoverage(); - }) - .run(function () { - test.done(); - }); -}); diff --git a/server/sonar-web/test/helpers/test-page.js b/server/sonar-web/test/helpers/test-page.js index d40c323f698..978e09b05cf 100644 --- a/server/sonar-web/test/helpers/test-page.js +++ b/server/sonar-web/test/helpers/test-page.js @@ -48,6 +48,15 @@ define(function (require) { }); }; + Command.prototype.fillElement = function (selector, value) { + return new this.constructor(this, function () { + return this.parent + .execute(function (selector, value) { + jQuery(selector).val(value); + }, [selector, value]); + }); + }; + Command.prototype.mockFromFile = function (url, file) { var response = fs.readFileSync('src/test/json/' + file, 'utf-8'); return new this.constructor(this, function () { @@ -67,6 +76,15 @@ define(function (require) { }); }; + Command.prototype.clearMocks = function () { + return new this.constructor(this, function () { + return this.parent + .execute(function () { + jQuery.mockjaxClear(); + }); + }); + }; + Command.prototype.startApp = function (app) { return new this.constructor(this, function () { return this.parent diff --git a/server/sonar-web/test/medium/users.spec.js b/server/sonar-web/test/medium/users.spec.js index f30ef2384b6..22a6757a47d 100644 --- a/server/sonar-web/test/medium/users.spec.js +++ b/server/sonar-web/test/medium/users.spec.js @@ -26,5 +26,146 @@ define(function (require) { .clickElement('[data-login="ryan"] .js-user-more-groups') .assertElementInclude('[data-login="ryan"]', 'four'); }); + + bdd.it('should search users', function () { + return this.remote + .get(require.toUrl('test/medium/base.html')) + .setFindTimeout(5000) + .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) + .clearMocks() + .mockFromFile('/api/users/search', 'users-spec/search-filtered.json') + .fillElement('#users-search-query', 'ryan') + .clickElement('#users-search-submit') + .waitForDeletedByCssSelector('[data-login="admin"]') + .assertElementCount('#users-list li[data-login]', 1) + .clearMocks() + .mockFromFile('/api/users/search', 'users-spec/search.json') + .fillElement('#users-search-query', '') + .clickElement('#users-search-submit') + .assertElementCount('[data-login="admin"]', 1) + .assertElementCount('#users-list li[data-login]', 3); + }); + + bdd.it('should show more', function () { + return this.remote + .get(require.toUrl('test/medium/base.html')) + .setFindTimeout(5000) + .mockFromString('/api/l10n/index', '{}') + .mockFromFile('/api/users/search', 'users-spec/search-big-1.json') + .startApp('users') + .assertElementCount('#users-list ul', 1) + .assertElementCount('#users-list li[data-login]', 2) + .clearMocks() + .mockFromFile('/api/users/search', 'users-spec/search-big-2.json') + .clickElement('#users-fetch-more') + .assertElementCount('[data-login="ryan"]', 1) + .assertElementCount('#users-list li[data-login]', 3); + }); + + bdd.it('should create a new user', function () { + return this.remote + .get(require.toUrl('test/medium/base.html')) + .setFindTimeout(5000) + .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) + .clickElement('#users-create') + .assertElementCount('#create-user-form', 1) + .clearMocks() + .mockFromFile('/api/users/search', 'users-spec/search-created.json') + .mockFromString('/api/users/create', '{}') + .clickElement('#create-user-add-scm-account') + .clickElement('#create-user-add-scm-account') + .execute(function () { + jQuery('#create-user-login').val('login'); + jQuery('#create-user-name').val('name'); + jQuery('#create-user-email').val('email@example.com'); + jQuery('#create-user-password').val('secret'); + jQuery('[name="scmAccounts"]').first().val('scm1'); + jQuery('[name="scmAccounts"]').last().val('scm2'); + }) + .clickElement('#create-user-submit') + .assertElementCount('[data-login="login"]', 1) + .assertElementCount('#users-list li[data-login]', 4) + .assertElementInclude('#users-list .js-user-login', 'login') + .assertElementInclude('#users-list .js-user-name', 'name') + .assertElementInclude('#users-list .js-user-email', 'email@example.com'); + }); + + bdd.it('should update a user', function () { + return this.remote + .get(require.toUrl('test/medium/base.html')) + .setFindTimeout(5000) + .mockFromString('/api/l10n/index', '{}') + .mockFromFile('/api/users/search', 'users-spec/search.json') + .startApp('users') + .assertElementCount('#users-list ul', 1) + .clickElement('[data-login="smith"] .js-user-update') + .assertElementCount('#create-user-form', 1) + .clearMocks() + .mockFromFile('/api/users/search', 'users-spec/search-updated.json') + .mockFromString('/api/users/update', '{}') + .clickElement('#create-user-add-scm-account') + .execute(function () { + jQuery('#create-user-name').val('Mike'); + jQuery('#create-user-email').val('mike@example.com'); + jQuery('[name="scmAccounts"]').first().val('scm5'); + jQuery('[name="scmAccounts"]').last().val('scm6'); + }) + .clickElement('#create-user-submit') + .waitForDeletedByCssSelector('#create-user-form') + .assertElementInclude('[data-login="smith"] .js-user-login', 'smith') + .assertElementInclude('[data-login="smith"] .js-user-name', 'Mike') + .assertElementInclude('[data-login="smith"] .js-user-email', 'mike@example.com'); + }); + + bdd.it('should change user\'s password', function () { + return this.remote + .get(require.toUrl('test/medium/base.html')) + .setFindTimeout(5000) + .mockFromString('/api/l10n/index', '{}') + .mockFromFile('/api/users/search', 'users-spec/search.json') + .startApp('users') + .assertElementCount('#users-list ul', 1) + .clickElement('[data-login="smith"] .js-user-change-password') + .assertElementCount('#change-user-password-form', 1) + .clearMocks() + .mockFromString('/api/users/change_password', '{}') + .execute(function () { + jQuery('#change-user-password-password').val('secret'); + jQuery('#change-user-password-password-confirmation').val('another'); + }) + .clickElement('#change-user-password-submit') + .assertElementCount('.alert.alert-danger', 1) + .execute(function () { + jQuery('#change-user-password-password').val('secret'); + jQuery('#change-user-password-password-confirmation').val('secret'); + }) + .clickElement('#change-user-password-submit') + .waitForDeletedByCssSelector('#change-user-password-form'); + }); + + bdd.it('should deactivate a user', function () { + return this.remote + .get(require.toUrl('test/medium/base.html')) + .setFindTimeout(5000) + .mockFromString('/api/l10n/index', '{}') + .mockFromFile('/api/users/search', 'users-spec/search.json') + .startApp('users') + .assertElementCount('#users-list ul', 1) + .clickElement('[data-login="smith"] .js-user-deactivate') + .assertElementCount('#deactivate-user-form', 1) + .clearMocks() + .mockFromString('/api/users/deactivate', '{}') + .clickElement('#deactivate-user-submit') + .waitForDeletedByCssSelector('[data-login="smith"]'); + }); }); + }); |