// @vitest-environment jsdom import { render, screen, within } from "@testing-library/react"; import { MemoryRouter } from "react-router-dom"; import { describe, expect, it } from "vitest"; import type { components } from "../../../src/features/tech-log/contracts/studio/generated.ts"; import type { ResolveEvidenceAsset, ResolvePublishedLabel, } from "../../../src/features/tech-log/domain/public-render-content.ts"; import { PublicRecordRenderer } from "../../../src/features/tech-log/presentation/shared/public-render/public-record-renderer.tsx"; type RenderModel = components["schemas"]["PublicRenderModel"]; type RecordKind = RenderModel["kind"]; const base = { slug: "sample", title: "표본 기록", summary: "요약", topic: { id: "topic-kvm", label: "CPU 가상화", publicPath: "/topics/cpu" }, project: { id: "project-v", label: "가상화", publicPath: "/projects/gasanghwa" }, relations: [ { id: "relation-1", targetId: "reference-1", targetKind: "REFERENCE" as const, title: "이어지는 기준", publicPath: "/references/linked", reason: "이 기록의 결론이 그대로 이 기준이 되었다.", order: 1, }, ], renderContext: { generatedAt: "2030-01-02T00:00:00Z", dependencyRevision: "r1" }, }; /* 종류마다 하나씩 둔다. `Record` 라 종류가 늘면 컴파일러가 빈 자리를 잡는다 — 이 저장소에서 손으로 나열한 목록에 새 종류를 빠뜨리는 일이 반복됐고, 맥락 덩어리가 한 종류에서만 빠지면 그 종류로 들어온 방문자에게만 조용히 사슬이 끊긴다. */ const MODELS: Record = { CASE: { ...base, kind: "CASE", publicPath: "/cases/sample", problem: "문제", conclusion: "결론", environment: "환경", reproduction: "데이터셋", lastVerifiedOn: "2030-01-02", bodyBlocks: [], }, CONCEPT: { ...base, kind: "CONCEPT", publicPath: "/concepts/sample", basisVersion: "Linux 6.8", bodyBlocks: [], }, SETUP: { ...base, kind: "SETUP", publicPath: "/setups/sample", pinnedVersions: [{ name: "Keycloak", version: "26.7.0" }], bodyBlocks: [], }, REFERENCE: { ...base, kind: "REFERENCE", publicPath: "/references/sample", purpose: "쓰는 이유", rules: [{ id: "11111111-1111-4111-8111-111111111111", title: "기준 하나", body: "본문", order: 1 }], applyWhen: [{ id: "22222222-2222-4222-8222-222222222222", text: "적용", order: 1 }], exceptions: [], examples: [], verifiedOn: "2030-01-02", }, QUESTION: { ...base, kind: "QUESTION", publicPath: "/questions/sample", status: "OPEN", facts: [], assumptions: [], unknowns: [], constraints: [], options: [], nextValidation: "다음 검증", resolution: null, }, PROJECT_DECISION: { ...base, kind: "PROJECT_DECISION", publicPath: "/projects/gasanghwa/decisions#sample", status: "ADOPTED", decidedOn: "2030-01-02", statement: "결정", rationale: "이유", consequences: [], }, }; // 이 검사는 본문을 보지 않는다. 본문이 빈 기록이라 이 둘은 불리지 않는다. const dependencies = { resolveEvidenceAsset: (key: string) => ({ src: `/media/${key}`, width: 1, height: 1, triggerLabel: "열기", dialogLabel: "그림", }), resolvePublishedLabel: () => undefined, } satisfies { resolveEvidenceAsset: ResolveEvidenceAsset; resolvePublishedLabel: ResolvePublishedLabel; }; describe("Record는 위치와 앞뒤 탐색만 보여 준다", () => { const navigation = { previous: { label: "열린 질문", title: "앞에서 확인할 질문", path: "/questions/previous", }, next: { label: "적용 기준", title: "다음에 읽을 기준", path: "/references/next", }, } as const; for (const kind of ["CASE", "CONCEPT", "SETUP", "REFERENCE", "QUESTION"] as const) { it(`${kind} 기록이 Project / Topic / Previous / Current / Next만 rail에 보여 준다`, () => { render( , ); // 예전처럼 제목 아래에 별도 Context Path를 다시 그리지 않는다. expect(screen.queryByRole("navigation", { name: "이 기록의 맥락" })).toBeNull(); const breadcrumb = screen.getByRole("navigation", { name: "문서 경로" }); expect(breadcrumb).toHaveTextContent("가상화/CPU 가상화"); const context = screen.getByRole("navigation", { name: "읽기 맥락" }); expect(within(context).getByRole("link", { name: "가상화" })).toHaveAttribute( "href", "/projects/gasanghwa", ); expect(within(context).getByRole("link", { name: "CPU 가상화" })).toHaveAttribute( "href", "/topics/cpu", ); expect(within(context).getByRole("link", { name: /앞에서 확인할 질문/ })).toHaveAttribute( "href", "/questions/previous", ); expect(within(context).getByText(/Current/)).toBeInTheDocument(); expect(within(context).getByRole("link", { name: /다음에 읽을 기준/ })).toHaveAttribute( "href", "/references/next", ); }); } it("Project Decision도 본문 위에 별도 Context Path를 만들지 않는다", () => { render( , ); expect(screen.queryByRole("navigation", { name: "이 기록의 맥락" })).toBeNull(); }); });