// @vitest-environment jsdom import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { describe, expect, it, vi } from "vitest"; import { createAnonymousSessionAdapter } from "../../../src/adapters/auth/external-session-adapter.ts"; import StateGalleryPage from "../../../src/features/platform-examples-feature/presentation/state-gallery-page.tsx"; import { ApplicationProvider } from "../../../src/presentation/providers/application-provider.tsx"; import { PreferenceProviders } from "../../../src/presentation/providers/preference-providers.tsx"; import { AppRouter } from "../../../src/presentation/routes/app-router.tsx"; import { createTestApplication } from "../../helpers/create-test-application.ts"; /** * The example screens (`/examples/ui`, `/examples/states`, `/examples/auth`) * are the template's content, not the platform (0929/10-02). 1103/09-04: * they are `platform-examples-feature`, and this folder goes with it; the * platform tests run on the test-only feature's pages and keep passing. */ function renderApp( url: string, application = createTestApplication(), ) { window.history.pushState({}, "", url); return render( , ); } describe("example pages", () => { it("reaches the UI gallery from the home page's starter actions", async () => { const user = userEvent.setup(); renderApp("/"); await user.click( await screen.findByRole("link", { name: "UI 구성요소 보기" }), ); await waitFor(() => expect( screen.getByRole("heading", { name: "UI 구성요소", level: 1 }), ).toHaveFocus(), ); }); it("returns to the current URL with its hash from the auth example page", async () => { const user = userEvent.setup(); const beginSignIn = vi.fn(async () => {}); renderApp( "/examples/auth#session", createTestApplication({ session: { ...createAnonymousSessionAdapter(), beginSignIn }, }), ); await user.click( await screen.findByRole("button", { name: "로그인 시작" }), ); expect(beginSignIn).toHaveBeenCalledWith("/examples/auth#session"); }); it("nests the state gallery's titles under the card and section around them (08-05)", () => { render(); expect( screen.getByRole("heading", { name: "아직 표시할 항목이 없습니다.", level: 4 }), ).toBeVisible(); expect(screen.getAllByRole("heading", { level: 3 }).map((h) => h.textContent)) .toEqual(expect.arrayContaining(["빈 화면", "복구 가능한 오류"])); // Access states sit directly under the section's h2. expect( screen.queryAllByRole("heading", { level: 2 }).map((h) => h.textContent), ).toEqual(["비동기 데이터 상태", "접근과 탐색 상태"]); }); });