`~/Desktop/tech-log-frontend` 가 세 번 더 고쳐져 있었다. 소스 열셋이 바뀌고 둘이
새로 생겼다(`markdown-block-editor`, `catalog-property-picker`). 검사 넷도 함께 바뀌었다.
기능이 바뀐 것부터 적는다.
**편집기에서 즉시 미리보기가 빠졌다.** v2 에서 「편집/나란히/미리보기」 모드가 생겼고,
v4 가 그 모드 자체를 없앴다 — 글 쓰는 화면은 하나이고 공개 렌더는 편집기의 두 번째
상태가 아니라는 판단이다. 직전 리뷰의 완료 조건 하나("preview 는 Desktop/Mobile 을
실제로 전환할 수 있다")가 이로써 다시 미적용이 된다. `InstantPreview` 는 파일로 남아
있으나 편집기 어디서도 부르지 않는다.
**본문이 textarea 에서 블록 편집기로 바뀌었다.** 기존 markdown 을 문단·제목·목록·인용·
코드·구분선·raw 로 읽고 같은 `bodyMarkdown` 계약으로 되돌려 쓴다. 읽었다가 그대로 다시
쓰는 왕복이 글을 바꾸면 작성자가 문서를 열어 저장하기만 해도 내용이 상하므로, 이
저장소가 실제로 쓰는 문법(앵커 단 소제목, 이름표 단 코드 울타리, `:::evidence`, 표,
인용, 목록, 구분선)을 하나씩 넣어 왕복을 검사로 고정했다. 빈 줄이 겹친 자리만 한 줄로
접히고 글자는 그대로다 — 그 예외도 검사에 적었다.
Project·Topic 이 검색 가능한 고르개로, 상태가 인라인 알약으로 바뀌었고, 메타데이터는
접히는 속성 면으로 내려갔다.
`useImperativeHandle` 안에서 부르는 `commit` 이 렌더마다 새로 만들어져 lint 가 막았다.
`useCallback` 으로 고정했다 — 바뀌는 것은 `onChange` 하나다.
Node 24 로 게이트 재실행: check:types · lint · test:unit(1829) · test:component(152) ·
test:tech-log(432) 전부 통과.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015c8cBFUaVr7KLVUx6ujz7D
295 lines
15 KiB
TypeScript
295 lines
15 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { fireEvent, render, screen, waitFor, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import type { ReactNode } from "react";
|
|
import { MemoryRouter } from "react-router-dom";
|
|
import { afterEach, describe, expect, it, vi } 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 { DocumentEditorScreen } from "../../../src/features/tech-log/presentation/studio/components/document-editor-screen.tsx";
|
|
import { StudioProvider } from "../../../src/features/tech-log/presentation/studio/studio-provider.tsx";
|
|
import { createManagementGatewayStub } from "../../helpers/management-gateway-stub.ts";
|
|
|
|
afterEach(() => vi.restoreAllMocks());
|
|
|
|
function renderEditor(
|
|
documentId: string,
|
|
gateway: StudioGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway(),
|
|
) {
|
|
// CASE editors mount the Asset Picker (Task 10), which uses the throwing
|
|
// `useStudioAssetGateway()` accessor -- a test harness that renders it must
|
|
// supply `createAssetGateway`, the same as `StudioShell` always does.
|
|
const assetGateway = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT)
|
|
.input.createStudioAssetGateway();
|
|
return render(
|
|
<MemoryRouter initialEntries={[`/studio/documents/${documentId}/edit`]}>
|
|
<StudioProvider
|
|
createManagementGateway={createManagementGatewayStub} createGateway={() => gateway} createAssetGateway={() => assetGateway}>
|
|
<DocumentEditorScreen documentId={documentId} />
|
|
</StudioProvider>
|
|
</MemoryRouter>,
|
|
);
|
|
}
|
|
|
|
function labelsIn(container: HTMLElement, selector: string): string[] {
|
|
return Array.from(
|
|
container.querySelectorAll<HTMLElement>(selector),
|
|
// 칸 이름은 보통 `<label><span>이름</span>` 이지만, 요약처럼 label 을 htmlFor 로 잇는
|
|
// 칸도 있다 — 두 모양 다 같은 이름 목록에 실려야 순서를 볼 수 있다.
|
|
(field) => field.querySelector(":scope > span, :scope > label")?.textContent ?? "",
|
|
);
|
|
}
|
|
|
|
function markdownSource(container: HTMLElement): HTMLTextAreaElement {
|
|
const source = container.querySelector<HTMLTextAreaElement>(".studio-markdown-source");
|
|
if (!source) throw new Error("single-surface Markdown source not found");
|
|
return source;
|
|
}
|
|
|
|
describe("TechLog Studio document editor", () => {
|
|
it("loads the Case as one document surface and owns dirty state without an editor preview mode", async () => {
|
|
const user = userEvent.setup();
|
|
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
|
const calls = { save: 0, validate: 0, preview: 0, publish: 0 };
|
|
const gateway = {
|
|
...base,
|
|
saveDocument(...args: Parameters<StudioGateway["saveDocument"]>) {
|
|
calls.save += 1;
|
|
return base.saveDocument(...args);
|
|
},
|
|
validateDocument(...args: Parameters<StudioGateway["validateDocument"]>) {
|
|
calls.validate += 1;
|
|
return base.validateDocument(...args);
|
|
},
|
|
createPreview(...args: Parameters<StudioGateway["createPreview"]>) {
|
|
calls.preview += 1;
|
|
return base.createPreview(...args);
|
|
},
|
|
publishDocument(...args: Parameters<StudioGateway["publishDocument"]>) {
|
|
calls.publish += 1;
|
|
return base.publishDocument(...args);
|
|
},
|
|
} satisfies StudioGateway;
|
|
const view = renderEditor(FIXTURE_IDS.redisAdapterCase, gateway);
|
|
|
|
expect(await screen.findByLabelText("제목")).toHaveValue(
|
|
"Redis Adapter가 도메인 TTL 정책을 소유하지 않는 이유",
|
|
);
|
|
expect(screen.getByLabelText("slug")).toHaveValue("redis-adapter-ttl-boundary");
|
|
expect(screen.getByLabelText("요약")).toHaveValue(
|
|
"만료 정책과 명령 실행 책임을 분리했습니다.",
|
|
);
|
|
expect(screen.getByLabelText("Topic")).toHaveTextContent("Redis");
|
|
expect(screen.getByLabelText("Project")).toHaveTextContent("Backend Skeleton");
|
|
// The common metadata remains a compact property surface. Record-specific
|
|
// content is no longer represented as a stack of `.studio-field` form rows.
|
|
expect(labelsIn(view.container, ".studio-field")).toEqual([
|
|
"제목",
|
|
"요약",
|
|
"프로젝트",
|
|
"주제",
|
|
"URL 이름",
|
|
]);
|
|
expect(screen.getByLabelText("문제")).toHaveValue("저장 기술이 정책을 소유했습니다.");
|
|
expect(markdownSource(view.container)).toHaveValue(
|
|
"## 책임 경계\n\n정책과 명령을 분리합니다.",
|
|
);
|
|
expect(screen.getByLabelText("1번째 제목 2")).toHaveValue("책임 경계");
|
|
expect(screen.getByLabelText("2번째 텍스트")).toHaveValue("정책과 명령을 분리합니다.");
|
|
expect(screen.getByRole("status", { name: "편집 상태" })).toHaveTextContent("저장됨");
|
|
|
|
await user.clear(screen.getByLabelText("제목"));
|
|
await user.type(screen.getByLabelText("제목"), "편집한 Redis 경계");
|
|
expect(screen.getByRole("status", { name: "편집 상태" })).toHaveTextContent(
|
|
"저장되지 않음",
|
|
);
|
|
|
|
// Version/kind belong to the document identity, while the command bar has
|
|
// only the two real author actions. There is no edit/split/preview state.
|
|
expect(screen.getByLabelText("현재 문서")).toHaveTextContent("CASE·v4");
|
|
const rail = screen.getByRole("complementary", { name: "작업 상태" });
|
|
expect(within(rail).getAllByRole("button").map((button) => button.textContent)).toEqual([
|
|
"저장",
|
|
"게시",
|
|
]);
|
|
expect(within(rail).queryAllByRole("link")).toHaveLength(0);
|
|
expect(screen.getByRole("main", { name: "문서 편집" })).toBeVisible();
|
|
expect(screen.queryByRole("button", { name: "편집" })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "나란히" })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("button", { name: "미리보기" })).not.toBeInTheDocument();
|
|
expect(screen.queryByRole("region", { name: "즉시 미리보기" })).not.toBeInTheDocument();
|
|
expect(screen.getByLabelText("제목")).toHaveValue("편집한 Redis 경계");
|
|
expect(calls).toEqual({ save: 0, validate: 0, preview: 0, publish: 0 });
|
|
});
|
|
|
|
it("adds, reorders, and removes relations with source accessibility names", async () => {
|
|
const user = userEvent.setup();
|
|
renderEditor(FIXTURE_IDS.redisAdapterCase);
|
|
await screen.findByLabelText("제목");
|
|
|
|
await user.click(screen.getByRole("button", { name: "관계 추가" }));
|
|
await user.click(screen.getByRole("button", { name: "관계 추가" }));
|
|
await user.selectOptions(
|
|
screen.getByLabelText("관계 1 대상"),
|
|
FIXTURE_IDS.fetchJoinCase,
|
|
);
|
|
await user.type(screen.getByLabelText("관계 1 이유"), "첫 번째 근거");
|
|
await user.selectOptions(
|
|
screen.getByLabelText("관계 2 대상"),
|
|
FIXTURE_IDS.stateNonceReference,
|
|
);
|
|
await user.type(screen.getByLabelText("관계 2 이유"), "두 번째 근거");
|
|
|
|
const relationRows = screen.getAllByLabelText(/관계 \d 대상/).map((select) =>
|
|
select.closest(".studio-relation-item") as HTMLElement,
|
|
);
|
|
await user.click(within(relationRows[1]!).getByRole("button", { name: "위로" }));
|
|
expect(screen.getByLabelText("관계 1 대상")).toHaveValue(
|
|
FIXTURE_IDS.stateNonceReference,
|
|
);
|
|
expect(screen.getByLabelText("관계 1 이유")).toHaveValue("두 번째 근거");
|
|
|
|
const firstRow = screen.getByLabelText("관계 1 대상").closest(
|
|
".studio-relation-item",
|
|
) as HTMLElement;
|
|
await user.click(within(firstRow).getByRole("button", { name: "삭제" }));
|
|
expect(screen.getByLabelText("관계 1 대상")).toHaveValue(FIXTURE_IDS.fetchJoinCase);
|
|
expect(screen.queryByLabelText("관계 2 대상")).not.toBeInTheDocument();
|
|
});
|
|
|
|
it("preserves Reference loaded values and ordered rule/text-list behavior", async () => {
|
|
const user = userEvent.setup();
|
|
renderEditor(FIXTURE_IDS.stateNonceReference);
|
|
|
|
/*
|
|
에디터 라벨이 공개 화면의 절 제목과 같아졌으므로(작성자가 매핑을 외우지 않도록), 미리보기의
|
|
`<section aria-labelledby>` 와 이름이 겹친다. 여기서 보려는 것은 입력 칸이다.
|
|
*/
|
|
expect(
|
|
await screen.findByRole("textbox", { name: "이 기준을 쓰는 이유" }),
|
|
).toHaveValue(
|
|
"각 검증값의 책임을 다시 찾는 기준입니다.",
|
|
);
|
|
expect(screen.getByLabelText("판단 기준 1 제목")).toHaveValue("state는 요청을 연결합니다");
|
|
expect(screen.getByLabelText("적용할 때 1")).toHaveValue("Code Flow를 구성할 때");
|
|
expect(screen.getByLabelText("마지막 검증일")).toHaveValue("2026-08-13");
|
|
expect(screen.getByText("아직 입력한 항목이 없습니다.")).toBeVisible();
|
|
|
|
await user.click(screen.getByRole("button", { name: "판단 기준 추가" }));
|
|
await user.type(screen.getByLabelText("판단 기준 2 제목"), "nonce는 Token을 연결합니다");
|
|
const secondRule = screen.getByLabelText("판단 기준 2 제목").closest(
|
|
".studio-ordered-item",
|
|
) as HTMLElement;
|
|
await user.click(within(secondRule).getByRole("button", { name: "위로" }));
|
|
expect(screen.getByLabelText("판단 기준 1 제목")).toHaveValue(
|
|
"nonce는 Token을 연결합니다",
|
|
);
|
|
await user.click(
|
|
within(
|
|
screen.getByLabelText("판단 기준 1 제목").closest(".studio-ordered-item") as HTMLElement,
|
|
).getByRole("button", { name: "삭제" }),
|
|
);
|
|
expect(screen.getByLabelText("판단 기준 1 제목")).toHaveValue("state는 요청을 연결합니다");
|
|
|
|
await user.click(screen.getByRole("button", { name: "적용할 때 추가" }));
|
|
await user.type(screen.getByLabelText("적용할 때 2"), "두 번째 적용 조건");
|
|
const secondApplyWhen = screen.getByLabelText("적용할 때 2").closest(
|
|
".studio-ordered-item",
|
|
) as HTMLElement;
|
|
await user.click(within(secondApplyWhen).getByRole("button", { name: "위로" }));
|
|
expect(screen.getByLabelText("적용할 때 1")).toHaveValue("두 번째 적용 조건");
|
|
await user.click(
|
|
within(
|
|
screen.getByLabelText("적용할 때 1").closest(".studio-ordered-item") as HTMLElement,
|
|
).getByRole("button", { name: "삭제" }),
|
|
);
|
|
expect(screen.getByLabelText("적용할 때 1")).toHaveValue("Code Flow를 구성할 때");
|
|
expect(screen.getByRole("status", { name: "편집 상태" })).toHaveTextContent(
|
|
"저장되지 않음",
|
|
);
|
|
});
|
|
|
|
it("preserves Question field differences, list controls, and conditional resolution fields", async () => {
|
|
const user = userEvent.setup();
|
|
renderEditor(FIXTURE_IDS.edgeTokenQuestion);
|
|
|
|
const questionStatus = await screen.findByRole("group", { name: "질문 상태" });
|
|
expect(within(questionStatus).getByRole("button", { name: "OPEN" })).toHaveAttribute("aria-pressed", "true");
|
|
expect(screen.getByLabelText("남은 미지수 1")).toHaveValue("신뢰 헤더 위조 가능성");
|
|
expect(screen.getByRole("textbox", { name: "다음 검증" })).toHaveValue(
|
|
"위협 모델을 비교합니다.",
|
|
);
|
|
expect(screen.queryByLabelText("해결 요약")).not.toBeInTheDocument();
|
|
|
|
await user.click(screen.getByRole("button", { name: "확인한 사실 추가" }));
|
|
await user.type(screen.getByLabelText("확인한 사실 1"), "Edge가 서명을 검증합니다");
|
|
await user.click(screen.getByRole("button", { name: "선택지 추가" }));
|
|
expect(screen.getByLabelText("선택지 1 제목")).toHaveValue("");
|
|
expect(screen.getByLabelText("선택지 1 설명")).toHaveValue("");
|
|
|
|
await user.click(within(questionStatus).getByRole("button", { name: "RESOLVED" }));
|
|
expect(screen.getByLabelText("해결 요약")).toHaveValue("");
|
|
expect(screen.getByLabelText("해결 근거")).toHaveTextContent("근거 선택");
|
|
expect(screen.getByLabelText("근거 링크 문구")).toHaveValue("");
|
|
expect(screen.getByRole("status", { name: "편집 상태" })).toHaveTextContent(
|
|
"저장되지 않음",
|
|
);
|
|
});
|
|
|
|
it("shows how much of the summary limit is left and keeps that limit at the contract's", async () => {
|
|
renderEditor(FIXTURE_IDS.edgeTokenQuestion);
|
|
|
|
const summary = await screen.findByLabelText("요약");
|
|
/*
|
|
계약 WorkingCopyInputBase.summary 와 같은 값이어야 한다. 300 이던 시절 이 칸은 문장
|
|
중간에서 말없이 입력을 멈췄고, 쓰는 사람에게는 키보드가 고장 난 것처럼 보였다.
|
|
*/
|
|
expect(summary).toHaveAttribute("maxlength", "2000");
|
|
// 목록 카드는 요약을 세 줄에서 자른다 — 작성자에게 그 경계를 알린다.
|
|
expect(screen.getByText(/목록 카드에는 약 90자까지 보입니다/u)).toBeInTheDocument();
|
|
|
|
fireEvent.change(summary, { target: { value: "가".repeat(412) } });
|
|
expect(screen.getByText(/412 \/ 2000/u)).toBeInTheDocument();
|
|
expect(
|
|
screen.queryByText(/2000자까지 모두 썼습니다/),
|
|
).not.toBeInTheDocument();
|
|
|
|
fireEvent.change(summary, { target: { value: "가".repeat(2000) } });
|
|
expect(screen.getByText(/2000 \/ 2000/u)).toBeInTheDocument();
|
|
// 한계에 닿았을 때만 알린다 — 글자마다 읽어 주면 받아쓰기가 된다.
|
|
expect(screen.getByText(/2000자까지 모두 썼습니다/)).toBeInTheDocument();
|
|
|
|
// 글자 수는 칸의 이름에 섞이지 않아야 한다. 섞이면 이름이 타자마다 바뀐다.
|
|
expect(screen.getByLabelText("요약")).toBe(summary);
|
|
});
|
|
|
|
it("renders source not-found and retry surfaces for document loading", async () => {
|
|
const unknown = renderEditor("aaaaaaaa-aaaa-4aaa-8aaa-aaaaaaaaaaaa");
|
|
expect(
|
|
await screen.findByRole("heading", { name: "Studio 화면을 찾을 수 없습니다" }),
|
|
).toBeVisible();
|
|
expect(screen.getByRole("link", { name: "작업본으로 돌아가기" })).toHaveAttribute(
|
|
"href",
|
|
"/studio/documents",
|
|
);
|
|
unknown.unmount();
|
|
|
|
const base = createTechLogFeatureInstalledInput(MOCK_STUDIO_INSTALL_CONTEXT).input.createStudioGateway();
|
|
const getDocument = vi
|
|
.fn<StudioGateway["getDocument"]>()
|
|
.mockRejectedValueOnce(new Error("offline"))
|
|
.mockImplementation((id, options) => base.getDocument(id, options));
|
|
renderEditor(FIXTURE_IDS.redisAdapterCase, { ...base, getDocument });
|
|
expect(await screen.findByRole("alert")).toHaveTextContent(
|
|
"문서를 불러오지 못했습니다offline",
|
|
);
|
|
fireEvent.click(screen.getByRole("button", { name: "다시 시도" }));
|
|
await waitFor(() => expect(screen.getByLabelText("제목")).toBeVisible());
|
|
expect(getDocument).toHaveBeenCalledTimes(2);
|
|
});
|
|
});
|