Files
tech-log-frontend/tests/component/highlight-match.test.tsx
T
DongHyeonkaandClaude Opus 5 642afa878c fix: 관계 목록이 사람이 읽는 이름과 요약을 보여 준다
Reference 화면에 `supportingCases` 가 한글 라벨 없이 네 번 반복해서 나왔다.
라벨 표의 키가 계약이 실제로 주는 이름과 어긋나 있었기 때문이다 —
`originCases`·`projectDecisions` 로 적혀 있었고 계약은 `supportingCases`·
`relatedDecisions` 를 준다. 표에 없는 키는 그대로 화면에 나온다.

Question 은 같은 결함을 이미 겪고 고친 자리다(주석에 남아 있다). 이번에는
표를 상수로 빼서 계약이 주는 이름 전부가 등록됐는지 확인할 수 있게 한다.

계약은 관계마다 요약도 함께 주는데 평탄화가 그것을 버렸다. 독자가 목록에서
보는 것이 제목뿐이라, 왜 이 기록이 걸려 있는지는 눌러 봐야 알 수 있었다.
요약을 흘려보내 제목 아래 두 줄로 보여 준다.

요약은 링크의 이름에서 뺀다 — 이름에 들어가면 관계 목록을 훑을 때 링크
하나하나가 문단이 되어 목록으로서 쓸모가 없어진다.

`cardSummary` 를 domain 으로 옮긴다. 어댑터가 presentation 을 import 하는
것을 아키텍처 규칙이 막았고, 그 지적이 옳다 — 이 함수는 화면이 아니라
글을 다루는 규칙이다.

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

63 lines
2.6 KiB
TypeScript

// @vitest-environment jsdom
import { render } from "@testing-library/react";
import { describe, expect, it } from "vitest";
import { HighlightMatch } from "../../src/features/tech-log/presentation/shared/highlight-match.tsx";
/**
* 검색 결과가 제목과 요약을 그대로 보여 주기만 해서, 무엇이 걸려 이 결과가 나왔는지 눈으로
* 다시 찾아야 했다.
*/
describe("검색어 강조", () => {
it("찾은 말을 표시한다", () => {
const { container } = render(
<HighlightMatch text="Session Cookie와 session ID는 다르다" query="session" />,
);
const marks = [...container.querySelectorAll("mark")].map((m) => m.textContent);
// 대소문자를 구분하지 않는다 — 이 저장소의 글은 둘을 섞어 쓴다.
expect(marks).toEqual(["Session", "session"]);
expect(container.textContent).toBe("Session Cookie와 session ID는 다르다");
});
it("걸린 곳이 없으면 원문 그대로 둔다", () => {
const { container } = render(<HighlightMatch text="토큰 경계" query="session" />);
expect(container.querySelectorAll("mark")).toHaveLength(0);
expect(container.textContent).toBe("토큰 경계");
});
it("정규식 문자가 들어가도 깨지지 않는다", () => {
const { container } = render(<HighlightMatch text="a+b 는 a+b 다" query="a+b" />);
expect(container.querySelectorAll("mark")).toHaveLength(2);
});
it("빈 검색어면 아무것도 표시하지 않는다", () => {
const { container } = render(<HighlightMatch text="아무 글" query=" " />);
expect(container.querySelectorAll("mark")).toHaveLength(0);
});
});
/**
* 목록·검색 카드는 본문 요약을 그대로 가져다 세 줄로 자른다. 그 요약은 Markdown 이므로
* 작성자가 코드 표시로 쓴 백틱이 카드에도 그대로 나왔다 — 홈·탐색·검색이 같은 텍스트를 쓰므로
* 세 곳에서 같이 보였다.
*/
describe("카드 요약", () => {
it("백틱을 지우고 줄바꿈을 접는다", async () => {
const { cardSummary } = await import(
"../../src/features/tech-log/domain/content-format/card-summary.ts"
);
expect(cardSummary("모두 하나의 `로그인 상태`로 보면\n안 된다.\n\n두 번째 문단.")).toBe(
"모두 하나의 로그인 상태로 보면 안 된다. 두 번째 문단.",
);
});
it("빈 값이면 빈 문자열을 준다", async () => {
const { cardSummary } = await import(
"../../src/features/tech-log/domain/content-format/card-summary.ts"
);
expect(cardSummary(undefined)).toBe("");
expect(cardSummary(" ")).toBe("");
});
});