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

/**
 * Issue #41 — the dashboard 'Total Purchase Orders' card shows the correct count.
 * Issue #26 — that stat card is clickable and links to the history page.
 * Both are verified on the generic dashboard (AUDITOR role).
 */
test.afterAll(closeDb);

test("#41 'Total Purchase Orders' card shows the correct unfiltered count", async ({ page }) => {
  const expected = await totalPoCount();
  await login(page, USERS.AUDITOR);
  await page.goto("/dashboard");

  const card = page.getByRole("link").filter({ hasText: "Total Purchase Orders" });
  await expect(card).toBeVisible();
  await expect(card).toContainText(String(expected));
});

test("#26 'Total Purchase Orders' card links to the history page", async ({ page }) => {
  await login(page, USERS.AUDITOR);
  await page.goto("/dashboard");
  await page.getByRole("link").filter({ hasText: "Total Purchase Orders" }).click();
  await expect(page).toHaveURL(/\/history/);
});
