Files
tech-log-frontend/tests/component/inline-line-breaks.test.tsx
T
DongHyeonkaandClaude Opus 5 9b7ad82fe3 fix: 산문 칸의 문단과 인라인 코드를 읽어서 그린다
Case 만 블록 파서를 타고 나머지 유형은 문자열을 그대로 내보내고 있었다.
그래서 두 가지가 깨졌다.

작성자가 백틱으로 적은 식별자가 백틱째 화면에 나왔다. 어떤 Reference 는
한 문서에 백틱이 32개였고, 그 원문이 홈 카드·탐색 카드·검색 결과까지
그대로 퍼졌다. 판단 기준은 `<p>{rule.body}</p>` 로, 적용할 때·예외·예시는
`<li>{item.text}</li>` 로 아무것도 거치지 않고 나가고 있었다.

빈 줄로 나눈 문단이 문단으로 보이지 않았다. 어제 넣은 PlainText 는 모든
줄바꿈을 <br> 로 만들었기 때문에 빈 줄도 <br><br> 로 나갔고, 문단 사이
여백이 없었다. Reference 7개 전부에 빈 줄이 9~16개 있다.

ProseText 로 바꾼다 — 빈 줄은 문단을 가르고, 문단 안 줄바꿈은 그 자리에
지키고, 백틱은 코드로 읽는다. 백틱 수가 홀수면 원문을 그대로 둔다:
작성자가 백틱 자체를 쓴 것일 수 있고, 반쯤 해석해 한쪽만 코드로 만드는
쪽이 더 나쁘다.

블록 파서(parseCaseContent)를 쓰지 않는 이유는 그쪽이 Case 전용 문법과
도식 참조까지 물고 있어 이 칸들에 없는 해석기를 끌고 오기 때문이다.

머리말 가드는 <br> 개수로 재고 있었다. 이제 기준이 문단이므로 문단 수와
문단 안 줄바꿈을 함께 확인하도록 고친다 — 가드가 낡은 것이지 화면이
틀린 것이 아니다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ
2026-08-31 08:06:03 +09:00

107 lines
4.4 KiB
TypeScript

// @vitest-environment jsdom
import { render } from "@testing-library/react";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it } from "vitest";
import { PublicDocumentHeader } from "../../src/features/tech-log/presentation/public/components/public-document-header.tsx";
import type { QuestionRecord } from "../../src/features/tech-log/application/ports/public-content-queries.ts";
import {
InlineRenderer,
PlainText,
} from "../../src/features/tech-log/presentation/shared/public-render/inline-renderer.tsx";
/**
* 작성자가 엔터로 나눠 쓴 글이 한 줄로 이어져 보였다. Markdown 이 한 번의 줄바꿈을 문단 내 공백으로
* 읽고, 파서가 그 줄바꿈을 텍스트에 남긴 뒤, HTML 이 다시 공백으로 접기 때문이다. 미리보기와 공개
* 화면이 같은 렌더러를 쓰므로 두 곳 모두에서 그랬다.
*/
describe("문단 안의 줄바꿈", () => {
it("줄바꿈을 <br> 로 그린다", () => {
const { container } = render(
<InlineRenderer content={[{ type: "TEXT", text: "첫째 줄\n둘째 줄" }]} />,
);
expect(container.querySelectorAll("br")).toHaveLength(1);
expect(container.textContent).toBe("첫째 줄둘째 줄");
});
it("줄바꿈이 없으면 <br> 를 넣지 않는다", () => {
const { container } = render(
<InlineRenderer content={[{ type: "TEXT", text: "한 줄" }]} />,
);
expect(container.querySelectorAll("br")).toHaveLength(0);
expect(container.textContent).toBe("한 줄");
});
it("여러 번 엔터를 친 만큼 내려간다", () => {
const { container } = render(
<InlineRenderer content={[{ type: "TEXT", text: "가\n나\n다" }]} />,
);
expect(container.querySelectorAll("br")).toHaveLength(2);
});
});
/**
* 요약·문제·결론·환경은 Markdown 을 거치지 않고 그대로 그려진다. 본문만 고쳤을 때 이 칸들이
* 여전히 이어져 보인 이유이고, 작성자가 "아직 안 고쳐졌다" 고 본 것도 이쪽이다.
*/
describe("Markdown 을 거치지 않는 평문 칸", () => {
it("작성자가 나눠 쓴 줄을 지킨다", () => {
const { container } = render(<PlainText text={"문제 첫 줄\n문제 둘째 줄"} />);
expect(container.querySelectorAll("br")).toHaveLength(1);
});
it("한 줄이면 <br> 를 넣지 않는다", () => {
const { container } = render(<PlainText text="한 줄" />);
expect(container.querySelectorAll("br")).toHaveLength(0);
});
});
/**
* 문서 머리말의 요약. 상한이 2000자가 되면서 요약은 한 문장이 아니라 여러 문단이 되었고,
* 여기만 `PlainText` 를 거치지 않아 그 문단들이 한 덩어리로 이어져 보였다.
*/
describe("문서 머리말의 요약", () => {
const record: QuestionRecord = {
kind: "QUESTION",
slug: "session-store-boundary",
title: "세션 저장소 경계",
summary: "Mediator와 BFF는 서로 다른 저장소를 쓴다.\n둘 다 메모리에 있다.\n\n인스턴스를 늘리면 설계가 필요하다.",
path: "/questions/session-store-boundary",
topic: "인증",
topicSlug: "auth",
projectSlug: "keycloak",
projectTitle: "Keycloak",
publishedAt: "2026-08-29T00:00:00Z",
publishedLabel: "2026.08.29",
visibility: "PUBLIC",
relations: [],
questionStatus: "OPEN",
facts: [],
assumptions: [],
unknowns: [],
constraints: [],
options: [],
nextValidation: "",
};
it("빈 줄은 문단으로, 문단 안 줄바꿈은 줄바꿈으로 그린다", () => {
const { container } = render(
<MemoryRouter>
<PublicDocumentHeader record={record} />
</MemoryRouter>,
);
/*
요약은 "두 줄 + 빈 줄 + 한 줄" 이다. 예전에는 셋 다 <br> 로 나가서 문단 사이 여백이
없었다. 지금은 빈 줄이 문단을 가르고, 문단 안의 줄바꿈만 <br> 로 남는다.
*/
const paragraphs = container.querySelectorAll(".public-document-header p");
expect(paragraphs).toHaveLength(2);
expect(container.querySelectorAll(".public-document-header p br")).toHaveLength(1);
// 그대로 넣으면 문단 하나에 <br> 0개가 되어 전부 한 덩어리로 읽힌다.
expect(paragraphs[0]).toHaveTextContent("둘 다 메모리에 있다.");
expect(paragraphs[1]).toHaveTextContent("인스턴스를 늘리면 설계가 필요하다.");
});
});