|
| 1 | +import { expect, Page, test } from "@playwright/test"; |
| 2 | +import { navigateTo, suffixForProject } from "../utils/helpers"; |
| 3 | +import { loginAsServerAdmin } from "../utils/authenticate"; |
| 4 | + |
| 5 | +const userLastName = "testactive"; |
| 6 | +const userUUID = "seb-inst-admin-active"; |
| 7 | + |
| 8 | +async function setupUserAccountsPage(page: Page, suffix: string) { |
| 9 | + await expect(page.getByTestId("userAccounts-list-container")).toBeVisible(); |
| 10 | + |
| 11 | + const searchFieldLocator = page |
| 12 | + .getByTestId("userAccounts-search-input") |
| 13 | + .getByRole("textbox"); |
| 14 | + const searchButtonLocator = page.getByTestId( |
| 15 | + "userAccounts-searchIcon-button", |
| 16 | + ); |
| 17 | + |
| 18 | + const activateButtonLocator = page.getByTestId( |
| 19 | + `userAccounts-status-chip-seb-inst-admin-active-${suffix}`, |
| 20 | + ); |
| 21 | + const statusDialogLocator = page.getByTestId("userAccounts-status-dialog"); |
| 22 | + const statusDialogActivateButtonLocator = page.getByTestId( |
| 23 | + "userAccounts-status-confirm-button", |
| 24 | + ); |
| 25 | + |
| 26 | + return { |
| 27 | + searchFieldLocator, |
| 28 | + searchButtonLocator, |
| 29 | + activateButtonLocator, |
| 30 | + statusDialogLocator, |
| 31 | + statusDialogActivateButtonLocator, |
| 32 | + }; |
| 33 | +} |
| 34 | + |
| 35 | +test.describe("1.3.3 User Accounts - UPDATE Deactivate", () => { |
| 36 | + test.beforeEach(async ({ page }) => { |
| 37 | + await loginAsServerAdmin(page); |
| 38 | + await navigateTo(page, "/user-accounts"); |
| 39 | + }); |
| 40 | + |
| 41 | + test("A Success", async ({ page }, testInfo) => { |
| 42 | + const browserSuffix = suffixForProject(testInfo.project.name); |
| 43 | + const userLastNameWithBrowserSuffix = |
| 44 | + userLastName + "-" + browserSuffix; |
| 45 | + const userUUIDWithBrowserSuffix = userUUID + "-" + browserSuffix; |
| 46 | + const deactivateRegex = new RegExp( |
| 47 | + `/useraccount/${userUUIDWithBrowserSuffix}/inactive(?:\\?|$)`, |
| 48 | + "i", |
| 49 | + ); |
| 50 | + |
| 51 | + const { |
| 52 | + searchFieldLocator, |
| 53 | + searchButtonLocator, |
| 54 | + activateButtonLocator, |
| 55 | + statusDialogLocator, |
| 56 | + statusDialogActivateButtonLocator, |
| 57 | + } = await setupUserAccountsPage(page, browserSuffix); |
| 58 | + |
| 59 | + await searchFieldLocator.fill(userLastNameWithBrowserSuffix); |
| 60 | + |
| 61 | + await searchButtonLocator.click(); |
| 62 | + |
| 63 | + await expect(activateButtonLocator).toBeVisible(); |
| 64 | + await expect(activateButtonLocator).toHaveText("Active"); |
| 65 | + |
| 66 | + await activateButtonLocator.click(); |
| 67 | + |
| 68 | + await expect(statusDialogLocator).toBeVisible(); |
| 69 | + |
| 70 | + await expect(statusDialogActivateButtonLocator).toHaveText( |
| 71 | + "Deactivate", |
| 72 | + ); |
| 73 | + |
| 74 | + const activateRequestPromise = page.waitForRequest( |
| 75 | + (req) => req.method() === "POST" && deactivateRegex.test(req.url()), |
| 76 | + ); |
| 77 | + |
| 78 | + const activateResponsePromise = page.waitForResponse( |
| 79 | + (resp) => |
| 80 | + resp.request().method() === "POST" && |
| 81 | + deactivateRegex.test(resp.url()), |
| 82 | + ); |
| 83 | + |
| 84 | + await statusDialogActivateButtonLocator.click(); |
| 85 | + |
| 86 | + const activateRequest = await activateRequestPromise; |
| 87 | + const activateResponse = await activateResponsePromise; |
| 88 | + |
| 89 | + expect(activateRequest.method()).toBe("POST"); |
| 90 | + expect(activateRequest.url()).toMatch(deactivateRegex); |
| 91 | + |
| 92 | + expect(activateResponse.url()).toMatch(deactivateRegex); |
| 93 | + expect(activateResponse.status()).toBe(200); |
| 94 | + expect(activateResponse.ok()).toBeTruthy(); |
| 95 | + |
| 96 | + await expect(activateButtonLocator).toHaveText("Inactive"); |
| 97 | + }); |
| 98 | +}); |
0 commit comments