// @vitest-environment jsdom import { render, screen, waitFor, within } 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 { ROUTE_FEATURE_OWNER, ROUTE_REGISTRY, } from "../../../src/features/installed-feature-contracts.ts"; import { PLATFORM_EXAMPLES_FEATURE_ID } from "../../../src/features/platform-examples-feature/contracts/platform-examples-contract.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"; import { createProductFeaturesStub } from "../../helpers/runtime-capabilities-stub.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(), ); }); // 1105/08-03. The home page's starter links read the same switch as the // shell's navigation: switched off at runtime, this feature's screens are // not offered there, and the next active screens take their place. it("leaves this feature's screens out of the home page's starter links when it is switched off", async () => { renderApp( "/", createTestApplication({ productFeatures: createProductFeaturesStub({ [PLATFORM_EXAMPLES_FEATURE_ID]: "DISABLED_BY_CONFIG", }), }), ); const starter = await screen.findByRole("region", { name: "준비된 화면 살펴보기" }); const starterPaths = within(starter) .getAllByRole("link") .map((link) => link.getAttribute("href")); const ownPaths = Object.values(ROUTE_REGISTRY) .filter((route) => ROUTE_FEATURE_OWNER[route.routeId] === PLATFORM_EXAMPLES_FEATURE_ID) .map((route) => route.path); const [navigation] = screen.getAllByRole("navigation", { name: "주요 탐색" }); const advertised = within(navigation!) .getAllByRole("link") .map((link) => link.getAttribute("href")) .filter((path) => path !== "/"); expect(ownPaths.length).toBeGreaterThan(0); expect(starterPaths.some((path) => ownPaths.includes(path ?? ""))).toBe(false); expect(starterPaths).toEqual(advertised.slice(0, 3)); }); 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(["비동기 데이터 상태", "접근과 탐색 상태"]); }); });