|
| 1 | +import { expect, test, type Page } from "@playwright/test"; |
| 2 | + |
| 3 | +const HOST_EMAIL = "demo-host@peels.local"; |
| 4 | +const DONOR_EMAIL = "demo-donor@peels.local"; |
| 5 | +const SEEDED_PASSWORD = "peels-demo-password"; |
| 6 | +const SEEDED_THREAD_ID = "33333333-3333-4333-8333-333333333333"; |
| 7 | + |
| 8 | +async function signIn( |
| 9 | + page: Page, |
| 10 | + { |
| 11 | + email, |
| 12 | + redirectTo = "/profile", |
| 13 | + }: { |
| 14 | + email: string; |
| 15 | + redirectTo?: string; |
| 16 | + } |
| 17 | +) { |
| 18 | + await page.goto(`/sign-in?redirect_to=${encodeURIComponent(redirectTo)}`); |
| 19 | + |
| 20 | + await expect(page.getByTestId("sign-in-form")).toBeVisible(); |
| 21 | + |
| 22 | + await page.getByLabel("Email").fill(email); |
| 23 | + await page.getByLabel("Password").fill(SEEDED_PASSWORD); |
| 24 | + |
| 25 | + await Promise.all([ |
| 26 | + page.waitForURL((url) => url.pathname === redirectTo), |
| 27 | + page.getByTestId("sign-in-submit").click(), |
| 28 | + ]); |
| 29 | +} |
| 30 | + |
| 31 | +test("auth-sign-in redirects a seeded donor into the signed-in experience", async ({ |
| 32 | + page, |
| 33 | +}) => { |
| 34 | + await signIn(page, { email: DONOR_EMAIL, redirectTo: "/profile" }); |
| 35 | + |
| 36 | + await expect(page).toHaveURL(/\/profile$/); |
| 37 | + await expect(page.getByTestId("profile-first-name")).toHaveText("Riley"); |
| 38 | +}); |
| 39 | + |
| 40 | +test("public-listing shows the seeded public listing and guest contact gate", async ({ |
| 41 | + page, |
| 42 | +}) => { |
| 43 | + await page.goto("/listings/demo-marrickville-compost"); |
| 44 | + |
| 45 | + await expect( |
| 46 | + page.getByRole("heading", { name: "Marrickville Neighbourhood Compost" }) |
| 47 | + ).toBeVisible(); |
| 48 | + await expect(page.getByTestId("listing-guest-cta")).toBeVisible(); |
| 49 | + await expect(page.getByTestId("listing-sign-in-to-contact")).toHaveAttribute( |
| 50 | + "href", |
| 51 | + "/sign-in?redirect_to=/listings/demo-marrickville-compost" |
| 52 | + ); |
| 53 | +}); |
| 54 | + |
| 55 | +test("profile loads the seeded host account and listings", async ({ page }) => { |
| 56 | + await signIn(page, { email: HOST_EMAIL, redirectTo: "/profile" }); |
| 57 | + |
| 58 | + await expect(page.getByTestId("profile-first-name")).toHaveText("Avery"); |
| 59 | + await expect(page.getByTestId("profile-listings")).toContainText( |
| 60 | + "Marrickville Neighbourhood Compost" |
| 61 | + ); |
| 62 | + await expect(page.getByTestId("profile-listings")).toContainText( |
| 63 | + "Inner West Cafe Compost Pickup" |
| 64 | + ); |
| 65 | +}); |
| 66 | + |
| 67 | +test("chat loads the seeded thread and composer for a signed-in donor", async ({ |
| 68 | + page, |
| 69 | +}) => { |
| 70 | + await signIn(page, { |
| 71 | + email: DONOR_EMAIL, |
| 72 | + redirectTo: `/chats/${SEEDED_THREAD_ID}`, |
| 73 | + }); |
| 74 | + |
| 75 | + await expect(page).toHaveURL(new RegExp(`/chats/${SEEDED_THREAD_ID}$`)); |
| 76 | + await expect(page.getByTestId("chat-window")).toBeVisible(); |
| 77 | + await expect(page.getByTestId("chat-message-list")).toContainText( |
| 78 | + "Hey Avery, do you take coffee grounds from a small home espresso machine?" |
| 79 | + ); |
| 80 | + await expect(page.getByTestId("chat-message-list")).toContainText( |
| 81 | + "Yes, absolutely. Small sealed containers are perfect." |
| 82 | + ); |
| 83 | + await expect(page.getByTestId("chat-composer")).toBeVisible(); |
| 84 | + await expect(page.getByTestId("chat-composer-input")).toBeVisible(); |
| 85 | +}); |
0 commit comments