Skip to content

Commit

Permalink
Add update user account tests (#90)
Browse files Browse the repository at this point in the history
* Add /user folder with feature file and scenarios

* Update feature scenarios & create steps to match

* Add edit user regime scenarios and steps to match

* Add disable & enable user account tests with steps

* Revert "Add disable & enable user account tests with steps"

This reverts commit 1df886a.

Co-authored-by: Isse <[email protected]>
  • Loading branch information
anwarisse1 and Isse authored Jun 7, 2022
1 parent 90f6609 commit be090af
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 0 deletions.
25 changes: 25 additions & 0 deletions cypress/integration/user/general.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Feature: Update user account

Background: Authenticate
Given I sign in as the 'admin' user
And I select a user

Scenario: Update first name
When I update the users first name
Then I will see confirmation the user account is updated
And I can confirm the users first name is updated

Scenario: Update Last name
When I update the users last name
Then I will see confirmation the user account is updated
And I can confirm the users last name is updated

Scenario Outline: Update Regime Access
When I update the users regime access to "<regime>"
Then I will see confirmation the user account is updated
And I can confirm the users regime access is updated to "<regime>"
Examples:
| regime |
| Installations |
| Waste |
| Water Quality |
188 changes: 188 additions & 0 deletions cypress/integration/user/general/general_steps.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,188 @@
import { Before, And, Then, When } from 'cypress-cucumber-preprocessor/steps'
import { generateUserHelper } from '../../../support/helpers'

import LastEmailPage from '../../../pages/last_email_page'
import AcceptInvitePage from '../../../pages/accept_invite_page'
import TransactionsPage from '../../../pages/transactions_page'
import UsersPage from '../../../pages/users_page'
import AddUserPage from '../../../pages/add_user_page'

Before(() => {
cy.intercept('GET', '**/users?search=*').as('getSearch')
})

And('I select a user', () => {
const user = generateUserHelper()
cy.wrap(user).as('user')

TransactionsPage.adminMenu.getOption('User Management', '').click()

UsersPage.addUserAccountButton().click()

cy.get('@user').then((user) => {
AddUserPage.emailInput().type(user.email)
AddUserPage.firstNameInput().type(user.firstName)
AddUserPage.lastNameInput().type(user.lastName)

AddUserPage.regimeAccessCheckbox('Waste').click()
AddUserPage.submitButton().click()
})
cy.alertShouldContain('User account created')
})

When('I update the users first name', () => {
TransactionsPage.adminMenu.getOption('User Management', '').click()

cy.get('@user').then((user) => {
UsersPage.searchNameInput().type(user.lastName)
UsersPage.submitButton().click()
cy.wait('@getSearch').its('response.statusCode').should('eq', 200)

UsersPage.searchResultsTable().each((element, index) => {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) td`).eq(2).invoke('text').then((email) => {
if (email === user.email) {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1})`).invoke('attr', 'id').then((id) => {
UsersPage.searchResultEditButton(id).click()
cy.wait(500)

const updatedUser = generateUserHelper()
cy.wrap(updatedUser).as('updatedUser')

cy.get('@updatedUser').then((updatedUser) => {
AddUserPage.firstNameInput().type(updatedUser.firstName)
AddUserPage.submitButton().click()
})
})
}
})
})
})
})

Then('I will see confirmation the user account is updated', () => {
cy.alertShouldContain('User account updated')
})

And('I can confirm the users first name is updated', () => {
cy.get('@user').then((user) => {
cy.get('@updatedUser').then((updatedUser) => {
UsersPage.searchNameInput().type(updatedUser.firstName)
UsersPage.submitButton().click()
cy.wait('@getSearch').its('response.statusCode').should('eq', 200)

UsersPage.searchResultsTable().each((element, index) => {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) td`).eq(2).invoke('text').then((email) => {
if (email === user.email) {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1})`).invoke('attr', 'id').then((id) => {
cy.wait(500)

cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) > td`).contains(user.firstName + updatedUser.firstName)
})
}
})
})
})
})
})

When('I update the users last name', () => {
TransactionsPage.adminMenu.getOption('User Management', '').click()

cy.get('@user').then((user) => {
UsersPage.searchNameInput().type(user.lastName)
UsersPage.submitButton().click()
cy.wait('@getSearch').its('response.statusCode').should('eq', 200)

UsersPage.searchResultsTable().each((element, index) => {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) td`).eq(2).invoke('text').then((email) => {
if (email === user.email) {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1})`).invoke('attr', 'id').then((id) => {
UsersPage.searchResultEditButton(id).click()
cy.wait(500)

const updatedUser = generateUserHelper()
cy.wrap(updatedUser).as('updatedUser')

cy.get('@updatedUser').then((updatedUser) => {
AddUserPage.lastNameInput().type(updatedUser.lastName)
AddUserPage.submitButton().click()
})
})
}
})
})
})
})

And('I can confirm the users last name is updated', () => {
cy.get('@user').then((user) => {
cy.get('@updatedUser').then((updatedUser) => {
UsersPage.searchNameInput().type(user.lastName + updatedUser.lastName)
UsersPage.submitButton().click()
cy.wait('@getSearch').its('response.statusCode').should('eq', 200)

UsersPage.searchResultsTable().each((element, index) => {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) td`).eq(2).invoke('text').then((email) => {
if (email === user.email) {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1})`).invoke('attr', 'id').then((id) => {
cy.wait(500)

cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) > td`).contains(user.lastName + updatedUser.lastName)
})
}
})
})
})
})
})

When('I update the users regime access to {string}', (regime) => {
TransactionsPage.adminMenu.getOption('User Management', '').click()

cy.get('@user').then((user) => {
UsersPage.searchNameInput().type(user.lastName)
UsersPage.submitButton().click()
cy.wait('@getSearch').its('response.statusCode').should('eq', 200)

UsersPage.searchResultsTable().each((element, index) => {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1}) td`).eq(2).invoke('text').then((email) => {
if (email === user.email) {
cy.get(`.table-responsive > tbody > tr:nth-child(${index + 1})`).invoke('attr', 'id').then((id) => {
UsersPage.searchResultEditButton(id).click()
cy.wait(500)

AddUserPage.regimeAccessCheckbox('Waste').click()
AddUserPage.regimeAccessCheckbox(regime).click()
AddUserPage.submitButton().click()
})
}
})
})
})
})

And('I can confirm the users regime access is updated to {string}', (regime) => {
cy.get('@user').then((user) => {
cy.signOut()

LastEmailPage.lastEmail([user.email, 'created an account'])
cy.get('@lastEmail').then((lastEmail) => {
const link = LastEmailPage.extractInvitationLink(lastEmail.last_email.body)

cy.visit(link).then(() => {
AcceptInvitePage.confirm()

AcceptInvitePage.passwordInput().type(Cypress.env('PASSWORD'), { log: false })
AcceptInvitePage.passwordConfirmationInput().type(Cypress.env('PASSWORD'), { log: false })
AcceptInvitePage.submitButton().click()

cy.get('@user').then((user) => {
const username = `${user.firstName} ${user.lastName}`
TransactionsPage.userMenu.menuLink().should('contain', username)

cy.get('.navbar-text').contains(regime)
})
})
})
})
})

0 comments on commit be090af

Please sign in to comment.