1
0
Fork 0
mirror of synced 2024-07-13 18:26:06 +12:00

Refactoring test: createUserAndRoles

This commit is contained in:
MihailHadzhiev2022 2022-06-06 18:03:41 +03:00
parent a36ac49807
commit 598c9c62b7
2 changed files with 46 additions and 37 deletions

View file

@ -1,4 +1,5 @@
import filterTests from "../support/filterTests" import filterTests from "../support/filterTests"
const interact = require('../support/interact')
filterTests(["smoke", "all"], () => { filterTests(["smoke", "all"], () => {
context("Create a User and Assign Roles", () => { context("Create a User and Assign Roles", () => {
@ -12,7 +13,7 @@ filterTests(["smoke", "all"], () => {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(1000) cy.wait(1000)
cy.createUser("bbuser@test.com") cy.createUser("bbuser@test.com")
cy.get(".spectrum-Table").should("contain", "bbuser") cy.get(interact.SPECTRUM_TABLE).should("contain", "bbuser")
}) })
it("should confirm there is No Access for a New User", () => { it("should confirm there is No Access for a New User", () => {
@ -20,9 +21,9 @@ filterTests(["smoke", "all"], () => {
cy.contains("bbuser").click() cy.contains("bbuser").click()
cy.wait(500) cy.wait(500)
// Get No Access table - Confirm it has apps in it // Get No Access table - Confirm it has apps in it
cy.get(".spectrum-Table").eq(1).should("not.contain", "No rows found") cy.get(interact.SPECTRUM_TABLE).eq(1).should("not.contain", "No rows found")
// Get Configure Roles table - Confirm it has no apps // Get Configure Roles table - Confirm it has no apps
cy.get(".spectrum-Table").eq(0).contains("No rows found") cy.get(interact.SPECTRUM_TABLE).eq(0).contains("No rows found")
}) })
if (Cypress.env("TEST_ENV")) { if (Cypress.env("TEST_ENV")) {
@ -40,7 +41,7 @@ filterTests(["smoke", "all"], () => {
} else { } else {
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
cy.get(`[data-cy="create-app-btn"]`).click({ force: true }) cy.get(interact.CREATE_APP_BUTTON).click({ force: true })
cy.createAppFromScratch(name) cy.createAppFromScratch(name)
} }
} }
@ -49,35 +50,35 @@ filterTests(["smoke", "all"], () => {
// Navigate back to the user // Navigate back to the user
cy.visit(`${Cypress.config().baseUrl}/builder`) cy.visit(`${Cypress.config().baseUrl}/builder`)
cy.wait(500) cy.wait(500)
cy.get(".spectrum-SideNav").contains("Users").click() cy.get(interact.SPECTRUM_SIDENAV).contains("Users").click()
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Table").contains("bbuser").click() cy.get(interact.SPECTRUM_TABLE).contains("bbuser").click()
cy.wait(1000) cy.wait(1000)
for (let i = 0; i < 3; i++) { for (let i = 0; i < 3; i++) {
cy.get(".spectrum-Table", { timeout: 3000}) cy.get(interact.SPECTRUM_TABLE, { timeout: 3000})
.eq(1) .eq(1)
.find(".spectrum-Table-row") .find(interact.SPECTRUM_TABLE_ROW)
.eq(0) .eq(0)
.find(".spectrum-Table-cell") .find(interact.SPECTRUM_TABLE_CELL)
.eq(0) .eq(0)
.click() .click()
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Dialog-grid") cy.get(interact.SPECTRUM_DIALOG_GRID)
.contains("Choose an option") .contains("Choose an option")
.click() .click()
.then(() => { .then(() => {
cy.wait(1000) cy.wait(1000)
if (i == 0) { if (i == 0) {
cy.get(".spectrum-Menu").contains("Admin").click({ force: true }) cy.get(interact.SPECTRUM_MENU).contains("Admin").click({ force: true })
} }
else if (i == 1) { else if (i == 1) {
cy.get(".spectrum-Menu").contains("Power").click({ force: true }) cy.get(interact.SPECTRUM_MENU).contains("Power").click({ force: true })
} }
else if (i == 2) { else if (i == 2) {
cy.get(".spectrum-Menu").contains("Basic").click({ force: true }) cy.get(interact.SPECTRUM_MENU).contains("Basic").click({ force: true })
} }
cy.wait(1000) cy.wait(1000)
cy.get(".spectrum-Button") cy.get(interact.SPECTRUM_BUTTON)
.contains("Update role") .contains("Update role")
.click({ force: true }) .click({ force: true })
}) })
@ -85,7 +86,7 @@ filterTests(["smoke", "all"], () => {
} }
// Confirm roles exist within Configure roles table // Confirm roles exist within Configure roles table
cy.wait(2000) cy.wait(2000)
cy.get(".spectrum-Table") cy.get(interact.SPECTRUM_TABLE)
.eq(0) .eq(0)
.within(assginedRoles => { .within(assginedRoles => {
expect(assginedRoles).to.contain("Admin") expect(assginedRoles).to.contain("Admin")
@ -96,60 +97,60 @@ filterTests(["smoke", "all"], () => {
it("should unassign role types", () => { it("should unassign role types", () => {
// Set each app within Configure roles table to 'No Access' // Set each app within Configure roles table to 'No Access'
cy.get(".spectrum-Table") cy.get(interact.SPECTRUM_TABLE)
.eq(0) .eq(0)
.find(".spectrum-Table-row") .find(interact.SPECTRUM_TABLE_ROW)
.its("length") .its("length")
.then(len => { .then(len => {
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table") cy.get(interact.SPECTRUM_TABLE)
.eq(0) .eq(0)
.find(".spectrum-Table-row") .find(interact.SPECTRUM_TABLE_ROW)
.eq(0) .eq(0)
.find(".spectrum-Table-cell") .find(interact.SPECTRUM_TABLE_CELL)
.eq(0) .eq(0)
.click() .click()
.then(() => { .then(() => {
cy.get(".spectrum-Picker").eq(1).click({ force: true }) cy.get(interact.SPECTRUM_PICKER).eq(1).click({ force: true })
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Popover").contains("No Access").click() cy.get(interact.SPECTRUM_POPOVER).contains("No Access").click()
}) })
cy.get(".spectrum-Button") cy.get(interact.SPECTRUM_BUTTON)
.contains("Update role") .contains("Update role")
.click({ force: true }) .click({ force: true })
cy.wait(1000) cy.wait(1000)
} }
}) })
// Confirm Configure roles table no longer has any apps in it // Confirm Configure roles table no longer has any apps in it
cy.get(".spectrum-Table").eq(0).contains("No rows found") cy.get(interact.SPECTRUM_TABLE).eq(0).contains("No rows found")
}) })
} }
it("should enable Developer access", () => { it("should enable Developer access", () => {
// Enable Developer access // Enable Developer access
cy.get(".field") cy.get(interact.FIELD)
.eq(4) .eq(4)
.within(() => { .within(() => {
cy.get(".spectrum-Switch-input").click({ force: true }) cy.get(interact.SPECTRUM_SWITCH_INPUT).click({ force: true })
}) })
// No Access table should now be empty // No Access table should now be empty
cy.get(".container") cy.get(interact.CONTAINER)
.contains("No Access") .contains("No Access")
.parent() .parent()
.within(() => { .within(() => {
cy.get(".spectrum-Table").contains("No rows found") cy.get(interact.SPECTRUM_TABLE).contains("No rows found")
}) })
// Each app within Configure roles should have Admin access // Each app within Configure roles should have Admin access
cy.get(".spectrum-Table") cy.get(interact.SPECTRUM_TABLE)
.eq(0) .eq(0)
.find(".spectrum-Table-row") .find(interact.SPECTRUM_TABLE_ROW)
.its("length") .its("length")
.then(len => { .then(len => {
for (let i = 0; i < len; i++) { for (let i = 0; i < len; i++) {
cy.get(".spectrum-Table") cy.get(interact.SPECTRUM_TABLE)
.eq(0) .eq(0)
.find(".spectrum-Table-row") .find(interact.SPECTRUM_TABLE_ROW)
.eq(i) .eq(i)
.contains("Admin") .contains("Admin")
cy.wait(500) cy.wait(500)
@ -169,26 +170,26 @@ filterTests(["smoke", "all"], () => {
.contains("Configure roles") .contains("Configure roles")
.parent() .parent()
.within(() => { .within(() => {
cy.get(".spectrum-Table").contains("No rows found") cy.get(interact.SPECTRUM_TABLE).contains("No rows found")
}) })
}) })
it("should delete a user", () => { it("should delete a user", () => {
// Click Delete user button // Click Delete user button
cy.get(".spectrum-Button") cy.get(interact.SPECTRUM_BUTTON)
.contains("Delete user") .contains("Delete user")
.click({ force: true }) .click({ force: true })
.then(() => { .then(() => {
// Confirm deletion within modal // Confirm deletion within modal
cy.wait(500) cy.wait(500)
cy.get(".spectrum-Dialog-grid").within(() => { cy.get(interact.SPECTRUM_DIALOG_GRID).within(() => {
cy.get(".spectrum-Button") cy.get(interact.SPECTRUM_BUTTON)
.contains("Delete user") .contains("Delete user")
.click({ force: true }) .click({ force: true })
cy.wait(4000) cy.wait(4000)
}) })
}) })
cy.get(".spectrum-Table").should("not.have.text", "bbuser") cy.get(interact.SPECTRUM_TABLE).should("not.have.text", "bbuser")
}) })
}) })
}) })

View file

@ -92,3 +92,11 @@ export const NAV_ITEM = ".nav-item"
export const ACTION_SPECTRUM_ICON = ".actions .spectrum-Icon" export const ACTION_SPECTRUM_ICON = ".actions .spectrum-Icon"
export const SPECTRUM_MENU_CHILD2 = ".spectrum-Menu > :nth-child(2)" export const SPECTRUM_MENU_CHILD2 = ".spectrum-Menu > :nth-child(2)"
export const DELETE_TABLE_CONFIRM = '[data-cy="delete-table-confirm"]' export const DELETE_TABLE_CONFIRM = '[data-cy="delete-table-confirm"]'
//createUSerAndRoles
export const SPECTRUM_TABLE = ".spectrum-Table"
export const SPECTRUM_SIDENAV = ".spectrum-SideNav"
export const SPECTRUM_TABLE_ROW = ".spectrum-Table-row"
export const SPECTRUM_TABLE_CELL = ".spectrum-Table-cell"
export const FIELD = ".field"
export const CONTAINER = ".container"