import { expect, test } from "@playwright/test"; import { captureBrowserFailures } from "./helpers"; test("public safety pages load and private discovery requires authentication", async ({ page, }) => { const assertNoBrowserFailures = captureBrowserFailures(page); await page.goto("/"); await expect( page.getByRole("heading", { name: "Need help nearby? Ask the community." }), ).toBeVisible(); await expect(page.getByText("Not an emergency or medical service.")).toBeVisible(); await page.getByRole("link", { name: "Safety rules", exact: true }).click(); await expect(page.getByRole("heading", { name: "Safety rules" })).toBeVisible(); await expect(page.getByRole("heading", { name: "Medicine requests" })).toBeVisible(); await page.getByRole("link", { name: "Requests" }).click(); await expect(page).toHaveURL(/\/users\/log-in$/); await expect(page.getByText("You must log in to access this page.")).toBeVisible(); assertNoBrowserFailures(); }); test("public demo labels the non-WebGL fallback honestly and offers retry", async ({ page, }) => { const assertNoBrowserFailures = captureBrowserFailures(page); const mapWarnings: string[] = []; page.on("console", (message) => { if (message.type() === "warning" && message.text().includes("Map unavailable")) { mapWarnings.push(message.text()); } }); await page.addInitScript(() => { const originalGetContext = HTMLCanvasElement.prototype.getContext; HTMLCanvasElement.prototype.getContext = function ( contextId: string, options?: unknown, ) { if (contextId === "webgl" || contextId === "webgl2") return null; return originalGetContext.call(this, contextId, options as never); } as typeof HTMLCanvasElement.prototype.getContext; }); await page.goto("/"); const map = page.locator("#home-demo-map"); const status = page.locator("[data-map-status-badge]"); const retry = map.getByRole("button", { name: "Try map again" }); await map.scrollIntoViewIfNeeded(); await expect(map.locator("[data-map-fallback=true]")).toBeVisible(); await expect(status).toHaveText("Static preview"); await expect(retry).toBeVisible(); await expect(map).toHaveAttribute("data-map-unavailable-reason", "webgl-context-unavailable"); await expect.poll(() => mapWarnings.length).toBe(1); await retry.click(); await expect.poll(() => mapWarnings.length).toBe(2); await expect(status).toHaveText("Static preview"); await expect(retry).toBeVisible(); assertNoBrowserFailures(); });