|
1 | 1 | import { expect, test } from "@playwright/test"; |
2 | | - |
3 | | -// Use a clean user for this test, to not interfere with other tests |
4 | | -test.use({ storageState: { cookies: [], origins: [] } }); |
| 2 | +import { testWithNewUser } from "./test-with-new-user"; |
5 | 3 |
|
6 | 4 | test.describe("User Email Change Flow", () => { |
7 | | - test("should sign up new user, change email, sign out, and sign in with new email", async ({ |
8 | | - page, |
9 | | - }) => { |
10 | | - // Generate random emails for the test |
11 | | - const initialEmail = `${Math.random().toString(36).substring(2, 15)}@example.com`; |
12 | | - const newEmail = `${Math.random().toString(36).substring(2, 15)}@example.com`; |
13 | | - const testPassword = "testpassword123"; |
14 | | - |
15 | | - await test.step("Navigate to homepage and ensure clean state", async () => { |
16 | | - await page.goto("/"); |
17 | | - await expect(page).toHaveTitle("Playwright Tutorial"); |
18 | | - |
19 | | - // Verify we're not logged in by checking for Sign Up link |
20 | | - await expect(page.getByRole("link", { name: "Sign Up" })).toBeVisible(); |
21 | | - }); |
22 | | - |
23 | | - await test.step("Navigate to sign up page", async () => { |
24 | | - await page.getByRole("link", { name: "Sign Up" }).click(); |
25 | | - await expect(page).toHaveURL("/sign-up"); |
26 | | - await expect( |
27 | | - page.getByRole("heading", { name: "Create your account" }), |
28 | | - ).toBeVisible(); |
29 | | - }); |
30 | | - |
31 | | - await test.step("Fill signup form and submit", async () => { |
32 | | - await page.getByRole("textbox", { name: "Email" }).fill(initialEmail); |
33 | | - await page.getByRole("textbox", { name: "Password" }).fill(testPassword); |
34 | | - await page.getByRole("button", { name: "Sign up" }).click(); |
35 | | - }); |
36 | | - |
37 | | - await test.step("Verify successful signup redirects to dashboard", async () => { |
38 | | - await expect(page).toHaveURL("/dashboard"); |
39 | | - await expect( |
40 | | - page.getByRole("heading", { name: "Team Settings" }), |
41 | | - ).toBeVisible(); |
42 | | - // Verify initial email appears in team members list |
| 5 | + testWithNewUser( |
| 6 | + "should sign up new user, change email, sign out, and sign in with new email", |
| 7 | + async ({ page, newUser: { email: initialEmail, password } }) => { |
| 8 | + await page.goto("/dashboard"); |
43 | 9 | await expect(page.getByText(initialEmail)).toBeVisible(); |
44 | | - }); |
45 | | - |
46 | | - await test.step("Navigate to general settings page", async () => { |
47 | | - await page.getByRole("link", { name: "General" }).click(); |
48 | | - await expect(page).toHaveURL("/dashboard/general"); |
49 | | - await expect( |
50 | | - page.getByRole("heading", { name: "General Settings" }), |
51 | | - ).toBeVisible(); |
52 | | - }); |
53 | | - |
54 | | - await test.step("Change email to new randomly generated email", async () => { |
55 | | - const nameInput = page.getByRole("textbox", { name: "Name" }); |
56 | | - await expect(nameInput).toBeVisible(); |
57 | | - await nameInput.fill("John Doe"); |
58 | | - |
59 | | - const emailInput = page.getByRole("textbox", { name: "Email" }); |
60 | | - await expect(emailInput).toBeVisible(); |
61 | | - await expect(emailInput).toHaveValue(initialEmail); |
62 | | - |
63 | | - await emailInput.clear(); |
64 | | - await emailInput.fill(newEmail); |
65 | | - await page.getByRole("button", { name: "Save Changes" }).click(); |
66 | | - |
67 | | - // Wait for success message |
68 | | - await expect( |
69 | | - page.getByText("Account updated successfully."), |
70 | | - ).toBeVisible(); |
71 | | - }); |
72 | | - |
73 | | - await test.step("Sign out", async () => { |
74 | | - // Click on user menu button |
75 | | - await page.getByTestId("user-menu-trigger").click(); |
76 | | - await page.getByRole("button", { name: "Sign out" }).click(); |
77 | | - |
78 | | - // Verify we're signed out by checking for Sign Up link |
79 | | - await expect(page.getByRole("link", { name: "Sign Up" })).toBeVisible(); |
80 | | - }); |
81 | | - |
82 | | - await test.step("Sign in with new email and test password", async () => { |
83 | | - // If not already on sign-in page, navigate there |
84 | | - const currentUrl = page.url(); |
85 | | - if (!currentUrl.includes("/sign-in")) { |
86 | | - await page.goto("/sign-in"); |
87 | | - } |
88 | | - |
89 | | - await expect( |
90 | | - page.getByRole("heading", { name: "Sign in to your account" }), |
91 | | - ).toBeVisible(); |
92 | | - |
93 | | - await page.getByRole("textbox", { name: "Email" }).fill(newEmail); |
94 | | - await page.getByRole("textbox", { name: "Password" }).fill(testPassword); |
95 | | - await page.getByRole("button", { name: "Sign in" }).click(); |
96 | | - }); |
97 | | - |
98 | | - await test.step("Verify successful sign in and redirect to team settings page", async () => { |
99 | | - await expect(page).toHaveURL("/dashboard"); |
100 | | - await expect( |
101 | | - page.getByRole("heading", { name: "Team Settings" }), |
102 | | - ).toBeVisible(); |
103 | | - }); |
104 | | - |
105 | | - await test.step("Verify new email is displayed in general settings page", async () => { |
106 | | - await page.getByRole("link", { name: "General" }).click(); |
107 | | - await expect(page).toHaveURL("/dashboard/general"); |
108 | | - await expect( |
109 | | - page.getByRole("heading", { name: "General Settings" }), |
110 | | - ).toBeVisible(); |
111 | 10 |
|
112 | | - // Verify the new email is displayed in the email field |
113 | | - const emailInput = page.getByRole("textbox", { name: "Email" }); |
114 | | - await expect(emailInput).toBeVisible(); |
115 | | - await expect(emailInput).toHaveValue(newEmail); |
116 | | - }); |
117 | | - }); |
| 11 | + await test.step("Navigate to general settings page", async () => { |
| 12 | + await page.getByRole("link", { name: "General" }).click(); |
| 13 | + await expect(page).toHaveURL("/dashboard/general"); |
| 14 | + await expect( |
| 15 | + page.getByRole("heading", { name: "General Settings" }), |
| 16 | + ).toBeVisible(); |
| 17 | + }); |
| 18 | + |
| 19 | + const newEmail = `${Math.random().toString(36).substring(2, 15)}@example.com`; |
| 20 | + |
| 21 | + await test.step("Change email to new randomly generated email", async () => { |
| 22 | + const nameInput = page.getByRole("textbox", { name: "Name" }); |
| 23 | + await expect(nameInput).toBeVisible(); |
| 24 | + await nameInput.fill("John Doe"); |
| 25 | + |
| 26 | + const emailInput = page.getByRole("textbox", { name: "Email" }); |
| 27 | + await expect(emailInput).toBeVisible(); |
| 28 | + await expect(emailInput).toHaveValue(initialEmail); |
| 29 | + |
| 30 | + await emailInput.clear(); |
| 31 | + await emailInput.fill(newEmail); |
| 32 | + await page.getByRole("button", { name: "Save Changes" }).click(); |
| 33 | + |
| 34 | + // Wait for success message |
| 35 | + await expect( |
| 36 | + page.getByText("Account updated successfully."), |
| 37 | + ).toBeVisible(); |
| 38 | + }); |
| 39 | + |
| 40 | + await test.step("Sign out", async () => { |
| 41 | + // Click on user menu button |
| 42 | + await page.getByTestId("user-menu-trigger").click(); |
| 43 | + await page.getByRole("button", { name: "Sign out" }).click(); |
| 44 | + |
| 45 | + // Verify we're signed out by checking for Sign Up link |
| 46 | + await expect(page.getByRole("link", { name: "Sign Up" })).toBeVisible(); |
| 47 | + }); |
| 48 | + |
| 49 | + await test.step("Sign in with new email and test password", async () => { |
| 50 | + // If not already on sign-in page, navigate there |
| 51 | + const currentUrl = page.url(); |
| 52 | + if (!currentUrl.includes("/sign-in")) { |
| 53 | + await page.goto("/sign-in"); |
| 54 | + } |
| 55 | + |
| 56 | + await expect( |
| 57 | + page.getByRole("heading", { name: "Sign in to your account" }), |
| 58 | + ).toBeVisible(); |
| 59 | + |
| 60 | + await page.getByRole("textbox", { name: "Email" }).fill(newEmail); |
| 61 | + await page.getByRole("textbox", { name: "Password" }).fill(password); |
| 62 | + await page.getByRole("button", { name: "Sign in" }).click(); |
| 63 | + }); |
| 64 | + |
| 65 | + await test.step("Verify successful sign in and redirect to team settings page", async () => { |
| 66 | + await expect(page).toHaveURL("/dashboard"); |
| 67 | + await expect( |
| 68 | + page.getByRole("heading", { name: "Team Settings" }), |
| 69 | + ).toBeVisible(); |
| 70 | + }); |
| 71 | + |
| 72 | + await test.step("Verify new email is displayed in general settings page", async () => { |
| 73 | + await page.getByRole("link", { name: "General" }).click(); |
| 74 | + await expect(page).toHaveURL("/dashboard/general"); |
| 75 | + await expect( |
| 76 | + page.getByRole("heading", { name: "General Settings" }), |
| 77 | + ).toBeVisible(); |
| 78 | + |
| 79 | + // Verify the new email is displayed in the email field |
| 80 | + const emailInput = page.getByRole("textbox", { name: "Email" }); |
| 81 | + await expect(emailInput).toBeVisible(); |
| 82 | + await expect(emailInput).toHaveValue(newEmail); |
| 83 | + }); |
| 84 | + }, |
| 85 | + ); |
118 | 86 | }); |
0 commit comments