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

/**
 * Issue #32 — the manager 'Approved This Month' card counts POs approved this month
 * regardless of their current status, and clicking it opens history pre-filtered by
 * approval date (?approvedFrom=YYYY-MM-01).
 */
test("#32 'Approved This Month' card links to history filtered by approval date", async ({ page }) => {
  const now = new Date();
  const expectedParam = `${now.getFullYear()}-${String(now.getMonth() + 1).padStart(2, "0")}-01`;

  await login(page, USERS.MANAGER);
  await page.goto("/dashboard");

  const card = page.getByRole("link").filter({ hasText: "Approved This Month" });
  await expect(card).toBeVisible();
  await card.click();

  await expect(page).toHaveURL(new RegExp(`/history\\?approvedFrom=${expectedParam}`));
});
