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

/**
 * Issue #11 — Admin-managed Terms & Conditions catalogue feeding a dynamic PO editor.
 *  - Admin surface at /admin/terms.
 *  - The PO create form renders a Terms & Conditions editor.
 */
test("#11 admin Terms & Conditions page renders for a manager", async ({ page }) => {
  await login(page, USERS.MANAGER);
  await page.goto("/admin/terms");
  await expect(page).not.toHaveURL(/\/login/);
  await expect(page.getByRole("heading", { name: /terms.*conditions/i }).first()).toBeVisible();
});

test("#11 new PO form includes a Terms & Conditions editor", async ({ page }) => {
  await login(page, USERS.MANAGER);
  await page.goto("/po/new");
  await expect(page.getByText(/terms.*conditions/i).first()).toBeVisible();
  // The dynamic editor offers an "Add term" affordance.
  await expect(page.getByRole("button", { name: /add term/i })).toBeVisible();
});
