import { expect, Page, test } from "@playwright/test"; import { applyDeterministicPage, e2eHeaders, useE2EUser } from "./helpers.ts"; test("tenant onboarding lets renters apply and reach dashboard", async ({ page }: { page: Page }) => { await applyDeterministicPage(page); await useE2EUser(page, "tenant"); await page.goto("/onboarding"); // Wait for the page to fully load and sections to be visible await page.waitForLoadState("networkidle"); await expect(page.getByRole("heading", { name: /tenant setup/i, level: 2 })) .toBeVisible(); await page.selectOption("#property_id", "e2e-prop-1"); await page.getByRole("button", { name: /apply to another property|start tenant setup/i, }).click(); await expect(page).toHaveURL(/\/tenant\/dashboard/); await expect(page.getByRole("heading", { name: /tenant portal/i })) .toBeVisible(); }); test("landlord onboarding entry points show dashboard access", async ({ page }: { page: Page }) => { await applyDeterministicPage(page); await useE2EUser(page, "landlord"); await page.goto("/onboarding"); // Wait for the page to fully load and sections to be visible await page.waitForLoadState("networkidle"); await expect(page.getByRole("heading", { name: /landlord setup/i, level: 2 })) .toBeVisible(); await expect(page.getByRole("link", { name: /open landlord dashboard/i })) .toBeVisible(); await expect( page.getByRole("button", { name: /add another property|continue landlord setup|start landlord setup/i, }), ).toBeVisible(); }); test("onboarded landlord skips profile onboarding", async ({ page }: { page: Page }) => { await applyDeterministicPage(page); await useE2EUser(page, "landlord"); await page.goto("/landlord/onboarding/profile"); await expect(page).toHaveURL( /\/landlord\/(properties\/add|onboarding\/property-setup)/, ); await expect(page.getByLabel(/street address/i)).toBeVisible(); }); test("invite links highlight the selected rental on onboarding", async ({ page }: { page: Page }) => { await applyDeterministicPage(page); const inviteResponse = await page.request.post("/api/update/tenant_invite", { headers: { "Content-Type": "application/json", ...e2eHeaders("landlord") }, data: { property_id: "e2e-prop-1" }, }); const invitePayload = await inviteResponse.json(); const inviteId = invitePayload?.invite?.id || ""; expect(inviteId).toBeTruthy(); await page.goto(`/onboarding?invite_id=${inviteId}#tenant`); // Wait for the page to fully load and sections to be visible await page.waitForLoadState("networkidle"); await expect(page.getByRole("heading", { name: /tenant setup/i, level: 2 })) .toBeVisible(); await expect( page.getByRole("heading", { name: /landlord setup/i, level: 2 }), ).toBeHidden(); await expect(page.getByText(/invite selected rental/i)).toBeVisible(); await expect(page.getByText("Skyline Lofts")).toBeVisible(); await expect(page.getByLabel(/select a property/i)).toHaveCount(0); });