fix(a11y): ghost hover 대비, tone 표시, 부트 재시도 버튼 높이를 고친다 #93
@@ -96,6 +96,10 @@ Gitea runner에서 merge 단계를 초록으로 만들고, worker를 늘리지
|
||||
- 옮기기 전: 대기가 힌트와 같거나, 힌트보다 늦은 로컬 지연과 같다고 단언한 시험이 실패할 수 있다. 실제 대기가 `maxDelayMs`·`maxIntervalMs`·`maxRetryAfterMs`보다 jitter만큼 길 수 있다. 상한 안의 힌트만 받던 설정도 다시 보낸 시도에 남는 시간이 줄어 timeout이 새로 날 수 있다.
|
||||
- 옮기는 법: 시간 예산(`totalDeadlineMs`, `maxElapsedMs`)을 재시도마다 더해지는 jitter 상한 2초만큼 여유 있게 둔다. 시험에 `random: () => 0`을 넣으면 jitter가 0이다. 그 밖에는 하한과 범위로 단언한다.
|
||||
- 옮긴 뒤 확인: `scripts/verify.sh script test:unit`.
|
||||
- `Alert`와 `Toast`의 텍스트가 tone 이름(정보·성공·경고·위험)으로 시작한다(DES-FE-0002).
|
||||
- 옮기기 전: 두 primitive의 글자 전체를 똑같이 견주는 자기 시험이 실패한다. 제목에 같은 낱말(「경고: …」)을 넣었으면 스크린 리더가 두 번 읽는다. 두 primitive가 보이는 자기 골든도 바뀐다.
|
||||
- 옮기는 법: 시험은 제목만 견주거나 앞의 tone 이름까지 적는다. 제목에서 그 낱말을 뺀다. 골든은 diff가 아이콘 자리뿐인지 보고 `test:visual:update`로 다시 찍는다.
|
||||
- 옮긴 뒤 확인: `scripts/verify.sh gate FE-GATE-006`, `scripts/verify.sh gate FE-GATE-008`.
|
||||
|
||||
### 보안·계약 변경
|
||||
|
||||
@@ -187,6 +191,9 @@ Gitea runner에서 merge 단계를 초록으로 만들고, worker를 늘리지
|
||||
| 노트북 `scripts/verify.sh docs`(`scripts/check-work-docs.py`)가, 기능 제거 드릴이 사본에서만 지우는 시험(`scripts/test-sample-removal.ts`의 `excludedFixtureTest` 목록)을 드릴 사본의 `verify:documentation`이 경로로 읽는 자리에 적으면 `file:line`으로 실패한다. 그 자리는 드릴이 복사하는 살아 있는 문서의 백틱 경로·명령 인자·상대 링크와 기록 문서 머리 블록의 「현재 정본」「대체」「대체됨」이다. 전에는 desktop FE-GATE-020에서야 드러났다. 그런 시험은 폴더와 파일 이름을 따로 적는다(`tests/unit/`의 `removal-fixture.test.ts`). 드릴은 `package.json`의 `test:sample-removal`로 찾는다. 그 script가 읽을 드릴 파일을 가리키지 않으면 「runs no drill file」, 목록을 못 찾으면 「was not found」, 목록에 큰따옴표 경로 말고 다른 것(펼침·작은따옴표)이 있으면 「holds more than double-quoted paths」로 실패한다. 이 규칙의 정본은 TypeScript이고, Python으로 다시 쓴 쪽과 어긋나면 `scripts/tests/test_check_work_docs.py`가 실패한다 | `scripts/check-work-docs.py`, `scripts/tests/test_check_work_docs.py`, `scripts/test-sample-removal.ts`, `docs/operations/adapter-remediation-ledger.md` | `d87f6792` |
|
||||
| FE-GATE-005의 기능 모양 기록 대조(`initialJavascriptRecordDrift`)가 `perContextGzipBytes` 칸만 바닥 64 B로 본다(전에는 16 B). 이 칸은 커밋 사이에서 2~28 B를 오가, 초기 청크를 바꾼 PR이 먼저 병합된 뒤 다른 PR이 낡은 base에서 잰 기록을 쓰면 main이 빨강이 됐다. 다른 칸의 16 B, 합계 256 B, context 상한 512 B는 그대로다. 소유자 결정 DES-DEC-0002(`docs/work/reference/decisions.md` 2.2절) | `scripts/scale/measure-feature-shape-growth.ts`, `tests/unit/feature-shape-growth.test.ts`, `docs/work/reference/decisions.md` | `e21a8355` |
|
||||
| 이력 문서를 읽지 않는지 보는 검사(`tests/unit/deletable-history-documents.test.ts`, FE-GATE-005)가 `history-free` 목록 대신 git이 무시하지 않는 코드·설정 파일(그 시험의 `CODE_FILE` 확장자)을 본다. 복사한 프로젝트의 루트 설정이 지워도 되는 이력 문서를 읽고 있으면 새로 실패한다. 그 읽기를 없앤다. `tests/features` 바로 아래에 있던 플랫폼 시험 `feature-module`·`product-features-scale`은 `tests/unit/`로 옮기고, 지워진 참조 기능만 보던 `feature-installation-surface` 시험은 지웠다. 폴더는 `.gitkeep`으로 남는다 | `tests/unit/`, `tests/features/`, `config/repository-layout.json` | `2816a42f`, `3686f92c` |
|
||||
| ghost 버튼에 마우스를 올린 글자가 `--color-action-hover`를 읽는다. 전에는 `--color-action`이라 라이트 테마에서 `--color-surface-muted` 배경과 4.14:1로 본문 기준 4.5:1에 못 미쳤다. 스타일 규칙 하나의 글자·배경 대비를 재는 `textContrastFailures`를 더하고 단위 시험(FE-GATE-005)이 두 테마에서 이 쌍을 잰다. `check:design-system`은 이 규칙을 부르지 않는다. 토큰을 바꾼 제품은 그 시험이 자기 값으로 잰다 (DES-FE-0001) | `src/presentation/styles/theme/primitives.css`, `scripts/lib/design-system-rules.ts`, `tests/unit/design-system-rules.test.ts` | `aab85a74` |
|
||||
| `Alert`와 `Toast`가 제목 앞에 tone마다 다른 장식 아이콘과 숨은 tone 이름(`status.tone.*`: 정보·성공·경고·위험)을 그린다. 전에는 tone을 색으로만 나타내, 중립 제목이면 경고와 정보가 갈리지 않았다. 두 primitive의 텍스트가 tone 이름으로 시작한다. 위 "먼저 할 일" (DES-FE-0002) | `src/presentation/design-system/primitives/status-tone.tsx`, `src/presentation/design-system/primitives/alert.tsx`, `src/presentation/design-system/primitives/toast.tsx`, `src/presentation/i18n/catalog.ts`, `src/presentation/styles/theme/primitives.css`, `tests/visual/__snapshots__/` | `7a9856bb` |
|
||||
| 부트 실패 화면의 재시도 버튼이 `ui-button ui-button--primary` class로 44px 높이를 갖는다. 전에는 class가 없어 24px였다. 이 화면은 여전히 `Button`을 import하지 않는다 (DES-FE-0009) | `src/presentation/boundaries/boot-error-shell.tsx`, `tests/e2e/responsive.spec.ts` | `a9c7ca4a` |
|
||||
|
||||
## 미출시 — `8327e221` → 하네스와 작업 매뉴얼
|
||||
|
||||
|
||||
@@ -60,6 +60,42 @@ export function focusContrastFailures(
|
||||
return failures;
|
||||
}
|
||||
|
||||
// DES-FE-0001. UI-01 measures the focus ring alone, and the ghost button's
|
||||
// hover drew blue-600 text on slate-100, 4.14:1 in the light theme. WCAG 1.4.3
|
||||
// asks 4.5:1 of text at the body size, under the pointer too. The pair is read
|
||||
// from the rule that draws it, so the colours measured are the ones it names.
|
||||
// check:design-system does not run this rule: design-system-rules.test.ts
|
||||
// hands it the repository's style sheet in FE-GATE-005.
|
||||
export function textContrastFailures(
|
||||
theme: string,
|
||||
selector: string,
|
||||
{ file, source }: CssSource,
|
||||
properties: ReadonlyMap<string, string>,
|
||||
): string[] {
|
||||
const drawn = new Map(properties);
|
||||
for (const [, selectors, body] of withoutComments(source).matchAll(/([^{}]+)\{([^{}]*)\}/g)) {
|
||||
if (!selectors.split(",").some((item) => item.trim() === selector)) continue;
|
||||
for (const [, property, value] of body.matchAll(/([a-z-]+)\s*:\s*([^;]+)/g)) {
|
||||
drawn.set(property, value.trim());
|
||||
}
|
||||
}
|
||||
const text = resolveColor("color", drawn);
|
||||
const background = resolveColor("background", drawn);
|
||||
if (!text || !background) {
|
||||
const property = text ? "background" : "color";
|
||||
return [
|
||||
`${file} ${theme} ${selector} ${property} is ${resolveValue(property, drawn) ?? "not defined"}; ` +
|
||||
"contrast needs an opaque oklch(L C H), hue in degrees with or without deg",
|
||||
];
|
||||
}
|
||||
const ratio = contrastRatio(text, background);
|
||||
if (ratio >= 4.5) return [];
|
||||
return [
|
||||
`${file} ${theme} ${selector} text contrast ${ratio.toFixed(2)}:1 ` +
|
||||
`(${drawn.get("color")} on ${drawn.get("background")}) is below 4.5:1`,
|
||||
];
|
||||
}
|
||||
|
||||
// UI-02. Hue-based spaces interpolate the hue angle, and an achromatic
|
||||
// stop such as oklch(1 0 0) carries hue 0: 14% blue into white came out
|
||||
// pink. oklab mixes on straight lines and has no hue to drag. CSS
|
||||
|
||||
@@ -72,7 +72,11 @@ export function BootErrorShell({
|
||||
{retry && (
|
||||
<>
|
||||
<p>{MESSAGES["boot.retry.hint"]}</p>
|
||||
<button type="button" onClick={onRetry}>
|
||||
<button
|
||||
type="button"
|
||||
className="ui-button ui-button--primary"
|
||||
onClick={onRetry}
|
||||
>
|
||||
{MESSAGES["boot.retry.action"]}
|
||||
</button>
|
||||
</>
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { useLocale } from "../../i18n/index.ts";
|
||||
import { CloseIcon } from "../icons/semantic-icons.tsx";
|
||||
import { IconButton } from "./icon-button.tsx";
|
||||
import { StatusTone } from "./status-tone.tsx";
|
||||
|
||||
export type AlertProps = Readonly<{
|
||||
title: string;
|
||||
@@ -24,6 +25,7 @@ export function Alert({
|
||||
role={variant === "danger" ? "alert" : "status"}
|
||||
>
|
||||
<div>
|
||||
<StatusTone tone={variant} />
|
||||
<strong>{title}</strong>
|
||||
{children ? <div className="ui-alert__content">{children}</div> : null}
|
||||
</div>
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
import { useLocale } from "../../i18n/index.ts";
|
||||
import {
|
||||
ErrorIcon,
|
||||
InfoIcon,
|
||||
SuccessIcon,
|
||||
WarningIcon,
|
||||
} from "../icons/semantic-icons.tsx";
|
||||
import { VisuallyHidden } from "./visually-hidden.tsx";
|
||||
|
||||
const TONES = {
|
||||
info: { Icon: InfoIcon, label: "status.tone.info" },
|
||||
success: { Icon: SuccessIcon, label: "status.tone.success" },
|
||||
warning: { Icon: WarningIcon, label: "status.tone.warning" },
|
||||
danger: { Icon: ErrorIcon, label: "status.tone.danger" },
|
||||
} as const;
|
||||
|
||||
/**
|
||||
* DES-FE-0002. What `Alert` and `Toast` put before their title, so that a tone
|
||||
* does not rest on colour or on the caller's words: an icon for the eye and
|
||||
* the tone's name for assistive technology. The space keeps the name a word
|
||||
* of its own in the text that is read out.
|
||||
*/
|
||||
export function StatusTone({ tone }: Readonly<{ tone: keyof typeof TONES }>) {
|
||||
const { message } = useLocale();
|
||||
const { Icon, label } = TONES[tone];
|
||||
return (
|
||||
<>
|
||||
<span className="ui-status-tone">
|
||||
<Icon />
|
||||
<VisuallyHidden>{message(label)}</VisuallyHidden>
|
||||
</span>{" "}
|
||||
</>
|
||||
);
|
||||
}
|
||||
@@ -11,6 +11,7 @@ import {
|
||||
import { useLocale } from "../../i18n/index.ts";
|
||||
import { CloseIcon } from "../icons/semantic-icons.tsx";
|
||||
import { IconButton } from "./icon-button.tsx";
|
||||
import { StatusTone } from "./status-tone.tsx";
|
||||
|
||||
type ToastTone = "info" | "success" | "warning" | "danger";
|
||||
type ToastInput = Readonly<{
|
||||
@@ -118,6 +119,7 @@ function ToastItem({
|
||||
}>) {
|
||||
const { message } = useLocale();
|
||||
const [paused, setPaused] = useState(false);
|
||||
const tone = toast.tone ?? "info";
|
||||
useEffect(() => {
|
||||
if (paused) return;
|
||||
const timeout = window.setTimeout(
|
||||
@@ -129,7 +131,7 @@ function ToastItem({
|
||||
|
||||
return (
|
||||
<article
|
||||
className={`ui-toast ui-toast--${toast.tone ?? "info"}`}
|
||||
className={`ui-toast ui-toast--${tone}`}
|
||||
onBlur={(event) => {
|
||||
if (!event.currentTarget.contains(event.relatedTarget)) setPaused(false);
|
||||
}}
|
||||
@@ -138,6 +140,7 @@ function ToastItem({
|
||||
onMouseLeave={() => setPaused(false)}
|
||||
>
|
||||
<div>
|
||||
<StatusTone tone={tone} />
|
||||
<strong>{toast.title}</strong>
|
||||
{toast.count > 1 ? (
|
||||
<span className="ui-toast__count"> ×{toast.count}</span>
|
||||
|
||||
@@ -160,6 +160,10 @@ const PLATFORM_KO_MESSAGES = {
|
||||
"form.remaining": "{count}자 남음",
|
||||
"form.remaining.one": "{count}자 남음",
|
||||
"toast.region": "알림",
|
||||
"status.tone.info": "정보",
|
||||
"status.tone.success": "성공",
|
||||
"status.tone.warning": "경고",
|
||||
"status.tone.danger": "위험",
|
||||
"error.network_unreachable": "네트워크에 연결할 수 없습니다.",
|
||||
"error.request_timeout": "요청 시간이 초과되었습니다.",
|
||||
"error.auth_required": "계속하려면 로그인이 필요합니다.",
|
||||
@@ -368,6 +372,10 @@ const PLATFORM_EN_MESSAGES = {
|
||||
"form.remaining": "{count} characters remaining",
|
||||
"form.remaining.one": "{count} character remaining",
|
||||
"toast.region": "Notifications",
|
||||
"status.tone.info": "Information",
|
||||
"status.tone.success": "Success",
|
||||
"status.tone.warning": "Warning",
|
||||
"status.tone.danger": "Danger",
|
||||
"error.network_unreachable": "The network is unavailable.",
|
||||
"error.request_timeout": "The request timed out.",
|
||||
"error.auth_required": "Sign in to continue.",
|
||||
|
||||
@@ -79,7 +79,7 @@
|
||||
}
|
||||
|
||||
.ui-button--ghost:hover {
|
||||
color: var(--color-action);
|
||||
color: var(--color-action-hover);
|
||||
background: var(--color-surface-muted);
|
||||
}
|
||||
|
||||
@@ -365,6 +365,11 @@
|
||||
background: var(--color-danger-surface);
|
||||
}
|
||||
|
||||
/* The icon before an Alert or Toast title, in that title's text colour. */
|
||||
.ui-status-tone {
|
||||
margin-inline-end: var(--space-1);
|
||||
}
|
||||
|
||||
.ui-alert__content,
|
||||
.ui-alert__content p {
|
||||
margin-block: var(--space-1) 0;
|
||||
|
||||
@@ -134,7 +134,12 @@ describe("render recovery boundaries", () => {
|
||||
expect(screen.getByRole("alert")).toHaveTextContent(
|
||||
"네트워크 연결을 확인한 뒤 다시 시도해 주세요.",
|
||||
);
|
||||
await user.click(screen.getByRole("button", { name: "다시 시도" }));
|
||||
const retry = screen.getByRole("button", { name: "다시 시도" });
|
||||
// DES-FE-0009. The 44px control rule is the class's; the shell imports
|
||||
// no Button to take it from.
|
||||
expect(retry).toHaveClass("ui-button");
|
||||
expect(retry).not.toHaveClass("ui-button--compact");
|
||||
await user.click(retry);
|
||||
expect(onRetry).toHaveBeenCalledTimes(1);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
import { render, screen, waitFor } from "@testing-library/react";
|
||||
import userEvent from "@testing-library/user-event";
|
||||
import { useState } from "react";
|
||||
import { useEffect, useState } from "react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { Alert } from "../../src/presentation/components/ui/alert.ts";
|
||||
@@ -11,6 +11,14 @@ import { Button } from "../../src/presentation/components/ui/button.ts";
|
||||
import { Card } from "../../src/presentation/components/ui/card.ts";
|
||||
import { Dialog } from "../../src/presentation/components/ui/dialog.ts";
|
||||
import { TextField } from "../../src/presentation/components/ui/text-field.ts";
|
||||
import {
|
||||
ErrorIcon,
|
||||
InfoIcon,
|
||||
SuccessIcon,
|
||||
ToastProvider,
|
||||
useToast,
|
||||
WarningIcon,
|
||||
} from "../../src/presentation/design-system/index.ts";
|
||||
|
||||
describe("domain-neutral UI primitives", () => {
|
||||
it("connects field help and validation errors to the input", () => {
|
||||
@@ -106,3 +114,96 @@ describe("domain-neutral UI primitives", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
// DES-FE-0002. The colour is not the only carrier of a tone: the primitive
|
||||
// draws an icon and says the tone, whatever words the caller put in the title.
|
||||
describe("Alert and Toast tone without colour", () => {
|
||||
const TITLE = "업로드 한도";
|
||||
const TONES = [
|
||||
["info", "정보"],
|
||||
["success", "성공"],
|
||||
["warning", "경고"],
|
||||
["danger", "위험"],
|
||||
] as const;
|
||||
type Tone = (typeof TONES)[number][0];
|
||||
const ICONS = {
|
||||
info: InfoIcon,
|
||||
success: SuccessIcon,
|
||||
warning: WarningIcon,
|
||||
danger: ErrorIcon,
|
||||
} as const;
|
||||
|
||||
function PushToast({ tone }: Readonly<{ tone?: Tone }>) {
|
||||
const { push } = useToast();
|
||||
useEffect(() => push({ id: "tone", title: TITLE, tone }), [push, tone]);
|
||||
return null;
|
||||
}
|
||||
|
||||
async function renderToast(tone?: Tone) {
|
||||
render(
|
||||
<ToastProvider>
|
||||
<PushToast tone={tone} />
|
||||
</ToastProvider>,
|
||||
);
|
||||
return (await screen.findByText(TITLE)).closest("article")!;
|
||||
}
|
||||
|
||||
function toneIcons(surface: HTMLElement) {
|
||||
return [...surface.querySelectorAll('svg[aria-hidden="true"]')].filter(
|
||||
(icon) => !icon.closest("button"),
|
||||
);
|
||||
}
|
||||
|
||||
// What assistive technology reads: the text less what is hidden from it and
|
||||
// less the close button, which has a name of its own.
|
||||
function readText(surface: HTMLElement) {
|
||||
const copy = surface.cloneNode(true) as HTMLElement;
|
||||
for (const unread of copy.querySelectorAll('[aria-hidden="true"], button')) unread.remove();
|
||||
return copy.textContent;
|
||||
}
|
||||
|
||||
// Soft, so that a run names both missing halves.
|
||||
function expectTone(surface: HTMLElement, label: string) {
|
||||
const icons = toneIcons(surface);
|
||||
expect.soft(icons, "a decorative tone icon outside the close button").toHaveLength(1);
|
||||
expect.soft(readText(surface), "the tone in the accessible text").toBe(`${label} ${TITLE}`);
|
||||
if (icons[0]) {
|
||||
expect(icons[0].compareDocumentPosition(screen.getByText(TITLE))).toBe(
|
||||
Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
);
|
||||
expect(screen.getByText(label)).toHaveClass("visually-hidden");
|
||||
}
|
||||
}
|
||||
|
||||
it.each(TONES)("marks a %s Alert with an icon and the label %s", (variant, label) => {
|
||||
render(<Alert onDismiss={vi.fn()} title={TITLE} variant={variant} />);
|
||||
expectTone(screen.getByRole(variant === "danger" ? "alert" : "status"), label);
|
||||
});
|
||||
|
||||
it.each(TONES)("marks a %s Toast with an icon and the label %s", async (tone, label) => {
|
||||
expectTone(await renderToast(tone), label);
|
||||
});
|
||||
|
||||
it("marks a Toast pushed without a tone as info", async () => {
|
||||
expectTone(await renderToast(), "정보");
|
||||
});
|
||||
|
||||
// Four shapes and four labels still hold when two icons trade places.
|
||||
it.each(TONES)("draws the %s icon for that tone", (variant) => {
|
||||
const Icon = ICONS[variant];
|
||||
const expected = render(<Icon />).container.querySelector("svg")!.innerHTML;
|
||||
const { container } = render(<Alert title={TITLE} variant={variant} />);
|
||||
expect(toneIcons(container).map((icon) => icon.innerHTML)).toEqual([expected]);
|
||||
});
|
||||
|
||||
it("gives each tone an icon of its own shape", () => {
|
||||
const { container } = render(
|
||||
<>
|
||||
{TONES.map(([variant]) => (
|
||||
<Alert key={variant} title={TITLE} variant={variant} />
|
||||
))}
|
||||
</>,
|
||||
);
|
||||
expect(new Set(toneIcons(container).map((icon) => icon.innerHTML)).size).toBe(TONES.length);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -129,6 +129,38 @@ for (const lang of ["ko", "en"]) {
|
||||
});
|
||||
}
|
||||
|
||||
// DES-FE-0009. The only control of a boot failure a fresh load can fix.
|
||||
test.describe("a runtime config that cannot be fetched", () => {
|
||||
// The aborted request, and Chromium's console line for it, which names no
|
||||
// URL. Another request that failed would still be recorded with its path.
|
||||
test.use({
|
||||
allowedBrowserFailure:
|
||||
/^(?:requestfailed:GET:\/config\.json:|console:error:Failed to load resource: net::ERR_FAILED$)/u,
|
||||
});
|
||||
|
||||
test("draws the boot retry button at least 44px in both directions at the 320px minimum", async ({
|
||||
page,
|
||||
}) => {
|
||||
await page.route(
|
||||
(url) => url.pathname === "/config.json",
|
||||
(route) => route.abort(),
|
||||
);
|
||||
await page.setViewportSize({ width: 320, height: 720 });
|
||||
await page.goto("/");
|
||||
|
||||
const shell = page.getByRole("alert");
|
||||
await expect(shell).toContainText("CONFIG_FETCH_FAILED");
|
||||
const retry = shell.getByRole("button", { name: "다시 시도" });
|
||||
await expect(retry).toBeVisible();
|
||||
const size = await retry.evaluate((button) => {
|
||||
const { width, height } = button.getBoundingClientRect();
|
||||
return { width, height };
|
||||
});
|
||||
expect.soft(size.height, "retry button height").toBeGreaterThanOrEqual(44);
|
||||
expect.soft(size.width, "retry button width").toBeGreaterThanOrEqual(44);
|
||||
});
|
||||
});
|
||||
|
||||
// 08-01. Below 48rem the header hides the theme selector, the session status
|
||||
// and the brand. WCAG 1.4.10 allows moving them, not dropping them: the menu
|
||||
// drawer carries them. 640px is a 1280px window at 200% zoom.
|
||||
|
||||
@@ -15,10 +15,12 @@ import {
|
||||
rawSemanticColourFailures,
|
||||
rawStyleValueFailures,
|
||||
styleSheetColourFailures,
|
||||
textContrastFailures,
|
||||
tokenRedefinitionFailures,
|
||||
undeclaredComponentTokenFailures,
|
||||
unreadTokenFailures,
|
||||
} from "../../scripts/lib/design-system-rules.ts";
|
||||
import { readCustomProperties } from "../../scripts/lib/oklch-contrast.ts";
|
||||
import {
|
||||
REQUIRED_COMPONENT_TOKENS,
|
||||
REQUIRED_SEMANTIC_TOKENS,
|
||||
@@ -68,6 +70,60 @@ describe("design system rules", { timeout: childProcessTimeout(3_540) }, () => {
|
||||
});
|
||||
});
|
||||
|
||||
// DES-FE-0001. The label of a ghost button is body-size text under the
|
||||
// pointer too.
|
||||
describe("text contrast of a style rule", () => {
|
||||
const selector = ".ui-button--ghost:hover";
|
||||
const palette = new Map([
|
||||
["--blue-600", "oklch(0.55 0.18 255)"],
|
||||
["--blue-700", "oklch(0.48 0.2 255)"],
|
||||
["--slate-100", "oklch(0.94 0.01 247)"],
|
||||
]);
|
||||
const rule = (colour: string) =>
|
||||
css(`@layer components {\n .a, ${selector} { color: ${colour}; background: var(--slate-100); }\n}`);
|
||||
|
||||
it("fails text below 4.5:1", () => {
|
||||
expect(textContrastFailures("light", selector, rule("var(--blue-600)"), palette)).toEqual([
|
||||
`probe.css light ${selector} text contrast 4.14:1 (var(--blue-600) on var(--slate-100)) is below 4.5:1`,
|
||||
]);
|
||||
});
|
||||
|
||||
it("passes text at 4.5:1 or more", () => {
|
||||
expect(textContrastFailures("light", selector, rule("var(--blue-700)"), palette)).toEqual([]);
|
||||
});
|
||||
|
||||
it("draws the line at 4.5:1, failing 4.49:1 and passing 4.51:1", () => {
|
||||
expect(textContrastFailures("light", selector, rule("oklch(0.53 0.18 255)"), palette)).toEqual([
|
||||
`probe.css light ${selector} text contrast 4.49:1 (oklch(0.53 0.18 255) on var(--slate-100)) is below 4.5:1`,
|
||||
]);
|
||||
expect(textContrastFailures("light", selector, rule("oklch(0.529 0.18 255)"), palette)).toEqual([]);
|
||||
});
|
||||
|
||||
it("fails a colour it cannot compute, and a rule that is not there", () => {
|
||||
const supported = "contrast needs an opaque oklch(L C H), hue in degrees with or without deg";
|
||||
expect(textContrastFailures("light", selector, rule("currentColor"), palette)).toEqual([
|
||||
`probe.css light ${selector} color is currentColor; ${supported}`,
|
||||
]);
|
||||
expect(textContrastFailures("light", ".missing:hover", rule("var(--blue-700)"), palette)).toEqual([
|
||||
`probe.css light .missing:hover color is not defined; ${supported}`,
|
||||
]);
|
||||
});
|
||||
|
||||
it.each(["light", "dark"])("passes the repository's ghost hover in the %s theme", async (theme) => {
|
||||
const tokens = "src/presentation/design-system/tokens";
|
||||
const [light, dark = ""] = (await readFile(`${tokens}/semantic.css`, "utf8")).split(':root[data-theme="dark"]');
|
||||
const properties = new Map([
|
||||
...readCustomProperties(await readFile(`${tokens}/primitive.css`, "utf8")),
|
||||
...readCustomProperties(light),
|
||||
...(theme === "dark" ? readCustomProperties(dark) : []),
|
||||
]);
|
||||
const file = "src/presentation/styles/theme/primitives.css";
|
||||
expect(
|
||||
textContrastFailures(theme, selector, { file, source: await readFile(file, "utf8") }, properties),
|
||||
).toEqual([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("UI-02 colour mixing space", () => {
|
||||
it("fails a hue-based mixing space", () => {
|
||||
expect(hueMixFailures(css("a { color: color-mix(in oklch, red, blue); }"))).toEqual([
|
||||
|
||||
BIN
Binary file not shown.
|
Before Width: | Height: | Size: 182 KiB After Width: | Height: | Size: 183 KiB |
Reference in New Issue
Block a user