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

test("clients page loads correctly", async ({ page }) => {
  await seedAuth(page);
  await installDevApiMock(page, {
    clients: [
      makeClient("client-playwright", {
        name: "Playwright Client",
        createdAt: new Date().toISOString(),
        redirectUris: ["http://localhost:5174/callback"],
      }),
    ],
    consents: [] as Consent[],
    auditLogsByCursor: undefined,
  });

  await page.goto("/clients");
  await expect(page).toHaveURL(/\/clients$/);

  // 타이틀 확인
  await expect(page).toHaveTitle(/바론 개발자 서비스/);

  // 페이지 내 주요 텍스트 확인
  await expect(page.getByText("연동 앱 목록")).toBeVisible();

  // 테이블 헤더 확인
  await expect(
    page.locator("th").filter({ hasText: "애플리케이션" }),
  ).toBeVisible();
  await expect(
    page.locator("th").filter({ hasText: /클라이언트 ID|Client ID/i }),
  ).toBeVisible();
});
