Files
tech-log-frontend/tests/features/tech-log/studio-decision-authoring.test.tsx
T
DongHyeonkaandClaude Opus 5 fe1f23520e feat: 기록마다 이 조사의 어디쯤인지를 제목 아래에 세운다
이 사이트의 차별점은 "기록 하나에 아무 데서나 들어와도 그 결론을 만든 맥락의 사슬을
잃지 않는다"는 것이다. 그런데 그 사슬이 화면에서는 제목 위 얇은 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
2026-09-15 20:03:01 +09:00

189 lines
7.7 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import type { ReactNode } from "react";
import { MemoryRouter, useLocation, useNavigate } from "react-router-dom";
import { describe, expect, it } from "vitest";
import { createTechLogFeatureInstalledInput } from "../../../src/features/tech-log/adapters/create-tech-log-feature-input.ts";
import { MOCK_STUDIO_INSTALL_CONTEXT } from "../../helpers/studio-install-context.ts";
import { FIXTURE_IDS } from "../../../src/features/tech-log/adapters/mock/fixtures.ts";
import type { StudioGateway } from "../../../src/features/tech-log/application/ports/studio-gateway.ts";
import type { WorkingCopyInput } from "../../../src/features/tech-log/contracts/studio/contract.ts";
import { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
import { NewDocumentForm } from "../../../src/features/tech-log/presentation/studio/components/new-document-form.tsx";
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
type DecisionInput = Extract<WorkingCopyInput, { kind: "PROJECT_DECISION" }>;
function decisionInput(): DecisionInput {
return {
kind: "PROJECT_DECISION",
title: "목록 페이징과 컬렉션 로딩을 분리합니다",
slug: "feed-pagination-boundary",
summary: "부모 페이지를 먼저 고정하고 연관 컬렉션을 별도로 조회합니다.",
topicId: FIXTURE_IDS.topicJpa,
projectId: FIXTURE_IDS.projectBackend,
relations: [
{
id: null,
targetId: FIXTURE_IDS.fetchJoinCase,
reason: "판단 근거",
order: 0,
},
],
decisionStatus: "ADOPTED",
decidedOn: "2026-08-11",
statement: "목록 조회와 컬렉션 로딩을 서로 다른 단계로 수행합니다.",
rationale: "Fetch Join이 DB LIMIT를 제거하는 문제를 피합니다.",
consequences: [
{
id: "99999999-9999-4999-8999-999999999991",
text: "목록 조회는 한 번의 SQL로 끝나지 않습니다.",
order: 0,
},
],
};
}
function RouterStudioProvider({
gateway,
children,
}: Readonly<{ gateway: StudioGateway; children: ReactNode }>) {
const navigate = useNavigate();
return (
<StudioProvider
createManagementGateway={createManagementGatewayStub}
createGateway={() => gateway}
navigate={(href) => { void navigate(href); }}
>
{children}
</StudioProvider>
);
}
function LocationProbe() {
return <output aria-label="현재 경로">{useLocation().pathname}</output>;
}
describe("TechLog Studio project decision authoring", () => {
it("creates Decision as the fourth working-copy type", async () => {
const user = userEvent.setup();
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
render(
<MemoryRouter initialEntries={["/studio/documents/new"]}>
<RouterStudioProvider gateway={gateway}>
<NewDocumentForm />
<LocationProbe />
</RouterStudioProvider>
</MemoryRouter>,
);
await user.click(screen.getByRole("radio", { name: /설계 결정/ }));
await user.click(screen.getByRole("button", { name: "작업본 만들기" }));
await waitFor(() => {
expect(screen.getByLabelText("현재 경로")).toHaveTextContent(
/^\/studio\/documents\/[0-9a-f-]+\/edit$/,
);
});
expect((await gateway.listDocuments({ kind: "PROJECT_DECISION" })).items)
.toHaveLength(1);
});
it("validates, previews, and publishes a project-scoped Decision", async () => {
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
const document = await gateway.createDocument(decisionInput(), {
idempotencyKey: "create-project-decision",
});
const validation = await gateway.validateDocument(
document.id,
{ expectedVersion: document.version },
{ idempotencyKey: "validate-project-decision" },
);
expect(validation).toMatchObject({ status: "VALID", issues: [] });
const preview = await gateway.createPreview(
document.id,
{
expectedVersion: document.version,
validationId: validation.validationId,
},
{ idempotencyKey: "preview-project-decision" },
);
expect(preview.renderModel).toMatchObject({
kind: "PROJECT_DECISION",
status: "ADOPTED",
publicPath: "/projects/backend-skeleton/decisions#feed-pagination-boundary",
});
const published = await gateway.publishDocument(
document.id,
{
expectedVersion: document.version,
validationId: validation.validationId,
previewId: preview.previewId,
acknowledgedWarningCodes: [],
},
{ idempotencyKey: "publish-project-decision" },
);
expect(published.publication.publicPath).toBe(
"/projects/backend-skeleton/decisions#feed-pagination-boundary",
);
});
it("edits Decision fields and renders the project decision card preview", async () => {
const user = userEvent.setup();
const gateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
const document = await gateway.createDocument(decisionInput(), {
idempotencyKey: "edit-project-decision",
});
render(
<MemoryRouter initialEntries={[`/studio/documents/${document.id}/edit`]}>
<StudioProvider
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway}>
<DocumentEditorScreen documentId={document.id} />
</StudioProvider>
</MemoryRouter>,
);
expect(await screen.findByLabelText("결정 상태")).toHaveValue("ADOPTED");
expect(screen.getByLabelText("결정일")).toHaveValue("2026-08-11");
expect(screen.getByLabelText("결정문")).toHaveValue(
"목록 조회와 컬렉션 로딩을 서로 다른 단계로 수행합니다.",
);
expect(screen.getByLabelText("판단 이유")).toHaveValue(
"Fetch Join이 DB LIMIT를 제거하는 문제를 피합니다.",
);
expect(screen.getByLabelText("영향 1")).toHaveValue(
"목록 조회는 한 번의 SQL로 끝나지 않습니다.",
);
expect(screen.getByLabelText("근거 1 대상")).toHaveValue(
FIXTURE_IDS.fetchJoinCase,
);
expect(screen.getByRole("complementary", { name: "작업 상태" }))
.toHaveTextContent("종류설계 결정");
const preview = screen.getByRole("region", { name: "즉시 미리보기" });
expect(
within(preview).getByRole("heading", {
name: "목록 페이징과 컬렉션 로딩을 분리합니다",
}),
).toBeVisible();
expect(within(preview).getByText("판단 이유")).toBeVisible();
expect(within(preview).getByText("영향")).toBeVisible();
expect(within(preview).getByText("근거 기록")).toBeVisible();
/*
같은 기록이 화면에 두 번 나온다 — 위쪽 「이 기록의 맥락」이 이 결정이 어느 조사에 속하는지
보여 주고, 아래 「근거 기록」이 그 결정을 뒷받침한 기록을 다시 세운다. 목차가 본문의 제목을
다시 적는 것과 같은 중복이므로, 확인은 근거 목록 안으로 좁힌다.
*/
const evidence = within(preview).getByText("근거 기록").closest("section")!;
expect(within(evidence as HTMLElement).getByRole("link", {
name: "컬렉션 Fetch Join과 페이징은 왜 충돌하는가",
})).toHaveAttribute("href", "/cases/collection-fetch-join-pagination");
});
});