Skip to content

Commit 74784f3

Browse files
committed
Client : E2E Tests : Created User Accounts edit tests
1 parent 5dc5d6f commit 74784f3

3 files changed

Lines changed: 168 additions & 4 deletions

File tree

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
import { expect, Page, test, TestInfo } from "@playwright/test";
2+
import { loginAsServerAdmin } from "../utils/authenticate";
3+
import { addBrowserSuffixToText } from "../utils/helpers";
4+
import { PlaywrightUserAccountsPage } from "./models/playwright-user-accounts-page";
5+
6+
test.describe("1.3.1 User Accounts - UPDATE Edit", () => {
7+
let userAccountsPage: PlaywrightUserAccountsPage;
8+
9+
async function openEditUserForTest(
10+
page: Page,
11+
testInfo: TestInfo,
12+
baseUuid: string,
13+
baseLastName: string,
14+
) {
15+
const suffix = testInfo.project.name.toLowerCase();
16+
const uuid = addBrowserSuffixToText(baseUuid, testInfo);
17+
const lastName = addBrowserSuffixToText(baseLastName, testInfo);
18+
19+
await userAccountsPage.search(lastName, page);
20+
const userAccountPage = await userAccountsPage.clickEditIcon(uuid);
21+
22+
await userAccountPage.expectVisible();
23+
await userAccountPage.expectStillOnEditPage(uuid);
24+
25+
await userAccountPage.expectFormLoaded({
26+
name: "Institutional",
27+
surname: lastName,
28+
email: `inst-admin-${baseLastName}-${suffix}@nomail.nomail`,
29+
});
30+
31+
return { userAccountPage, uuid, lastName };
32+
}
33+
34+
test.beforeEach(async ({ page }) => {
35+
await loginAsServerAdmin(page);
36+
37+
userAccountsPage = new PlaywrightUserAccountsPage(page);
38+
await userAccountsPage.goto();
39+
await userAccountsPage.expectVisible();
40+
});
41+
42+
test("A Success", async ({ page }, testInfo) => {
43+
const { userAccountPage } = await openEditUserForTest(
44+
page,
45+
testInfo,
46+
"seb-user-account-edit-a",
47+
"testedit-a",
48+
);
49+
50+
const unique = `e2e-1.3.A-${Date.now()}`;
51+
52+
await userAccountPage.fillEditForm({
53+
name: `${unique}-Name`,
54+
surname: `${unique}-Surname`,
55+
username: `${unique}-Username`,
56+
email: `${unique}@email.com`,
57+
pickFirstTimezone: true,
58+
roleName: "Exam Administrator",
59+
});
60+
61+
await userAccountPage.toggleStatusChip();
62+
63+
await expect(userAccountPage.saveChangesButton).toBeEnabled();
64+
65+
await userAccountPage.expectEditRequestSucceeded(async () => {
66+
await userAccountPage.submitSaveChanges();
67+
});
68+
69+
await userAccountPage.expectRedirectToUserAccounts();
70+
});
71+
72+
test("B Validation Failure", async ({ page }, testInfo) => {
73+
const REQUIRED = "This field is required";
74+
75+
const { userAccountPage, uuid } = await openEditUserForTest(
76+
page,
77+
testInfo,
78+
"seb-user-account-edit-b",
79+
"testedit-b",
80+
);
81+
82+
await userAccountPage.fillEditForm({
83+
name: "",
84+
surname: "",
85+
username: "",
86+
});
87+
88+
await userAccountPage.expectNoEditRequest(async () => {
89+
await userAccountPage.submitSaveChanges();
90+
});
91+
92+
await userAccountPage.expectRequiredFieldErrors({
93+
name: REQUIRED,
94+
surname: REQUIRED,
95+
username: REQUIRED,
96+
});
97+
98+
await userAccountPage.expectStillOnEditPage(uuid);
99+
});
100+
101+
test("C Server Error - duplicate username", async ({ page }, testInfo) => {
102+
const { userAccountPage, uuid } = await openEditUserForTest(
103+
page,
104+
testInfo,
105+
"seb-user-account-edit-c",
106+
"testedit-c",
107+
);
108+
109+
await userAccountPage.fillEditForm({
110+
username: "createtests",
111+
});
112+
113+
await userAccountPage.expectEditRequestFailed({
114+
action: async () => {
115+
await userAccountPage.submitSaveChanges();
116+
},
117+
});
118+
119+
await userAccountPage.expectErrorToast([
120+
"Field validation error",
121+
"Username is already being used.",
122+
]);
123+
124+
await userAccountPage.expectStillOnEditPage(uuid);
125+
});
126+
});

client/tests/e2e/1-user-account/models/playwright-user-account-page.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,21 @@ export class PlaywrightUserAccountPage {
273273
if (params.email !== undefined) await this.fillEmail(params.email);
274274
}
275275

276+
async expectFormLoaded(expected: {
277+
name: string;
278+
surname: string;
279+
email: string;
280+
}) {
281+
await expect(this.name).toHaveValue(expected.name, { timeout: 10_000 });
282+
await expect(this.surname).toHaveValue(expected.surname, {
283+
timeout: 10_000,
284+
});
285+
286+
await expect(this.email).toHaveValue(expected.email, {
287+
timeout: 10_000,
288+
});
289+
}
290+
276291
// ------------------------
277292
// Validation assertions
278293
// ------------------------
@@ -282,9 +297,13 @@ export class PlaywrightUserAccountPage {
282297
}
283298

284299
async expectFieldError(testId: string, text: string) {
285-
await expect(this.fieldError(testId, text)).toHaveCount(1, {
286-
timeout: 5_000,
287-
});
300+
await expect(
301+
this.page
302+
.getByTestId(testId)
303+
.locator(".v-messages__message")
304+
.filter({ hasText: text })
305+
.first(),
306+
).toBeVisible({ timeout: 5_000 });
288307
}
289308

290309
async expectRequiredFieldErrors(errors: {
@@ -394,6 +413,23 @@ export class PlaywrightUserAccountPage {
394413
});
395414
}
396415

416+
async expectEditRequestFailed(params: {
417+
action: () => Promise<void>;
418+
expectedStatus?: number;
419+
expectedStatuses?: number[];
420+
}) {
421+
const expectedStatuses = params.expectedStatuses ?? [
422+
params.expectedStatus ?? 400,
423+
];
424+
425+
const resp = await this.captureEditResponse(params.action);
426+
427+
expect(expectedStatuses).toContain(resp.status());
428+
expect(resp.ok()).toBeFalsy();
429+
430+
return resp;
431+
}
432+
397433
async expectStatusToggleRequestSucceeded(action: () => Promise<void>) {
398434
await expectRequestSucceeded({
399435
page: this.page,

client/tests/e2e/1-user-account/models/playwright-user-accounts-page.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,9 +191,11 @@ export class PlaywrightUserAccountsPage {
191191
await this.cancelButton.click();
192192
}
193193

194-
async search(value: string) {
194+
async search(value: string, page: Page) {
195+
await page.waitForTimeout(500);
195196
await this.fillSearch(value);
196197
await this.searchByButton();
198+
await page.waitForTimeout(500);
197199
}
198200

199201
statusChipFilter(status: "Active" | "Inactive"): Locator {

0 commit comments

Comments
 (0)