Skip to content

Commit f193fd9

Browse files
committed
E2E : Created Get All e2e test
1 parent fa51745 commit f193fd9

2 files changed

Lines changed: 258 additions & 49 deletions

File tree

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
import { expect, test } from "@playwright/test";
2+
import { addBrowserSuffixToText } from "../utils/helpers";
3+
import { loginAsServerAdmin } from "../utils/authenticate";
4+
import { PlaywrightUserAccountsPage } from "../models/playwright-user-accounts-page";
5+
6+
const searchSurname = "000-testgetall";
7+
const activeUserUuid = "seb-user-account-getall-active";
8+
const inactiveUserUuid = "seb-user-account-getall-inactive";
9+
10+
const institutionModelId = 11;
11+
12+
test.describe("1.2.2 User Accounts - READ Get All", () => {
13+
let userAccountsPage: PlaywrightUserAccountsPage;
14+
15+
test.beforeEach(async ({ page }) => {
16+
await loginAsServerAdmin(page);
17+
userAccountsPage = new PlaywrightUserAccountsPage(page);
18+
await userAccountsPage.goto();
19+
await userAccountsPage.expectVisible();
20+
});
21+
22+
test("A Success", async ({ page }, testInfo) => {
23+
expect(page.url()).toContain("/user-accounts");
24+
25+
const surnameWithBrowserSuffix = addBrowserSuffixToText(
26+
searchSurname,
27+
testInfo,
28+
);
29+
30+
const activeUuidWithBrowserSuffix = addBrowserSuffixToText(
31+
activeUserUuid,
32+
testInfo,
33+
);
34+
35+
const inactiveUuidWithBrowserSuffix = addBrowserSuffixToText(
36+
inactiveUserUuid,
37+
testInfo,
38+
);
39+
40+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
41+
async () => {
42+
await userAccountsPage.search(surnameWithBrowserSuffix);
43+
},
44+
{
45+
urlMustContain: [
46+
/optionalParameters%5Bsurname%5D=/i,
47+
encodeURIComponent(surnameWithBrowserSuffix),
48+
],
49+
},
50+
);
51+
52+
await userAccountsPage.expectRowVisible(activeUuidWithBrowserSuffix);
53+
await userAccountsPage.expectRowVisible(inactiveUuidWithBrowserSuffix);
54+
});
55+
56+
test("B Using search and filters", async ({ page }, testInfo) => {
57+
expect(page.url()).toContain("/user-accounts");
58+
59+
const surnameWithBrowserSuffix = addBrowserSuffixToText(
60+
searchSurname,
61+
testInfo,
62+
);
63+
64+
const activeUuidWithBrowserSuffix = addBrowserSuffixToText(
65+
activeUserUuid,
66+
testInfo,
67+
);
68+
69+
const inactiveUuidWithBrowserSuffix = addBrowserSuffixToText(
70+
inactiveUserUuid,
71+
testInfo,
72+
);
73+
74+
await userAccountsPage.search(surnameWithBrowserSuffix);
75+
await userAccountsPage.expectRowVisible(activeUuidWithBrowserSuffix);
76+
await userAccountsPage.expectRowVisible(inactiveUuidWithBrowserSuffix);
77+
78+
//set status filter inactive
79+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
80+
async () => {
81+
await userAccountsPage.toggleStatusFilter("Inactive");
82+
},
83+
{ urlMustContain: [/optionalParameters%5Bactive%5D=false/i] },
84+
);
85+
86+
await userAccountsPage.expectRowVisible(inactiveUuidWithBrowserSuffix);
87+
await expect(
88+
userAccountsPage.row(activeUuidWithBrowserSuffix),
89+
).toHaveCount(0);
90+
91+
//set status filter active
92+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
93+
async () => {
94+
await userAccountsPage.toggleStatusFilter("Active");
95+
},
96+
{ urlMustContain: [/optionalParameters%5Bactive%5D=true/i] },
97+
);
98+
99+
await userAccountsPage.expectRowVisible(activeUuidWithBrowserSuffix);
100+
await expect(
101+
userAccountsPage.row(inactiveUuidWithBrowserSuffix),
102+
).toHaveCount(0);
103+
104+
// if possible set institutions
105+
if (await userAccountsPage.institutionFilterSection.count()) {
106+
await userAccountsPage.expectInstitutionFilterVisible();
107+
108+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
109+
async () => {
110+
await userAccountsPage.toggleInstitutionFilter(
111+
institutionModelId,
112+
);
113+
},
114+
{
115+
urlMustContain: [
116+
new RegExp(
117+
`optionalParameters%5BinstitutionId%5D=${institutionModelId}`,
118+
"i",
119+
),
120+
],
121+
},
122+
);
123+
124+
// Best-effort: table still renders after filtering
125+
await expect(userAccountsPage.table).toBeVisible();
126+
} else {
127+
await userAccountsPage.expectInstitutionFilterNotVisible();
128+
}
129+
130+
//clear filters / searches
131+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
132+
async () => {
133+
await userAccountsPage.clearSearch();
134+
},
135+
{
136+
urlMustContain: [
137+
/optionalParameters%5Bpage_size%5D=5/i,
138+
/optionalParameters%5Bpage_number%5D=1/i,
139+
],
140+
},
141+
);
142+
143+
await expect(userAccountsPage.searchInput).toHaveValue("");
144+
});
145+
146+
test("C Using table sorting and paging", async ({ page }, testInfo) => {
147+
expect(page.url()).toContain("/user-accounts");
148+
149+
const surnameWithBrowserSuffix = addBrowserSuffixToText(
150+
searchSurname,
151+
testInfo,
152+
);
153+
154+
await userAccountsPage.search(surnameWithBrowserSuffix);
155+
156+
// sort by username
157+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
158+
async () => {
159+
await userAccountsPage.sortByHeaderText("Username");
160+
},
161+
{ urlMustContain: [/optionalParameters%5Bsort%5D=username/i] },
162+
);
163+
164+
// sort by name
165+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
166+
async () => {
167+
await userAccountsPage.sortByHeaderText("Name");
168+
},
169+
{ urlMustContain: [/optionalParameters%5Bsort%5D=name/i] },
170+
);
171+
172+
//verify pagination
173+
const pagination = userAccountsPage.paginationRoot();
174+
if (await pagination.count()) {
175+
await userAccountsPage.expectPaginationVisible();
176+
177+
// Vuetify commonly renders page buttons like "2", "3", ...
178+
const page2 = pagination.getByRole("button", { name: "2" });
179+
if (await page2.count()) {
180+
await userAccountsPage.expectUserAccountsListRequestSucceeded(
181+
async () => {
182+
await page2.first().click();
183+
},
184+
{
185+
urlMustContain: [
186+
/optionalParameters%5Bpage_number%5D=2/i,
187+
],
188+
},
189+
);
190+
}
191+
}
192+
});
193+
194+
test("D Server Error", async ({ page }) => {
195+
// Force error 500 via intercept
196+
await page.route(/\/useraccount\?/i, async (route) => {
197+
await route.fulfill({
198+
status: 500,
199+
contentType: "application/json",
200+
body: JSON.stringify({
201+
message: "Internal Server Error (forced by Playwright)",
202+
}),
203+
});
204+
});
205+
206+
await userAccountsPage.goto();
207+
await userAccountsPage.expectVisible();
208+
await userAccountsPage.expectAnyValidationMessageVisible();
209+
});
210+
});

0 commit comments

Comments
 (0)