// @vitest-environment jsdom import { render, screen, waitFor } from "@testing-library/react"; import userEvent from "@testing-library/user-event"; import { MemoryRouter } from "react-router-dom"; import { describe, expect, it, vi } from "vitest"; import { createAnonymousSessionAdapter } from "../../src/adapters/auth/external-session-adapter.ts"; import StateGalleryPage from "../../src/presentation/examples/state-gallery-page.tsx"; import { LocaleProvider } from "../../src/presentation/i18n/index.ts"; import HomePage from "../../src/presentation/pages/home-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 starter screens (`/` and `/examples/*`) are the template's content, not * the platform (0929/10-02). A product that replaces them deletes the * `starter-*.test.tsx` files with them; 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("starter home page", () => { it("reaches the platform overview from the starter actions", async () => { const user = userEvent.setup(); renderApp("/"); await user.click( await screen.findByRole("link", { name: "플랫폼 구성 보기" }), ); await waitFor(() => expect( screen.getByRole("heading", { name: "플랫폼 구성", level: 1 }), ).toHaveFocus(), ); }); it("stops the release summary from loading forever", async () => { render( { throw new Error("manifest unavailable"); }, refresh: async () => { throw new Error("manifest unavailable"); }, }, })} > {/* HomePage renders router links, so it needs a router but not the app one. */} , ); await waitFor(() => expect( screen.getByText("런타임 정보를 확인하지 못했습니다."), ).toBeVisible(), ); expect( screen.queryByText("검증된 런타임 정보를 확인하고 있습니다."), ).not.toBeInTheDocument(); }); }); describe("starter example pages", () => { 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(["비동기 데이터 상태", "접근과 탐색 상태"]); }); });