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

/**
 * Issue #14 — 'Email to vendor' option becomes available once a PO is approved (and
 * after payment), when the vendor has a contact email. We assert the button is
 * present on such a PO. (The underlying PDF/Outlook pipeline depends on PdfService
 * env config; this verifies the user-facing affordance exists.)
 */
test.afterAll(closeDb);

test("#14 approved PO with a vendor email shows the 'Email to vendor' button", async ({ page }) => {
  const po = await poWithVendorEmail();
  test.skip(!po, "no approved PO with a vendor contact email in staging data");

  await login(page, USERS.MANAGER);
  await page.goto(`/po/${po!.id}`);
  await expect(page.getByText(po!.poNumber)).toBeVisible();
  await expect(page.getByRole("button", { name: /email to vendor/i })).toBeVisible();
});
