import { expect, test } from "@playwright/test";
import {
  type Consent,
  installDevApiMock,
  makeClient,
  seedAuth,
} from "./helpers/devfront-fixtures";

test.describe("DevFront consents", () => {
  test.beforeEach(async ({ page }) => {
    page.on("dialog", async (dialog) => {
      await dialog.accept();
    });
    await seedAuth(page);
  });

  test("consent list and revoke flow", async ({ page }) => {
    const state = {
      clients: [makeClient("client-consent", { name: "Consent app" })],
      consents: [
        {
          subject: "user-1",
          userName: "Alice",
          clientId: "client-consent",
          clientName: "Consent app",
          grantedScopes: ["openid", "profile"],
          authenticatedAt: "2026-03-03T08:00:00.000Z",
          createdAt: "2026-03-02T08:00:00.000Z",
          status: "active",
          tenantId: "tenant-a",
          tenantName: "Tenant A",
        },
      ] as Consent[],
      auditLogsByCursor: undefined,
    };
    await installDevApiMock(page, state);

    await page.goto("/clients/client-consent/consents");
    await expect(page.getByText("Alice")).toBeVisible();
    await expect(page.getByText("Tenant A")).toBeVisible();

    await page.getByRole("button", { name: /권한 철회|철회|Revoke/i }).click();
    await expect(page.getByText(/Revoked|철회/i).first()).toBeVisible();
  });
});
