From 925c6543c48bafe7e4ca269b7839ddcb243c7df8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ely=C3=A9zer=20Rezende?= Date: Thu, 31 Jan 2019 15:16:01 -0200 Subject: [PATCH] Add users CRUD e2e tests --- awx/ui/test/e2e/commands/waitForSpinny.js | 8 +++ awx/ui/test/e2e/objects/users.js | 20 ++++-- awx/ui/test/e2e/tests/test-users-crud.js | 87 +++++++++++++++++++++++ 3 files changed, 109 insertions(+), 6 deletions(-) create mode 100644 awx/ui/test/e2e/commands/waitForSpinny.js create mode 100644 awx/ui/test/e2e/tests/test-users-crud.js diff --git a/awx/ui/test/e2e/commands/waitForSpinny.js b/awx/ui/test/e2e/commands/waitForSpinny.js new file mode 100644 index 0000000000..8188a79e64 --- /dev/null +++ b/awx/ui/test/e2e/commands/waitForSpinny.js @@ -0,0 +1,8 @@ +/* Utility function to wait for the working spinner to disappear. */ +exports.command = function waitForSpinny () { + const selector = 'div.spinny'; + this + .waitForElementVisible(selector) + .waitForElementNotVisible(selector); + return this; +}; diff --git a/awx/ui/test/e2e/objects/users.js b/awx/ui/test/e2e/objects/users.js index 9b78588a21..b87d43e9b9 100644 --- a/awx/ui/test/e2e/objects/users.js +++ b/awx/ui/test/e2e/objects/users.js @@ -19,6 +19,18 @@ const details = createFormSection({ } }); +const addEditElements = { + title: 'div[class^="Form-title"]', + confirmPassword: '#user_password_confirm_input', + email: '#user_email', + firstName: '#user_first_name', + lastName: '#user_last_name', + organization: 'input[name="organization_name"]', + password: '#user_password_input', + save: '#user_save_btn', + username: '#user_username', +}; + module.exports = { url () { return `${this.api.globals.launch_url}/#/users`; @@ -39,9 +51,7 @@ module.exports = { sections: { details }, - elements: { - title: 'div[class^="Form-title"]' - } + elements: addEditElements, }, edit: { selector: 'div[ui-view="form"]', @@ -49,9 +59,7 @@ module.exports = { details, permissions }, - elements: { - title: 'div[class^="Form-title"]' - } + elements: addEditElements, }, list: { selector: 'div[ui-view="list"]', diff --git a/awx/ui/test/e2e/tests/test-users-crud.js b/awx/ui/test/e2e/tests/test-users-crud.js new file mode 100644 index 0000000000..fe778f3e34 --- /dev/null +++ b/awx/ui/test/e2e/tests/test-users-crud.js @@ -0,0 +1,87 @@ +/* Tests for the user CRUD operations. */ +import uuid from 'uuid'; + +const row = '#users_table .List-tableRow'; +const testID = uuid().substr(0, 8); + +const store = { + organization: { + name: `org-${testID}` + }, + user: { + email: `email-${testID}@example.com`, + firstName: `first-${testID}`, + lastName: `last-${testID}`, + password: `${testID}`, + username: `user-${testID}`, + }, +}; + +module.exports = { + before: (client, done) => { + client.login(); + client.waitForAngular(); + + client.inject( + [store, 'OrganizationModel'], + (_store_, Model) => new Model().http.post({ data: _store_.organization }), + ({ data }) => { + store.organization = data; + done(); + } + ); + }, + 'create an user': client => { + const users = client.page.users(); + users.load(); + client.waitForSpinny(); + users.section.list + .waitForElementVisible('@add') + .click('@add'); + users.section.add + .waitForElementVisible('@title') + .setValue('@organization', store.organization.name) + .setValue('@email', store.user.email) + .setValue('@username', store.user.username) + .setValue('@password', store.user.password) + .setValue('@confirmPassword', store.user.password) + .click('@save'); + client.waitForSpinny(); + users.section.list.section.search + .setValue('@input', store.user.username) + .click('@searchButton'); + client.waitForSpinny(); + users.waitForElementNotPresent(`${row}:nth-of-type(2)`); + users.expect.element('.List-titleBadge').text.to.contain('1'); + users.expect.element(row).text.contain(store.user.username); + }, + 'edit an user': client => { + const users = client.page.users(); + users.load(); + client.waitForSpinny(); + users.section.list.section.search + .setValue('@input', store.user.username) + .click('@searchButton'); + client.waitForSpinny(); + users.waitForElementNotPresent(`${row}:nth-of-type(2)`); + users.expect.element('.List-titleBadge').text.to.contain('1'); + users.expect.element(row).text.contain(store.user.username); + const editButton = `${row} i[class*="fa-pencil"]`; + users.waitForElementVisible(editButton).click(editButton); + users.section.edit + .waitForElementVisible('@title') + .setValue('@firstName', store.user.firstName) + .setValue('@lastName', store.user.lastName) + .click('@save'); + client.waitForSpinny(); + users.section.list.section.search + .setValue('@input', store.user.username) + .click('@searchButton'); + client.waitForSpinny(); + users.waitForElementNotPresent(`${row}:nth-of-type(2)`); + users.expect.element(row).text.contain(`${store.user.username}\n${store.user.firstName[0].toUpperCase() + store.user.firstName.slice(1)}\n${store.user.lastName}`); + }, + after: client => { + client.end(); + }, +};