import { test, expect } from "@playwright/test";
import { USERS, login } from "./helpers";

/**
 * Crewing epics (#75 Requisitions, #76 Candidates, #79 Crew records, #81 Leave &
 * Attendance, #83 Office verification, #86 Reference data/admin) — feature-flagged
 * behind NEXT_PUBLIC_CREWING_ENABLED, which is "true" on staging.
 *
 * These are smoke checks that each epic's primary surface renders for an authorised
 * role (the deep state-machine flows — pipeline #77, onboarding #78, PPE #80,
 * appraisal #82, sign-off #85 — are covered by the existing integration suites noted
 * in Docs/TESTING.md). Render-without-redirect is the proof the shipped feature is
 * live on staging.
 */

const PAGES: Array<{ issue: string; name: string; path: string; user: keyof typeof USERS; heading: RegExp }> = [
  { issue: "#75", name: "Requisitions", path: "/crewing/requisitions", user: "MANAGER", heading: /requisition/i },
  { issue: "#76", name: "Candidates",   path: "/crewing/candidates",   user: "MANAGER", heading: /candidate/i },
  { issue: "#79", name: "Crew records", path: "/crewing/crew",         user: "MANAGER", heading: /crew/i },
  { issue: "#81", name: "Leave",        path: "/crewing/leave",        user: "MANAGER", heading: /leave/i },
  { issue: "#81", name: "Attendance",   path: "/crewing/attendance",   user: "MANAGER", heading: /attendance/i },
  { issue: "#83", name: "Verification", path: "/crewing/verification", user: "MANNING", heading: /verif/i },
  { issue: "#86", name: "Ranks",        path: "/admin/ranks",          user: "MANAGER", heading: /rank/i },
  { issue: "#86", name: "Crew admin",   path: "/admin/crew",           user: "MANAGER", heading: /crew/i },
];

for (const p of PAGES) {
  test(`${p.issue} ${p.name} surface renders on staging (${p.path})`, async ({ page }) => {
    await login(page, USERS[p.user]);
    await page.goto(p.path);
    await expect(page, `should not redirect away from ${p.path}`).toHaveURL(new RegExp(p.path.replace(/\//g, "\\/")));
    await expect(page.getByRole("heading", { name: p.heading }).first()).toBeVisible();
  });
}
