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

/**
 * Issue #4 — Submitter can set an optional PO date (back/forward-datable).
 * Fix: a `poDate` date input on the PO create/edit forms.
 */
test("#4 PO create form exposes an optional, free-to-set PO Date field", async ({ page }) => {
  await login(page, USERS.TECH);
  await page.goto("/po/new");

  const poDate = page.locator('input[name="poDate"]');
  await expect(poDate).toBeVisible();
  await expect(poDate).toHaveAttribute("type", "date");
  await expect(poDate).not.toHaveAttribute("required", "");

  // It accepts a back-dated value and a forward-dated value.
  await poDate.fill("2024-01-15");
  await expect(poDate).toHaveValue("2024-01-15");
  await poDate.fill("2030-12-31");
  await expect(poDate).toHaveValue("2030-12-31");
});
