Files
DongHyeonka d42ad073ee fix(i18n): 상태 화면 문구를 최종 사용자 말로 쓰고 숫자·단수형·문장 조립을 catalog에 맡긴다
화면 문구 셋이 어긋난다.
- 상태 화면 문구가 템플릿 개발자용이다(04-01). 생성 기능은 모두
  `session-required`라 로그인 전 최종 사용자에게 "이 화면은 인증 연동 지점을
  확인하기 위한 보호 라우트입니다."가 보인다. 끈 기능 화면은 "코드에는
  포함되어 있으며 운영자가 다시 켤 수 있습니다.", 연동 실패 화면은 "외부 인증
  소유자가 연결되면…"이다.
- 숫자를 locale formatter 없이 그린다(04-03). 생성 목록이 "총 12345개 항목"을
  그리고, TextArea는 en에서 남은 1자도 "1 characters remaining"이다.
- ko·en 뜻이 다르다(04-07). en `form.conflict`에 "최신 상태를 확인해 주세요"가
  없고, en 문서 제목 "Page not found"와 h1 "Page not found."가 다르다.
  ErrorSummary가 번역 문장 사이에 JSX 글자 ": "를 넣는다.

고른 방법: 세 설명을 사용자 말("이 화면을 보려면 로그인해 주세요." 등)로 바꾸고
운영 설명은 뺐다. 생성 목록은 `useLocale().number(total)`을 넘긴다. TextArea는
`plural`로 `form.remaining.one`(en 단수)과 `form.remaining`을 고른다. en 충돌
문구에 행동을 더하고 not-found 제목을 h1과 같게 했다. 오류 요약 항목은
`form.errorSummary.item` "{label}: {message}"로 잇는다. 연동 실패 화면의 제목
"로그인 연동이 필요합니다."는 짝 백엔드 매뉴얼이 그 글자로 가리켜 그대로 뒀다.
검증 V4가 반박한 부분(세 화면에 행동 버튼이 없다, ProgressBar `%`)은 고치지
않았다: 셸 탐색이 늘 있고, `%`는 ko·en 결과가 같다.

위험·한계: 다운스트림이 이 키의 옛 문장을 시험으로 고정했으면 문장을 바꾼다.
이미 생성한 기능의 목록 페이지는 `count: query.data.total`을 그대로 갖는다.
`number(query.data.total)`로 바꾸면 된다(생성 명령의 새 출력과 같다).

검증: `tests/unit/i18n-contract.test.ts`(개발자 낱말, not-found 제목, 항목
문장), `tests/component/design-system-a11y.test.tsx`(en 단수·복수),
`tests/unit/create-feature.test.ts`(생성 목록의 `number(`)가 고치기 전에
실패하고 고친 뒤 통과한다. 생성 기능 시험의 total 12345 → "총 12,345개 항목"은
FE-GATE-005가 돌린다(desktop, PR 본문).

Refs: 1112/04-01, 1112/04-03, 1112/04-07
2026-11-13 19:03:18 +09:00

295 lines
9.4 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { useState } from "react";
import { describe, expect, it, vi } from "vitest";
import {
Button,
Checkbox,
Dialog,
Menu,
Popover,
SearchField,
TextArea,
ToastProvider,
Tooltip,
useToast,
} from "../../src/presentation/design-system/index.ts";
import { LocaleProvider } from "../../src/presentation/i18n/index.ts";
/**
* 1112/05-10, 05-11, 05-13, 05-14, 05-17. What the shared primitives promise
* a keyboard and screen reader user (docs/design/2026-07-26-design-system-platform-design.md
* 8.1·8.2절, WCAG 2.2 AA): a named dialog, Escape that closes the innermost
* layer only, required shown both ways, focus that does not fall to the body,
* and a counter that is not announced on every key.
*/
function DialogWith({ onClose, children }: Readonly<{ onClose(): void; children: React.ReactNode }>) {
return (
<Dialog open onClose={onClose} title="설정">
{children}
</Dialog>
);
}
describe("Popover", () => {
it("names its dialog after the trigger", async () => {
const user = userEvent.setup();
render(
<Popover triggerLabel="설명 열기">
<Button>내부 작업</Button>
</Popover>,
);
await user.click(screen.getByRole("button", { name: "설명 열기" }));
expect(screen.getByRole("dialog", { name: "설명 열기" })).toBeVisible();
});
});
describe("Escape inside a Dialog", () => {
it("closes an open Popover and keeps the Dialog", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(
<DialogWith onClose={onClose}>
<Popover triggerLabel="설명 열기">
<Button>내부 작업</Button>
</Popover>
</DialogWith>,
);
await user.click(screen.getByRole("button", { name: "설명 열기" }));
await user.click(screen.getByRole("button", { name: "내부 작업" }));
await user.keyboard("{Escape}");
expect(screen.queryByRole("button", { name: "내부 작업" })).not.toBeInTheDocument();
expect(screen.getByRole("button", { name: "설명 열기" })).toHaveFocus();
expect(onClose).not.toHaveBeenCalled();
});
it("closes an open Menu and keeps the Dialog", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(
<DialogWith onClose={onClose}>
<Menu triggerLabel="더 보기" items={[{ id: "copy", label: "복사", onSelect: () => {} }]} />
</DialogWith>,
);
await user.click(screen.getByRole("button", { name: "더 보기" }));
expect(screen.getByRole("menu")).toBeVisible();
await user.keyboard("{Escape}");
expect(screen.queryByRole("menu")).not.toBeInTheDocument();
expect(onClose).not.toHaveBeenCalled();
});
it("hides a shown Tooltip and keeps the Dialog", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(
<DialogWith onClose={onClose}>
<Tooltip content="자세한 설명">
<Button>도움말</Button>
</Tooltip>
</DialogWith>,
);
await user.hover(screen.getByRole("button", { name: "도움말" }));
await user.keyboard("{Escape}");
expect(screen.getByRole("tooltip", { hidden: true })).not.toBeVisible();
expect(onClose).not.toHaveBeenCalled();
});
// round9 confirm review. A popover or tooltip left open outside a Dialog
// does not take the Dialog's Escape: the Escape belongs to the Dialog it
// was pressed in.
it.each([
[
"a Popover",
(
<Popover key="layer" triggerLabel="설명 열기">
<Button>내부 작업</Button>
</Popover>
),
(user: ReturnType<typeof userEvent.setup>) => user.click(screen.getByRole("button", { name: "설명 열기" })),
],
[
"a Tooltip",
(
<Tooltip key="layer" content="자세한 설명">
<Button>도움말</Button>
</Tooltip>
),
(user: ReturnType<typeof userEvent.setup>) => user.hover(screen.getByRole("button", { name: "도움말" })),
],
])("closes the Dialog when %s outside it is open", async (_label, layer, openLayer) => {
const user = userEvent.setup();
const onClose = vi.fn();
render(
<>
{layer}
<DialogWith onClose={onClose}>
<Button>안쪽 버튼</Button>
</DialogWith>
</>,
);
await openLayer(user);
screen.getByRole("button", { name: "안쪽 버튼" }).focus();
await user.keyboard("{Escape}");
expect(onClose).toHaveBeenCalledTimes(1);
});
// WebKit does not focus a clicked button: an Escape with focus on the body
// still closes the open Popover.
it("closes an open Popover on an Escape from the body", async () => {
const user = userEvent.setup();
render(
<Popover triggerLabel="설명 열기">
<Button>내부 작업</Button>
</Popover>,
);
await user.click(screen.getByRole("button", { name: "설명 열기" }));
(document.activeElement as HTMLElement | null)?.blur();
await user.keyboard("{Escape}");
expect(screen.queryByRole("button", { name: "내부 작업" })).not.toBeInTheDocument();
});
it("closes the Dialog when no inner layer is open", async () => {
const user = userEvent.setup();
const onClose = vi.fn();
render(
<DialogWith onClose={onClose}>
<Button>안쪽 버튼</Button>
</DialogWith>,
);
screen.getByRole("button", { name: "안쪽 버튼" }).focus();
await user.keyboard("{Escape}");
expect(onClose).toHaveBeenCalledTimes(1);
});
});
describe("required fields", () => {
it("marks a required SearchField both on the input and with the symbol", () => {
render(<SearchField label="검색" required value="" onChange={() => {}} clearLabel="지우기" onClear={() => {}} />);
expect(screen.getByRole("searchbox", { name: /검색/u })).toBeRequired();
expect(screen.getByText("*", { exact: false })).toHaveAttribute("aria-hidden", "true");
});
it("marks a required Checkbox both on the input and with the symbol", () => {
render(<Checkbox label="약관에 동의" required />);
const checkbox = screen.getByRole("checkbox", { name: /약관에 동의/u });
expect(checkbox).toBeRequired();
const label = checkbox.closest("label");
if (!label) throw new Error("expected the checkbox label");
expect(within(label).getByText("*", { exact: false })).toHaveAttribute("aria-hidden", "true");
});
});
describe("Toast focus when it is closed", () => {
function Harness({ count }: Readonly<{ count: number }>) {
const toast = useToast();
return (
<Button
onClick={() => {
for (let index = 0; index < count; index += 1) {
toast.push({ id: `toast-${index}`, title: `알림 ${index}`, durationMs: 60_000 });
}
}}
>
알림 보이기
</Button>
);
}
it("moves focus to the next toast's close button", async () => {
const user = userEvent.setup();
render(
<ToastProvider>
<Harness count={2} />
</ToastProvider>,
);
await user.click(screen.getByRole("button", { name: "알림 보이기" }));
const [first] = screen.getAllByRole("button", { name: /닫기/u });
if (!first) throw new Error("expected two close buttons");
first.focus();
await user.click(first);
expect(document.activeElement).not.toBe(document.body);
expect(document.activeElement).toBe(screen.getByRole("button", { name: /닫기/u }));
});
it("returns focus to where it was before the last toast took it", async () => {
const user = userEvent.setup();
render(
<ToastProvider>
<Harness count={1} />
</ToastProvider>,
);
const trigger = screen.getByRole("button", { name: "알림 보이기" });
await user.click(trigger);
await user.tab();
const close = screen.getByRole("button", { name: /닫기/u });
expect(close).toHaveFocus();
await user.keyboard("{Enter}");
expect(screen.queryByRole("article")).not.toBeInTheDocument();
expect(trigger).toHaveFocus();
});
});
describe("TextArea counter", () => {
it("describes the field without announcing every key", async () => {
const user = userEvent.setup();
function Controlled() {
const [value, setValue] = useState("");
return <TextArea label="메모" maxLength={30} value={value} onChange={(event) => setValue(event.currentTarget.value)} />;
}
render(<Controlled />);
const field = screen.getByRole("textbox", { name: "메모" });
await user.type(field, "가나다");
expect(screen.queryByRole("status")).not.toBeInTheDocument();
expect(field).toHaveAccessibleDescription(/27/u);
});
// 1112/04-03. The count picks the locale's singular and plural forms.
it("uses the singular form for one character left in English", () => {
render(
<LocaleProvider initialLocale="en-US">
<TextArea label="Note" maxLength={5} defaultValue="abcd" />
</LocaleProvider>,
);
expect(screen.getByRole("textbox", { name: "Note" })).toHaveAccessibleDescription(
"1 character remaining",
);
});
it("keeps the plural form for other counts", () => {
render(
<LocaleProvider initialLocale="en-US">
<TextArea label="Note" maxLength={5} defaultValue="abc" />
</LocaleProvider>,
);
expect(screen.getByRole("textbox", { name: "Note" })).toHaveAccessibleDescription(
"2 characters remaining",
);
});
});