// @vitest-environment jsdom import { act, render, screen, waitFor, within } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import { composeContractContributions, type ComposedContractContributions, } from "../../src/contracts/external-contract-runtime.ts"; import { unvalidatedPayload } from "../../src/contracts/unvalidated-payload.ts"; import { SERVER_STATE_PROFILES } from "../../src/contracts/server-state.ts"; import { COMPOSED_CONTRACT_CONTRIBUTIONS } from "../../src/features/loaded-feature-runtimes.ts"; import { ROUTE_REGISTRY } from "../../src/features/installed-feature-contracts.ts"; import { PlatformOverviewPage } from "../../src/presentation/examples/platform-overview-page.tsx"; import { LocaleProvider } from "../../src/presentation/i18n/index.ts"; import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx"; import { createTestApplication } from "../helpers/create-test-application.ts"; import { TEST_CONTRACT_CONTRIBUTION } from "../helpers/external-contract-fixture.ts"; import { createRuntimeCapabilitiesStub } from "../helpers/runtime-capabilities-stub.ts"; /** * A starter screen (0929/10-02): a product that replaces `/examples/platform` * deletes this file with it. Platform tests use the test-only feature's pages. * * The page must stay a projection of the installed registries. Every assertion * below derives its expectation from the same registry the page reads, so a * template that removes its sample feature still satisfies this suite. */ /** * 1103/15-01. The contract tables wait for the features' runtime halves * behind their own Suspense boundary; `act` lets the given promise settle. */ async function renderPage( options: Readonly<{ application?: ReturnType; contracts?: ComposedContractContributions; }> = {}, ) { await act(async () => { render( , ); }); } function tableByCaption(caption: string): HTMLElement { return screen.getByRole("table", { name: caption }); } /** A metric is a `dt`/`dd` pair, which carries no ARIA role to query by. */ function metricByLabel(scope: HTMLElement, label: string): HTMLElement { const term = within(scope).getByText(label).closest(".platform-metric"); if (!(term instanceof HTMLElement)) { throw new Error(`No metric is labelled ${label}`); } return term; } describe("platform overview page", () => { it("renders one route row per installed route registry entry", async () => { await renderPage(); const table = tableByCaption("설치된 라우트 목록"); const dataRows = within(table).getAllByRole("row").slice(1); expect(dataRows).toHaveLength(Object.keys(ROUTE_REGISTRY).length); for (const definition of Object.values(ROUTE_REGISTRY)) { expect( within(table).getByText(definition.routeId), ).toBeInTheDocument(); } }); it("renders one operation row per installed HTTP contract", async () => { const operationIds = [ ...COMPOSED_CONTRACT_CONTRIBUTIONS.httpByOperationId.keys(), ]; await renderPage(); if (operationIds.length === 0) { expect( screen.getByRole("heading", { name: "설치된 HTTP 오퍼레이션이 없습니다.", }), ).toBeVisible(); return; } const table = tableByCaption("설치된 HTTP 오퍼레이션"); expect(within(table).getAllByRole("row").slice(1)).toHaveLength( operationIds.length, ); for (const operationId of operationIds) { expect(within(table).getByText(operationId)).toBeInTheDocument(); } }); // 1101/07-03. A skipped validation is shown, not just composed. it("lists the operations that skip runtime validation, with the reason", async () => { const [listRow, ...rest] = TEST_CONTRACT_CONTRIBUTION.http; const contracts = composeContractContributions([ Object.freeze({ ...TEST_CONTRACT_CONTRIBUTION, http: Object.freeze([ { ...listRow!, contract: { ...listRow!.contract, outputValidator: unvalidatedPayload( "TestEntityListPayload", "typed by the package", ), }, }, ...rest, ]), }), ]); await renderPage({ contracts }); const table = tableByCaption("런타임 검증을 생략한 계약"); const [row, ...others] = within(table).getAllByRole("row").slice(1); expect(others).toHaveLength(0); expect(within(row!).getByText("TEST_LIST_ENTITIES")).toBeVisible(); expect(within(row!).getByText("typed by the package")).toBeVisible(); }); it("shows no skipped-validation list when every operation validates", async () => { await renderPage(); expect( screen.queryByRole("table", { name: "런타임 검증을 생략한 계약" }), ).toBeNull(); }); it("renders every fixed server-state profile with its own budget", async () => { await renderPage(); const table = tableByCaption("서버 상태 프로파일"); for (const profile of Object.values(SERVER_STATE_PROFILES)) { expect(within(table).getByText(profile.profileId)).toBeInTheDocument(); } expect(within(table).getAllByRole("row").slice(1)).toHaveLength( Object.keys(SERVER_STATE_PROFILES).length, ); }); it("labels a capability that was never selected as unselected", async () => { await renderPage(); const region = screen.getByRole("region", { name: "선택적 런타임 능력" }); expect(within(region).getAllByText("미선택")).toHaveLength(4); expect(within(region).queryByText("운영자가 비활성화함")).toBeNull(); }); it("separates an operator disable from a capability that was never selected", async () => { await renderPage({ application: createTestApplication({ runtimeCapabilities: createRuntimeCapabilitiesStub({ SERVICE_WORKER: { selected: 1, active: 0, override: "DISABLED" }, OFFLINE_COMMANDS: { selected: 1, active: 1 }, }), }), }); const region = screen.getByRole("region", { name: "선택적 런타임 능력" }); expect(within(region).getByText("운영자가 비활성화함")).toBeVisible(); expect(within(region).getByText("활성 (1)")).toBeVisible(); expect(within(region).getAllByText("미선택")).toHaveLength(2); }); it("counts installed contract packages separately from template fixtures", async () => { const fixtures = COMPOSED_CONTRACT_CONTRIBUTIONS.contributions.filter( (contribution) => contribution.source.kind === "TEMPLATE_FIXTURE", ).length; await renderPage(); const summary = screen.getByRole("region", { name: "설치 요약" }); const packages = metricByLabel(summary, "외부 계약 패키지"); expect( within(packages).getByText( `${COMPOSED_CONTRACT_CONTRIBUTIONS.externalPackages.length}개`, ), ).toBeVisible(); expect( within(packages).getByText(`템플릿 픽스처 ${fixtures}개`), ).toBeVisible(); expect( within(metricByLabel(summary, "라우트")).getByText( `${Object.keys(ROUTE_REGISTRY).length}개`, ), ).toBeVisible(); }); it("renders the verified release identity once the runtime resolves it", async () => { await renderPage(); const region = screen.getByRole("region", { name: "릴리스 신원" }); await waitFor(() => expect( within(metricByLabel(region, "빌드")).getByText("test-build"), ).toBeVisible(), ); expect( within(metricByLabel(region, "릴리스")).getByText("test-release"), ).toBeVisible(); }); it("stops the release metrics from loading forever", async () => { await renderPage({ application: createTestApplication({ releaseInfo: { getCurrent: async () => { throw new Error("manifest unavailable"); }, refresh: async () => { throw new Error("manifest unavailable"); }, }, }), }); const region = screen.getByRole("region", { name: "릴리스 신원" }); await waitFor(() => expect( within(metricByLabel(region, "빌드")).getByText("확인하지 못했습니다."), ).toBeVisible(), ); expect(within(region).queryByText("확인하고 있습니다.")).not.toBeInTheDocument(); }); /** * 1105/15-01. The release metrics drew one "상태" card until the summary * resolved, then four cards with hint lines: the grid grew by a hint line * about 30-100 ms after the title and pushed the rest of the page 21 px * (CLS 0.0046 on a direct visit). The cards and their hint lines are the * same in every state; only the values change. */ it("keeps the release metrics' cards and hint lines while the summary loads", async () => { const summary = { buildId: "test-build", releaseId: "test-release", configSchemaVersion: "1", apiContractVersion: "1", assetManifestHash: "test-hash", routeChunks: { "route-home": "assets/home.js" }, }; let resolve: (value: typeof summary) => void = () => {}; const pending = new Promise((settle) => { resolve = settle; }); await renderPage({ application: createTestApplication({ releaseInfo: { getCurrent: () => pending, refresh: () => pending }, }), }); const region = screen.getByRole("region", { name: "릴리스 신원" }); const shape = () => [...region.querySelectorAll(".platform-metric")].map((card) => [ card.querySelector("dt")?.textContent, card.querySelector(".platform-metric__hint") !== null, ]); const loading = shape(); expect(within(metricByLabel(region, "빌드")).getByText("확인하고 있습니다.")).toBeVisible(); expect(region.querySelector("dl")).toHaveAttribute("aria-busy", "true"); await act(async () => { resolve(summary); await pending; }); await waitFor(() => expect(within(metricByLabel(region, "빌드")).getByText("test-build")).toBeVisible(), ); expect(loading).toEqual([ ["빌드", false], ["릴리스", false], ["설정 스키마", true], ["계약 집합 다이제스트", true], ]); expect(shape()).toEqual(loading); expect(region.querySelector("dl")).toHaveAttribute("aria-busy", "false"); }); });