// @vitest-environment jsdom import { render } from "@testing-library/react"; import { describe, expect, it } from "vitest"; import { ProseText } from "../../src/features/tech-log/presentation/shared/public-render/prose-text.tsx"; /** * 산문 칸이 오래 평문으로 나갔다. 빈 줄로 나눈 문단이 문단으로 보이지 않았고, 작성자가 백틱으로 * 적은 식별자가 백틱째 화면에 나왔다 — 그 원문이 카드와 검색 결과까지 그대로 퍼졌다. */ describe("산문 칸", () => { it("빈 줄로 나눈 문단을 문단으로 그린다", () => { const { container } = render(); const paragraphs = container.querySelectorAll("p"); expect(paragraphs).toHaveLength(2); expect(paragraphs[0]).toHaveTextContent("첫 문단."); expect(paragraphs[1]).toHaveTextContent("둘째 문단."); }); it("빈 줄을 여러 개 띄워도 빈 문단을 만들지 않는다", () => { const { container } = render(); expect(container.querySelectorAll("p")).toHaveLength(2); }); it("문단 안의 줄바꿈은 그 자리에 지킨다", () => { const { container } = render(); expect(container.querySelectorAll("p")).toHaveLength(1); expect(container.querySelectorAll("br")).toHaveLength(1); }); it("백틱으로 감싼 조각을 코드로 읽는다", () => { const { container } = render( , ); const codes = [...container.querySelectorAll("code")].map((el) => el.textContent); expect(codes).toEqual(["로그인 상태가 만료되었다", "Access Token"]); // 백틱은 화면에 남지 않아야 한다 — 카드와 검색 결과까지 퍼지던 것이 이 문자다. expect(container.textContent).not.toContain("`"); }); it("백틱 짝이 맞지 않으면 원문을 그대로 둔다", () => { const { container } = render(); expect(container.querySelectorAll("code")).toHaveLength(0); expect(container.textContent).toContain("`"); }); it("빈 문자열이면 아무것도 그리지 않는다", () => { const { container } = render(); expect(container.querySelectorAll("p")).toHaveLength(0); }); }); /** * 릴리스 노트의 각 칸은 Markdown 으로 쓰이는데 목록으로만 읽혀서, 소제목과 블록 문법이 항목에 * 섞여 나왔다. 그 노트의 내용이 하필 "본문의 표·코드·callout·그림이 렌더링됩니다" 였다. */ describe("릴리스 노트 목록 읽기", () => { it("소제목·수평선·블록 울타리를 항목으로 세지 않는다", async () => { const { markdownLines } = await import( "../../src/features/tech-log/adapters/http/public-content-mapping.ts" ); expect( markdownLines("## 작성\n\n- 편집 화면의 버튼을 줄였습니다.\n- 채워야 할 칸을 표시합니다.\n\n---\n\n## 본문 문법\n:::note\n- 표를 지원합니다."), ).toEqual([ "편집 화면의 버튼을 줄였습니다.", "채워야 할 칸을 표시합니다.", "표를 지원합니다.", ]); }); it("번호 목록도 항목으로 읽는다", async () => { const { markdownLines } = await import( "../../src/features/tech-log/adapters/http/public-content-mapping.ts" ); expect(markdownLines("1. 첫째\n2. 둘째")).toEqual(["첫째", "둘째"]); }); }); /** * 관계 목록의 요약. 계약은 관계마다 요약을 주는데 경계 세 곳(평탄화 → 렌더 모델 → 화면 목록)을 * 지나며 조용히 사라졌다. 독자가 목록에서 보는 것이 제목뿐이라, 왜 이 기록이 걸려 있는지는 * 눌러 봐야 알 수 있었다. */ describe("관계 목록", () => { async function renderRelations(relation: Record) { const { PublicDocumentRelations } = await import( "../../src/features/tech-log/presentation/shared/public-render/public-document-relations.tsx" ); const { MemoryRouter: Router } = await import("react-router-dom"); return render( , ); } it("대상 요약을 제목 아래 보여 주되 링크 이름에는 넣지 않는다", async () => { const { container, getByRole } = await renderRelations({ label: "적용 기준", title: "SPA에서 토큰을 직접 관리하면서 드러난 경계", path: "/cases/spa-browser-credential-boundary", summary: "SPA가 public OAuth client로 code를 직접 교환한다.", }); expect(container.querySelector(".document-relations li p")).toHaveTextContent( "SPA가 public OAuth client로 code를 직접 교환한다.", ); /* 링크 이름에 요약이 들어가면 관계 목록을 훑을 때 링크 하나하나가 문단이 되어 목록으로서 쓸모가 없어진다 — 이름은 「묶음 이름 + 제목」까지다. */ const link = getByRole("link", { name: /적용 기준/ }); expect(link.getAttribute("aria-label")).toBeNull(); expect(link).not.toHaveAccessibleName(/code를 직접 교환/); }); /* 작성자가 관계마다 남긴 문장이 「다음에 무엇을 읽을지」의 답이다. 대상의 요약은 대상을 설명할 뿐이라, 둘 다 있으면 작성자의 문장을 보인다. 이 문장은 오래 Studio 에만 있었고 공개 화면에는 한 번도 나오지 않았다. */ it("작성자가 남긴 이유가 있으면 대상 요약 대신 그것을 보인다", async () => { const { container } = await renderRelations({ label: "검증 기록", title: "SPA에서 토큰을 직접 관리하면서 드러난 경계", path: "/cases/spa-browser-credential-boundary", note: "이 기준이 왜 필요했는지를 이 기록이 보여 준다.", summary: "SPA가 public OAuth client로 code를 직접 교환한다.", }); const description = container.querySelector(".document-relations li p"); expect(description).toHaveTextContent("이 기준이 왜 필요했는지를 이 기록이 보여 준다."); expect(description).not.toHaveTextContent("code를 직접 교환"); }); });