Skip to content

Commit 5cce90a

Browse files
committed
✅ Update tests
1 parent 3c49d73 commit 5cce90a

File tree

1 file changed

+36
-66
lines changed

1 file changed

+36
-66
lines changed

frontend/tests/user-settings.spec.ts

Lines changed: 36 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { createUser } from "./utils/privateApi.ts"
44
import { randomEmail, randomPassword } from "./utils/random"
55
import { logInUser, logOutUser } from "./utils/user"
66

7-
const tabs = ["My profile", "Password", "Appearance"]
7+
const tabs = ["My profile", "Password", "Danger zone"]
88

99
// User Information
1010

@@ -43,9 +43,7 @@ test.describe("Edit user full name and email successfully", () => {
4343
await page.getByRole("button", { name: "Save" }).click()
4444
await expect(page.getByText("User updated successfully")).toBeVisible()
4545
// Check if the new name is displayed on the page
46-
await expect(
47-
page.getByLabel("My profile").getByText(updatedName, { exact: true }),
48-
).toBeVisible()
46+
await expect(page.getByText(updatedName, { exact: true })).toBeVisible()
4947
})
5048

5149
test("Edit user email with a valid email", async ({ page }) => {
@@ -64,9 +62,7 @@ test.describe("Edit user full name and email successfully", () => {
6462
await page.getByLabel("Email").fill(updatedEmail)
6563
await page.getByRole("button", { name: "Save" }).click()
6664
await expect(page.getByText("User updated successfully")).toBeVisible()
67-
await expect(
68-
page.getByLabel("My profile").getByText(updatedEmail, { exact: true }),
69-
).toBeVisible()
65+
await expect(page.getByText(updatedEmail, { exact: true })).toBeVisible()
7066
})
7167
})
7268

@@ -88,7 +84,7 @@ test.describe("Edit user with invalid data", () => {
8884
await page.getByRole("button", { name: "Edit" }).click()
8985
await page.getByLabel("Email").fill(invalidEmail)
9086
await page.locator("body").click()
91-
await expect(page.getByText("Email is required")).toBeVisible()
87+
await expect(page.getByText("Invalid email address")).toBeVisible()
9288
})
9389

9490
test("Cancel edit action restores original name", async ({ page }) => {
@@ -107,9 +103,7 @@ test.describe("Edit user with invalid data", () => {
107103
await page.getByLabel("Full name").fill(updatedName)
108104
await page.getByRole("button", { name: "Cancel" }).first().click()
109105
await expect(
110-
page
111-
.getByLabel("My profile")
112-
.getByText(user.full_name as string, { exact: true }),
106+
page.locator("form").getByText(user.full_name as string, { exact: true }),
113107
).toBeVisible()
114108
})
115109

@@ -129,7 +123,7 @@ test.describe("Edit user with invalid data", () => {
129123
await page.getByLabel("Email").fill(updatedEmail)
130124
await page.getByRole("button", { name: "Cancel" }).first().click()
131125
await expect(
132-
page.getByLabel("My profile").getByText(email, { exact: true }),
126+
page.locator("form").getByText(email, { exact: true }),
133127
).toBeVisible()
134128
})
135129
})
@@ -151,11 +145,11 @@ test.describe("Change password successfully", () => {
151145

152146
await page.goto("/settings")
153147
await page.getByRole("tab", { name: "Password" }).click()
154-
await page.getByPlaceholder("Current Password").fill(password)
155-
await page.getByPlaceholder("New Password").fill(NewPassword)
156-
await page.getByPlaceholder("Confirm Password").fill(NewPassword)
157-
await page.getByRole("button", { name: "Save" }).click()
158-
await expect(page.getByText("Password updated successfully.")).toBeVisible()
148+
await page.getByTestId("current-password-input").fill(password)
149+
await page.getByTestId("new-password-input").fill(NewPassword)
150+
await page.getByTestId("confirm-password-input").fill(NewPassword)
151+
await page.getByRole("button", { name: "Update Password" }).click()
152+
await expect(page.getByText("Password updated successfully")).toBeVisible()
159153

160154
await logOutUser(page)
161155

@@ -179,9 +173,10 @@ test.describe("Change password with invalid data", () => {
179173

180174
await page.goto("/settings")
181175
await page.getByRole("tab", { name: "Password" }).click()
182-
await page.getByPlaceholder("Current Password").fill(password)
183-
await page.getByPlaceholder("New Password").fill(weakPassword)
184-
await page.getByPlaceholder("Confirm Password").fill(weakPassword)
176+
await page.getByTestId("current-password-input").fill(password)
177+
await page.getByTestId("new-password-input").fill(weakPassword)
178+
await page.getByTestId("confirm-password-input").fill(weakPassword)
179+
await page.getByRole("button", { name: "Update Password" }).click()
185180
await expect(
186181
page.getByText("Password must be at least 8 characters"),
187182
).toBeVisible()
@@ -202,11 +197,11 @@ test.describe("Change password with invalid data", () => {
202197

203198
await page.goto("/settings")
204199
await page.getByRole("tab", { name: "Password" }).click()
205-
await page.getByPlaceholder("Current Password").fill(password)
206-
await page.getByPlaceholder("New Password").fill(newPassword)
207-
await page.getByPlaceholder("Confirm Password").fill(confirmPassword)
208-
await page.getByLabel("Password", { exact: true }).locator("form").click()
209-
await expect(page.getByText("The passwords do not match")).toBeVisible()
200+
await page.getByTestId("current-password-input").fill(password)
201+
await page.getByTestId("new-password-input").fill(newPassword)
202+
await page.getByTestId("confirm-password-input").fill(confirmPassword)
203+
await page.getByRole("button", { name: "Update Password" }).click()
204+
await expect(page.getByText("The passwords don't match")).toBeVisible()
210205
})
211206

212207
test("Current password and new password are the same", async ({ page }) => {
@@ -220,10 +215,10 @@ test.describe("Change password with invalid data", () => {
220215

221216
await page.goto("/settings")
222217
await page.getByRole("tab", { name: "Password" }).click()
223-
await page.getByPlaceholder("Current Password").fill(password)
224-
await page.getByPlaceholder("New Password").fill(password)
225-
await page.getByPlaceholder("Confirm Password").fill(password)
226-
await page.getByRole("button", { name: "Save" }).click()
218+
await page.getByTestId("current-password-input").fill(password)
219+
await page.getByTestId("new-password-input").fill(password)
220+
await page.getByTestId("confirm-password-input").fill(password)
221+
await page.getByRole("button", { name: "Update Password" }).click()
227222
await expect(
228223
page.getByText("New password cannot be the same as the current one"),
229224
).toBeVisible()
@@ -232,54 +227,39 @@ test.describe("Change password with invalid data", () => {
232227

233228
// Appearance
234229

235-
test("Appearance tab is visible", async ({ page }) => {
230+
test("Appearance button is visible in sidebar", async ({ page }) => {
236231
await page.goto("/settings")
237-
await page.getByRole("tab", { name: "Appearance" }).click()
238-
await expect(page.getByLabel("Appearance")).toBeVisible()
232+
await expect(page.getByTestId("theme-button")).toBeVisible()
239233
})
240234

241235
test("User can switch from light mode to dark mode and vice versa", async ({
242236
page,
243237
}) => {
244238
await page.goto("/settings")
245-
await page.getByRole("tab", { name: "Appearance" }).click()
246239

247-
// Ensure the initial state is light mode
240+
await page.getByTestId("theme-button").click()
248241
if (
249242
await page.evaluate(() =>
250243
document.documentElement.classList.contains("dark"),
251244
)
252245
) {
253-
await page
254-
.locator("label")
255-
.filter({ hasText: "Light Mode" })
256-
.locator("span")
257-
.first()
258-
.click()
246+
await page.getByTestId("light-mode").click()
247+
await page.getByTestId("theme-button").click()
259248
}
260249

261250
let isLightMode = await page.evaluate(() =>
262251
document.documentElement.classList.contains("light"),
263252
)
264253
expect(isLightMode).toBe(true)
265254

266-
await page
267-
.locator("label")
268-
.filter({ hasText: "Dark Mode" })
269-
.locator("span")
270-
.first()
271-
.click()
255+
await page.getByTestId("dark-mode").click()
272256
const isDarkMode = await page.evaluate(() =>
273257
document.documentElement.classList.contains("dark"),
274258
)
275259
expect(isDarkMode).toBe(true)
276260

277-
await page
278-
.locator("label")
279-
.filter({ hasText: "Light Mode" })
280-
.locator("span")
281-
.first()
282-
.click()
261+
await page.getByTestId("theme-button").click()
262+
await page.getByTestId("light-mode").click()
283263
isLightMode = await page.evaluate(() =>
284264
document.documentElement.classList.contains("light"),
285265
)
@@ -288,33 +268,23 @@ test("User can switch from light mode to dark mode and vice versa", async ({
288268

289269
test("Selected mode is preserved across sessions", async ({ page }) => {
290270
await page.goto("/settings")
291-
await page.getByRole("tab", { name: "Appearance" }).click()
292271

293-
// Ensure the initial state is light mode
272+
await page.getByTestId("theme-button").click()
294273
if (
295274
await page.evaluate(() =>
296275
document.documentElement.classList.contains("dark"),
297276
)
298277
) {
299-
await page
300-
.locator("label")
301-
.filter({ hasText: "Light Mode" })
302-
.locator("span")
303-
.first()
304-
.click()
278+
await page.getByTestId("light-mode").click()
279+
await page.getByTestId("theme-button").click()
305280
}
306281

307282
const isLightMode = await page.evaluate(() =>
308283
document.documentElement.classList.contains("light"),
309284
)
310285
expect(isLightMode).toBe(true)
311286

312-
await page
313-
.locator("label")
314-
.filter({ hasText: "Dark Mode" })
315-
.locator("span")
316-
.first()
317-
.click()
287+
await page.getByTestId("dark-mode").click()
318288
let isDarkMode = await page.evaluate(() =>
319289
document.documentElement.classList.contains("dark"),
320290
)

0 commit comments

Comments
 (0)