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

/**
 * Issue #10 — PO detail shows ALL attachments, grouped by type
 * (Submission / Payment / Delivery). Requires a PO that actually has documents;
 * if the staging mirror has none, the spec skips (documented data limitation).
 */
test.afterAll(closeDb);

test("#10 PO detail groups attachments by type", async ({ page }) => {
  const po = await poWithDocuments();
  test.skip(!po, "no PO with uploaded documents in staging data");

  await login(page, USERS.MANAGER);
  await page.goto(`/po/${po!.id}`);
  await expect(page.getByText(po!.poNumber)).toBeVisible();

  // The attachments region renders at least one of the typed group headings.
  const groups = page.getByText(
    /SUBMISSION DOCUMENTS|PAYMENT DOCUMENTS|DELIVERY RECEIPTS|OTHER ATTACHMENTS/i,
  );
  await expect(groups.first()).toBeVisible();
});
