Files
tech-log-frontend/tests/features/tech-log/section-heading-rank.test.ts
T
DongHyeonkaandClaude Opus 5 68538f2e17 fix: 구역 제목의 급이 갈리던 것을 정본에 맞춘다
「구조별로 알게 된 것」만 26px·굵기 400 으로 나왔다. 형제 구역(「먼저 읽을 것」·「이 주제를
다룬 프로젝트」)은 30px·650 이라, 같은 화면에서 이 구역만 급이 낮아 디자인이 빠진 것처럼
보였다.

규칙이 없었던 게 아니라 절반만 있었다. 정본은 `.section-heading-row h2` 인데 그 안에
들어가지 않는 두 구역이 크기만 각자 적어 두어 굵기를 아무도 정하지 않았고, 그래서 기본값
400 으로 떨어졌다. 값을 정본과 맞추고, 나란히 서는 제목들이 다시 갈라지면 멈추는 검사를
둔다 — 굵기를 빼 보고 실제로 멈추는 것을 확인했다.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_011nAjrqNHGPNngN4aUbcyvJ
2026-09-01 21:19:47 +09:00

55 lines
2.2 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import { test } from "vitest";
/**
* 한 화면에 나란히 서는 구역 제목은 같은 급이어야 한다.
*
* <p>정본은 `.section-heading-row h2` 다. 그 안에 들어가지 않는 두 구역이 크기만 각자 적어 두어
* 굵기를 아무도 정하지 않았고, 400 으로 떨어져 「구조별로 알게 된 것」만 형제 구역보다 작고
* 가늘게 나왔다 — 규칙이 없는 게 아니라 절반만 있었고, 그래서 「디자인이 안 됐다」로 보였다.
*/
const RAW = readFileSync("src/features/tech-log/presentation/styles/globals.css", "utf8");
/**
* 좁은 화면용 값은 뺀다. 화면 폭마다 급이 달라지는 것은 의도이고, 여기서 보려는 것은 같은
* 폭에서 나란히 설 때의 급이다.
*/
const CSS = RAW.replace(/@media[^{]*\{(?:[^{}]*\{[^}]*\})*[^{}]*\}/gu, "");
/** 나란히 서는 구역 제목들. 정본이 맨 앞이다. */
const SECTION_HEADINGS = [
".section-heading-row h2",
".document-relations h2",
".topic-variants h2",
] as const;
/** 마지막으로 선언된 값을 읽는다 — 뒤에 오는 규칙이 이긴다. */
function declared(selector: string, property: string): string | null {
const escaped = selector.replace(/[.*+?^${}()|[\]\\]/gu, "\\$&");
const blocks = [
...CSS.matchAll(new RegExp(`(?:^|,|\\n)\\s*${escaped}\\s*(?:,[^{]*)?\\{([^}]*)\\}`, "gu")),
];
let value: string | null = null;
for (const block of blocks) {
const found = new RegExp(`${property}:\\s*([^;]+)`, "u").exec(block[1]!);
if (found) value = found[1]!.trim();
}
return value;
}
test("나란히 서는 구역 제목이 같은 크기와 굵기를 쓴다", () => {
const canonical = SECTION_HEADINGS[0];
for (const property of ["font-size", "font-weight"]) {
const want = declared(canonical, property);
assert.ok(want, `${canonical} 에 ${property} 가 없다 — 정본이 값을 갖고 있어야 한다`);
for (const selector of SECTION_HEADINGS.slice(1)) {
assert.equal(
declared(selector, property),
want,
`${selector} 의 ${property} 가 ${canonical} 과 다르다`,
);
}
}
});