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: "Help can be closer than you think." }),
  ).toBeVisible();
  await expect(page.getByText("Not an emergency or medical service.")).toBeVisible();

  await page.getByRole("link", { name: "Safety rules" }).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();
});
