Skip to content

Commit b0d12b3

Browse files
committed
✅ Update E2E tests for new User Settings UI
1 parent 35b00e4 commit b0d12b3

File tree

1 file changed

+83
-44
lines changed

1 file changed

+83
-44
lines changed

frontend/tests/user-settings.spec.ts

Lines changed: 83 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ 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", "Danger zone"]
7+
const tabs = ["Personal", "Account"]
88

9-
test("My profile tab is active by default", async ({ page }) => {
9+
test("Personal tab is active by default", async ({ page }) => {
1010
await page.goto("/settings")
11-
await expect(page.getByRole("tab", { name: "My profile" })).toHaveAttribute(
11+
await expect(page.getByRole("tab", { name: "Personal" })).toHaveAttribute(
1212
"aria-selected",
1313
"true",
1414
)
@@ -35,20 +35,19 @@ test.describe("Edit user profile", () => {
3535
test.beforeEach(async ({ page }) => {
3636
await logInUser(page, email, password)
3737
await page.goto("/settings")
38-
await page.getByRole("tab", { name: "My profile" }).click()
38+
await page.getByRole("tab", { name: "Personal" }).click()
3939
})
4040

4141
test("Edit user name with a valid name", async ({ page }) => {
4242
const updatedName = "Test User 2"
4343

4444
await page.getByRole("button", { name: "Edit" }).click()
4545
await page.getByLabel("Full name").fill(updatedName)
46-
await page.getByRole("button", { name: "Save" }).click()
46+
await page.getByRole("button", { name: "Save changes" }).click()
4747

48-
await expect(page.getByText("User updated successfully")).toBeVisible()
49-
await expect(
50-
page.locator("form").getByText(updatedName, { exact: true }),
51-
).toBeVisible()
48+
await expect(page.getByText("Profile updated successfully")).toBeVisible()
49+
// Wait for read-only mode to be restored (Edit button reappears)
50+
await expect(page.getByRole("button", { name: "Edit" })).toBeVisible()
5251
})
5352

5453
test("Edit user email with an invalid email shows error", async ({
@@ -73,54 +72,36 @@ test.describe("Edit user email", () => {
7372
await createUser({ email, password })
7473
await logInUser(page, email, password)
7574
await page.goto("/settings")
76-
await page.getByRole("tab", { name: "My profile" }).click()
75+
await page.getByRole("tab", { name: "Personal" }).click()
7776

7877
await page.getByRole("button", { name: "Edit" }).click()
7978
await page.getByLabel("Email").fill(updatedEmail)
80-
await page.getByRole("button", { name: "Save" }).click()
79+
await page.getByRole("button", { name: "Save changes" }).click()
8180

82-
await expect(page.getByText("User updated successfully")).toBeVisible()
83-
await expect(
84-
page.locator("form").getByText(updatedEmail, { exact: true }),
85-
).toBeVisible()
81+
await expect(page.getByText("Profile updated successfully")).toBeVisible()
82+
// Wait for read-only mode to be restored (Edit button reappears)
83+
await expect(page.getByRole("button", { name: "Edit" })).toBeVisible()
8684
})
8785
})
8886

8987
test.describe("Cancel edit actions", () => {
9088
test.use({ storageState: { cookies: [], origins: [] } })
9189

92-
test("Cancel edit action restores original name", async ({ page }) => {
93-
const email = randomEmail()
94-
const password = randomPassword()
95-
const user = await createUser({ email, password })
96-
97-
await logInUser(page, email, password)
98-
await page.goto("/settings")
99-
await page.getByRole("tab", { name: "My profile" }).click()
100-
await page.getByRole("button", { name: "Edit" }).click()
101-
await page.getByLabel("Full name").fill("Test User")
102-
await page.getByRole("button", { name: "Cancel" }).first().click()
103-
104-
await expect(
105-
page.locator("form").getByText(user.full_name as string, { exact: true }),
106-
).toBeVisible()
107-
})
108-
109-
test("Cancel edit action restores original email", async ({ page }) => {
90+
test("Cancel edit action restores original values", async ({ page }) => {
11091
const email = randomEmail()
11192
const password = randomPassword()
11293
await createUser({ email, password })
11394

11495
await logInUser(page, email, password)
11596
await page.goto("/settings")
116-
await page.getByRole("tab", { name: "My profile" }).click()
97+
await page.getByRole("tab", { name: "Personal" }).click()
11798
await page.getByRole("button", { name: "Edit" }).click()
99+
await page.getByLabel("Full name").fill("Test User")
118100
await page.getByLabel("Email").fill(randomEmail())
119101
await page.getByRole("button", { name: "Cancel" }).first().click()
120102

121-
await expect(
122-
page.locator("form").getByText(email, { exact: true }),
123-
).toBeVisible()
103+
// Wait for read-only mode to be restored (Edit button reappears)
104+
await expect(page.getByRole("button", { name: "Edit" })).toBeVisible()
124105
})
125106
})
126107

@@ -136,11 +117,12 @@ test.describe("Change password", () => {
136117
await logInUser(page, email, password)
137118

138119
await page.goto("/settings")
139-
await page.getByRole("tab", { name: "Password" }).click()
120+
await page.getByRole("tab", { name: "Account" }).click()
121+
await page.getByRole("button", { name: "Change password" }).click()
140122
await page.getByTestId("current-password-input").fill(password)
141123
await page.getByTestId("new-password-input").fill(newPassword)
142124
await page.getByTestId("confirm-password-input").fill(newPassword)
143-
await page.getByRole("button", { name: "Update Password" }).click()
125+
await page.getByRole("button", { name: "Update password" }).click()
144126

145127
await expect(page.getByText("Password updated successfully")).toBeVisible()
146128

@@ -163,7 +145,8 @@ test.describe("Change password validation", () => {
163145
test.beforeEach(async ({ page }) => {
164146
await logInUser(page, email, password)
165147
await page.goto("/settings")
166-
await page.getByRole("tab", { name: "Password" }).click()
148+
await page.getByRole("tab", { name: "Account" }).click()
149+
await page.getByRole("button", { name: "Change password" }).click()
167150
})
168151

169152
test("Update password with weak passwords", async ({ page }) => {
@@ -172,7 +155,7 @@ test.describe("Change password validation", () => {
172155
await page.getByTestId("current-password-input").fill(password)
173156
await page.getByTestId("new-password-input").fill(weakPassword)
174157
await page.getByTestId("confirm-password-input").fill(weakPassword)
175-
await page.getByRole("button", { name: "Update Password" }).click()
158+
await page.getByRole("button", { name: "Update password" }).click()
176159

177160
await expect(
178161
page.getByText("Password must be at least 8 characters"),
@@ -185,16 +168,16 @@ test.describe("Change password validation", () => {
185168
await page.getByTestId("current-password-input").fill(password)
186169
await page.getByTestId("new-password-input").fill(randomPassword())
187170
await page.getByTestId("confirm-password-input").fill(randomPassword())
188-
await page.getByRole("button", { name: "Update Password" }).click()
171+
await page.getByRole("button", { name: "Update password" }).click()
189172

190-
await expect(page.getByText("The passwords don't match")).toBeVisible()
173+
await expect(page.getByText("Passwords do not match")).toBeVisible()
191174
})
192175

193176
test("Current password and new password are the same", async ({ page }) => {
194177
await page.getByTestId("current-password-input").fill(password)
195178
await page.getByTestId("new-password-input").fill(password)
196179
await page.getByTestId("confirm-password-input").fill(password)
197-
await page.getByRole("button", { name: "Update Password" }).click()
180+
await page.getByRole("button", { name: "Update password" }).click()
198181

199182
await expect(
200183
page.getByText("New password cannot be the same as the current one"),
@@ -254,3 +237,59 @@ test("Selected mode is preserved across sessions", async ({ page }) => {
254237
)
255238
expect(isDarkMode).toBe(true)
256239
})
240+
241+
test.describe("Delete account", () => {
242+
test.use({ storageState: { cookies: [], origins: [] } })
243+
244+
test("Delete account successfully", async ({ page }) => {
245+
const email = randomEmail()
246+
const password = randomPassword()
247+
248+
await createUser({ email, password })
249+
await logInUser(page, email, password)
250+
251+
await page.goto("/settings")
252+
await page.getByRole("tab", { name: "Account" }).click()
253+
await page.getByRole("button", { name: "Delete account" }).click()
254+
255+
// Verify dialog is shown
256+
await expect(page.getByRole("dialog")).toBeVisible()
257+
await expect(
258+
page.getByRole("heading", { name: "Delete account" }),
259+
).toBeVisible()
260+
await expect(
261+
page.getByText("All your account data will be permanently deleted"),
262+
).toBeVisible()
263+
264+
// Confirm deletion
265+
await page.getByRole("button", { name: "Delete", exact: true }).click()
266+
267+
// Verify user is logged out and redirected to login (toast may not be visible due to redirect)
268+
await expect(page).toHaveURL("/login")
269+
})
270+
271+
test("Cancel delete account dialog", async ({ page }) => {
272+
const email = randomEmail()
273+
const password = randomPassword()
274+
275+
await createUser({ email, password })
276+
await logInUser(page, email, password)
277+
278+
await page.goto("/settings")
279+
await page.getByRole("tab", { name: "Account" }).click()
280+
await page.getByRole("button", { name: "Delete account" }).click()
281+
282+
// Verify dialog is shown
283+
await expect(page.getByRole("dialog")).toBeVisible()
284+
285+
// Cancel deletion
286+
await page.getByRole("button", { name: "Cancel" }).click()
287+
288+
// Verify dialog is closed
289+
await expect(page.getByRole("dialog")).not.toBeVisible()
290+
291+
// Verify user is still logged in and can access settings
292+
await expect(page).toHaveURL("/settings")
293+
await expect(page.getByRole("tab", { name: "Personal" })).toBeVisible()
294+
})
295+
})

0 commit comments

Comments
 (0)