Files
tech-log-frontend/tests/component/highlight-match.test.tsx
T
DongHyeonkaandClaude Opus 5 795a4bf4a9 fix: 목록·검색 카드에서 백틱을 지운다
카드는 본문 요약을 그대로 가져다 세 줄로 자른다. 그 요약은 Markdown 으로
쓰였으므로 작성자가 코드 표시로 쓴 백틱이 카드에도 그대로 나왔다 — 문서
본문에서는 <code> 가 되지만 카드에서는 그냥 문자다. 홈·탐색·검색이 같은
텍스트를 쓰므로 세 곳에서 같이 보였다. 배포된 검색 모달을 열어 보고서야
알았다: 본문만 고치고 카드는 그대로 두었다.

카드에서 코드 스타일을 살리지 않는 이유는 카드가 훑어보는 자리이기
때문이다. 한 줄 안에 배경색 조각이 여럿 끼면 제목보다 그쪽이 먼저 눈에
든다. 문단 줄바꿈도 공백으로 접는다 — 어차피 세 줄에서 잘리므로 줄을
지켜 봐야 잘리는 위치만 어긋난다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ
2026-08-31 09:28:30 +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/presentation/shared/card-summary.ts"
);
expect(cardSummary("모두 하나의 `로그인 상태`로 보면\n안 된다.\n\n두 번째 문단.")).toBe(
"모두 하나의 로그인 상태로 보면 안 된다. 두 번째 문단.",
);
});
it("빈 값이면 빈 문자열을 준다", async () => {
const { cardSummary } = await import(
"../../src/features/tech-log/presentation/shared/card-summary.ts"
);
expect(cardSummary(undefined)).toBe("");
expect(cardSummary(" ")).toBe("");
});
});