Files
clean-architecture-frontend…/tests/unit/oklch-contrast.test.ts
T
DongHyeonka 35b183b64f fix(design-system): 라이트 포커스 링이 모든 표면에서 3:1을 넘게 한다 (UI-01)
라이트 --color-focus가 흰 패널에서 2.33:1, surface-muted에서 1.95:1로
WCAG 1.4.11 기준(3:1)에 못 미쳤다. 포커스 링은 컨트롤에서 3px 떨어져
그려지므로, 대비를 따질 인접색은 컨트롤 뒤의 표면이다.

라이트 포커스를 oklch(0.52 0.15 230)으로 바꿨다. 가장 낮은 대비가
4.24:1이다. 다크는 그대로다. check:design-system이 두 테마에서 포커스
토큰과 표면 토큰 8종의 대비를 계산하고, 3:1 미만이면 실패한다.
안팎 이중 링은 버렸다. 한 색으로 충분하고 링 모양이 바뀌지 않는다.

위험: 포커스 링 색이 진해져 시각 골든이 바뀐다(별도 커밋에서 갱신).
검증: 토큰을 바꾸기 전 검사가 라이트 표면 8종 모두에서 실패했고,
바꾼 뒤 통과했다. 계산식은 브라우저 실측값 2.33:1과 일치한다
(tests/unit/oklch-contrast.test.ts).
2026-11-01 18:34:28 +09:00

44 lines
1.5 KiB
TypeScript

import { describe, expect, it } from "vitest";
import {
contrastRatio,
parseOklch,
readCustomProperties,
resolveColor,
} from "../../scripts/lib/oklch-contrast.ts";
const color = (value: string) => {
const parsed = parseOklch(value);
if (!parsed) throw new Error(`not an oklch value: ${value}`);
return parsed;
};
describe("oklch contrast", () => {
it("gives 21:1 for white on black", () => {
expect(contrastRatio(color("oklch(1 0 0)"), color("oklch(0 0 0)"))).toBeCloseTo(21, 1);
});
// UI-01: the old light focus ring measured 2.33:1 on white in Chromium.
it("matches the ratio the browser measured for the old focus ring", () => {
expect(
contrastRatio(color("oklch(0.72 0.16 225)"), color("oklch(1 0 0)")),
).toBeCloseTo(2.33, 1);
});
it("reads percentages and a missing hue", () => {
expect(parseOklch("oklch(50% 0.1 none)")).toEqual({ l: 0.5, c: 0.1, h: 0 });
expect(parseOklch("color-mix(in oklab, red, blue)")).toBeNull();
});
it("follows var() chains and refuses values it cannot draw", () => {
const properties = readCustomProperties(`
--palette-white: oklch(1 0 0);
--color-panel: var(--palette-white);
--color-mixed: color-mix(in oklab, var(--palette-white) 50%, transparent);
`);
expect(resolveColor("--color-panel", properties)).toEqual({ l: 1, c: 0, h: 0 });
expect(resolveColor("--color-mixed", properties)).toBeNull();
expect(resolveColor("--color-missing", properties)).toBeNull();
});
});