|
| 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: [] } }); |
| 5 | + |
| 6 | +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 |
| 43 | + 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 | + |
| 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 | + }); |
| 118 | +}); |
0 commit comments