import { test, expect } from "@playwright/test";

/**
 * Backoffice smoke (Track B foundation): the staff storageState authenticates past the middleware
 * cookie gate, /currencies loads its list from the API, and the add-rate control is reachable.
 * Proves staff auth (cookie + localStorage + API token) is fully wired.
 */
test("backoffice: staff can load /currencies and reach the add-rate control", async ({ page }) => {
  await page.goto("/currencies", { waitUntil: "domcontentloaded" });

  // Not bounced to /login (middleware cookie gate passed).
  await expect(page).not.toHaveURL(/\/login/);

  // The page rendered a currencies view with a seeded currency and an add control.
  await expect(page.getByText(/ETB|USD|DJF/).first()).toBeVisible({ timeout: 20_000 });
  await expect(
    page.getByRole("button", { name: /add/i }).first(),
  ).toBeVisible();
});
