이 사이트의 차별점은 "기록 하나에 아무 데서나 들어와도 그 결론을 만든 맥락의 사슬을 잃지 않는다"는 것이다. 그런데 그 사슬이 화면에서는 제목 위 얇은 breadcrumb 한 줄과 문서 맨 아래 「다음에 읽을 것」으로만 표현돼 있었다 — 검색으로 Case 하나에 들어온 사람은 바닥까지 내려가야 이 기록이 어느 프로젝트의 어느 질문에서 나왔는지 알 수 있었다. 저장은 되어 있는데 겪게 되지는 않는 상태였다. 제목·요약 바로 아래에 맥락을 하나의 덩어리로 세운다. 프로젝트 → 주제로 올라가는 길과, 같은 조사 안에서 이웃한 기록들을 함께 보인다. 이웃에는 작성자가 그 관계에 남긴 문장을 붙인다 — 「다음에 무엇을」보다 「왜 그것을」이 먼저 있어야 목록이 아니라 사슬로 읽힌다. 지금 보는 기록도 목록에 남겨 자기 자리가 보이게 한다. 여섯 종류 전부에 들어간다. 종류마다 하나씩 픽스처를 둔 `Record<RecordKind, …>` 검사로 막았다 — 한 종류에서만 빠지면 그 종류로 들어온 방문자에게만 조용히 사슬이 끊긴다. Question 에서 빼 보고 그 검사만 실패하는 것을 확인했다. 화면 촬영기(`scripts/capture-screens.ts`)도 함께 넣는다. 라우트 레지스트리를 돌며 공개·Studio 전 화면을 찍는다. 찍을 목록을 손으로 적지 않고 `Record<RouteId, …>` 로 두어 라우트가 늘면 컴파일러가 빈 자리를 잡는다. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_015c8cBFUaVr7KLVUx6ujz7D
165 lines
5.3 KiB
TypeScript
165 lines
5.3 KiB
TypeScript
// @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<RecordKind, …>` 라 종류가 늘면 컴파일러가 빈 자리를 잡는다 —
|
|
이 저장소에서 손으로 나열한 목록에 새 종류를 빠뜨리는 일이 반복됐고, 맥락 덩어리가 한 종류에서만
|
|
빠지면 그 종류로 들어온 방문자에게만 조용히 사슬이 끊긴다.
|
|
*/
|
|
const MODELS: Record<RecordKind, RenderModel> = {
|
|
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("기록마다 맥락이 제목 바로 아래에 있다", () => {
|
|
for (const [kind, model] of Object.entries(MODELS)) {
|
|
it(`${kind} 기록이 프로젝트·주제·이웃 기록을 함께 보여 준다`, () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<PublicRecordRenderer {...dependencies} model={model} />
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
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: "이어지는 기준" })).toBeInTheDocument();
|
|
expect(
|
|
within(context).getByText("이 기록의 결론이 그대로 이 기준이 되었다."),
|
|
).toBeInTheDocument();
|
|
// 지금 보는 기록도 목록에 있어야 "내가 그중 어디인가"가 보인다.
|
|
expect(within(context).getByText("지금 읽는 기록")).toBeInTheDocument();
|
|
});
|
|
}
|
|
|
|
it("올라갈 곳도 옆으로 갈 곳도 없으면 빈 상자를 남기지 않는다", () => {
|
|
render(
|
|
<MemoryRouter>
|
|
<PublicRecordRenderer
|
|
{...dependencies}
|
|
model={{
|
|
...MODELS.CONCEPT,
|
|
topic: { id: "t", label: "", publicPath: null },
|
|
project: null,
|
|
relations: [],
|
|
}}
|
|
/>
|
|
</MemoryRouter>,
|
|
);
|
|
|
|
expect(screen.queryByRole("navigation", { name: "이 기록의 맥락" })).toBeNull();
|
|
});
|
|
});
|