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

/**
 * Issue #12 — Manager dashboard 'Total approved this month' was stuck at 0 / not
 * updating. Fix: the card counts every PO approved this month (any post-approval
 * status). We assert the rendered value matches the DB-computed count, proving it
 * reflects real data rather than 0.
 */
test.afterAll(closeDb);

test("#12 'Approved This Month' card shows the correct, live count", async ({ page }) => {
  const expected = await approvedThisMonthCount();

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

  const card = page.locator("a,div", { has: page.getByText("Approved This Month", { exact: true }) }).first();
  await expect(card).toBeVisible();
  await expect(card).toContainText(String(expected));
});
