Merge branch 'fix/r9-primitive-a11y' into fix/r9-form-and-primitives
frontend-quality-gates / merge / static checks (pull_request) Successful in 2m49s
frontend-quality-gates / merge / tests (pull_request) Successful in 15m8s
frontend-quality-gates / merge / browser tests (pull_request) Successful in 7m8s
frontend-quality-gates / FE-GATE-014 / config-compatibility (pull_request) Skipped
frontend-quality-gates / FE-GATE-028 / manual-accessibility-review (pull_request) Skipped
frontend-quality-gates / FE-GATE-026 / lab-performance (pull_request) Skipped
frontend-quality-gates / FE-GATE-015 / immutable-release-candidate (pull_request) Skipped
frontend-quality-gates / external-vulnerability-provider (pull_request) Skipped
frontend-quality-gates / external-provenance-provider (pull_request) Skipped
frontend-quality-gates / promote-verified-immutable-candidate (pull_request) Skipped
frontend-quality-gates / deploy-promoted-release (pull_request) Skipped
frontend-quality-gates / FE-GATE-019 / hosting-header (pull_request) Skipped
frontend-quality-gates / FE-GATE-021 / runbook-boot-config (pull_request) Skipped
frontend-quality-gates / FE-GATE-022 / runbook-chunk-mismatch (pull_request) Skipped
frontend-quality-gates / FE-GATE-023 / runbook-api-degradation (pull_request) Skipped
frontend-quality-gates / FE-GATE-024 / runbook-telemetry (pull_request) Skipped
frontend-quality-gates / FE-GATE-025 / runbook-release-rollback (pull_request) Skipped
frontend-quality-gates / FE-GATE-018 / field-web-vitals (pull_request) Skipped
frontend-quality-gates / FE-GATE-017 / diagram-review (pull_request) Skipped
frontend-quality-gates / main / self-tests and removal drills (pull_request) Skipped

This commit is contained in:
DongHyeonka
2026-11-13 10:28:11 +09:00
21 changed files with 525 additions and 53 deletions
+270
View File
@@ -0,0 +1,270 @@
// @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";
/**
* 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);
});
});
+11 -1
View File
@@ -5,7 +5,7 @@ import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it } from "vitest";
import { LocaleProvider } from "../../src/presentation/i18n/index.ts";
import { formatMessage, LocaleProvider } from "../../src/presentation/i18n/index.ts";
import HomePage from "../../src/presentation/pages/home-page.tsx";
import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx";
import { PreferenceProviders } from "../../src/presentation/providers/preference-providers.tsx";
@@ -35,6 +35,16 @@ function renderApp(
}
describe("starter home page", () => {
// 1112/05-15. A generic div's aria-label is dropped by assistive technology;
// the readiness list is a named group.
it("names the readiness list as a group", async () => {
renderApp("/");
expect(
await screen.findByRole("group", { name: formatMessage("ko-KR", "home.readiness") }),
).toBeVisible();
});
it("reaches the platform overview from the starter actions", async () => {
const user = userEvent.setup();
renderApp("/");