화면 문구 셋이 어긋난다.
- 상태 화면 문구가 템플릿 개발자용이다(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
280 lines
9.8 KiB
TypeScript
280 lines
9.8 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { act, render, screen, waitFor, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import {
|
|
createAnonymousSessionAdapter,
|
|
createDemoSessionAdapter,
|
|
} from "../../src/adapters/auth/external-session-adapter.ts";
|
|
import type { ApplicationOutputPorts } from "../../src/application/create-application.ts";
|
|
import { INSTALLED_PRODUCT_FEATURE_IDS } from "../../src/features/installed-product-manifest.ts";
|
|
import { ApplicationProvider } from "../../src/presentation/providers/application-provider.tsx";
|
|
import { PreferenceProviders } from "../../src/presentation/providers/preference-providers.tsx";
|
|
import { AppRouter } from "../../src/presentation/routes/app-router.tsx";
|
|
import { createTestApplication } from "../helpers/create-test-application.ts";
|
|
import { createProductFeaturesStub } from "../helpers/runtime-capabilities-stub.ts";
|
|
|
|
// Routes and pages come from a test-only feature, not the removable sample
|
|
// (FE-GATE-020 runs this file after deleting the sample) nor the starter
|
|
// screens a product replaces (0929/10-02; starter-*.test.tsx test those).
|
|
vi.mock("../../src/.generated/product-feature-index.ts", async () => ({
|
|
DECLARED_PRODUCT_FEATURE_IDS: ["fixture-feature"],
|
|
PRODUCT_FEATURE_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_FEATURE_MODULE],
|
|
}));
|
|
vi.mock("../../src/.generated/product-context-index.ts", async () => ({
|
|
PRODUCT_CONTEXT_MODULES: [(await import("../helpers/fixture-feature.tsx")).FIXTURE_CONTEXT_MODULE],
|
|
}));
|
|
|
|
function renderRouter(
|
|
diagnostics: ApplicationOutputPorts["diagnostics"] = { record: () => {} },
|
|
productFeatures?: ApplicationOutputPorts["productFeatures"],
|
|
session: ApplicationOutputPorts["session"] = createAnonymousSessionAdapter(),
|
|
) {
|
|
return render(
|
|
<ApplicationProvider
|
|
application={createTestApplication({
|
|
session,
|
|
diagnostics,
|
|
...(productFeatures ? { productFeatures } : {}),
|
|
})}
|
|
>
|
|
<PreferenceProviders>
|
|
<AppRouter />
|
|
</PreferenceProviders>
|
|
</ApplicationProvider>,
|
|
);
|
|
}
|
|
|
|
/** A back/forward style navigation that leaves focus where the user left it. */
|
|
function navigateByHistory(url: string) {
|
|
act(() => {
|
|
window.history.pushState({}, "", url);
|
|
window.dispatchEvent(new PopStateEvent("popstate"));
|
|
});
|
|
}
|
|
|
|
function routeChangeReports(record: ReturnType<typeof vi.fn>) {
|
|
return record.mock.calls.filter(
|
|
([event]) => (event as { eventId: string }).eventId === "route.changed",
|
|
).length;
|
|
}
|
|
|
|
describe("generic application router", () => {
|
|
it("renders the app shell and not-found route without a feature input", async () => {
|
|
window.history.pushState({}, "", "/missing");
|
|
renderRouter();
|
|
|
|
expect(
|
|
await screen.findByRole("heading", {
|
|
name: "페이지를 찾을 수 없습니다.",
|
|
}),
|
|
).toBeVisible();
|
|
expect(screen.getByRole("navigation", { name: "주요 탐색" })).toBeVisible();
|
|
expect(screen.getByRole("main")).toBeVisible();
|
|
});
|
|
|
|
it("navigates between registry-backed routes", async () => {
|
|
const user = userEvent.setup();
|
|
window.history.pushState({}, "", "/");
|
|
renderRouter();
|
|
|
|
await user.click(
|
|
await screen.findByRole("link", { name: "Fixture first page" }),
|
|
);
|
|
|
|
expect(
|
|
await screen.findByRole("heading", { name: "Fixture first page", level: 1 }),
|
|
).toBeVisible();
|
|
expect(window.location.pathname).toBe("/fixture/first");
|
|
await waitFor(() =>
|
|
expect(document.title).toBe("Fixture first page · Frontend Skeleton"),
|
|
);
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByRole("heading", { name: "Fixture first page", level: 1 }),
|
|
).toHaveFocus(),
|
|
);
|
|
});
|
|
|
|
it("changes only the title and copy when the locale changes", async () => {
|
|
// docs/design/2026-07-26-routing-pages-and-patterns-design.md §9: a locale change
|
|
// re-renders the document title and copy; it is not a route change.
|
|
const user = userEvent.setup();
|
|
const record = vi.fn();
|
|
window.history.pushState({}, "", "/missing");
|
|
renderRouter({ record });
|
|
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByRole("heading", {
|
|
name: "페이지를 찾을 수 없습니다.",
|
|
level: 1,
|
|
}),
|
|
).toHaveFocus(),
|
|
);
|
|
const reportsBefore = routeChangeReports(record);
|
|
expect(reportsBefore).toBeGreaterThan(0);
|
|
|
|
const localeSelect = screen.getByLabelText("언어");
|
|
await user.selectOptions(localeSelect, "en-US");
|
|
|
|
await waitFor(() =>
|
|
expect(document.title).toBe("Page not found. · Frontend Skeleton"),
|
|
);
|
|
expect(
|
|
screen.getByRole("heading", { name: "Page not found.", level: 1 }),
|
|
).toBeVisible();
|
|
expect(localeSelect).toHaveFocus();
|
|
expect(routeChangeReports(record)).toBe(reportsBefore);
|
|
});
|
|
|
|
it.each([
|
|
{
|
|
surface: "authentication-required",
|
|
url: "/fixture/items",
|
|
routeId: "FIXTURE_ITEMS",
|
|
title: "Fixture items · Frontend Skeleton",
|
|
disableFeature: false,
|
|
},
|
|
{
|
|
surface: "invalid-route",
|
|
url: "/fixture/items?limit=invalid",
|
|
routeId: "FIXTURE_ITEMS",
|
|
title: "Fixture items · Frontend Skeleton",
|
|
disableFeature: false,
|
|
},
|
|
{
|
|
surface: "disabled-feature",
|
|
url: "/fixture/items",
|
|
routeId: "FIXTURE_ITEMS",
|
|
title: "Fixture items · Frontend Skeleton",
|
|
disableFeature: true,
|
|
},
|
|
])(
|
|
"runs the route lifecycle on the $surface surface",
|
|
async ({ surface, url, routeId, title, disableFeature }) => {
|
|
const record = vi.fn();
|
|
window.history.pushState({}, "", "/");
|
|
const { container } = renderRouter(
|
|
{ record },
|
|
disableFeature
|
|
? createProductFeaturesStub({
|
|
[INSTALLED_PRODUCT_FEATURE_IDS[0]!]: "DISABLED_BY_CONFIG",
|
|
})
|
|
: undefined,
|
|
);
|
|
const link = within(
|
|
await screen.findByRole("navigation", { name: "주요 탐색" }),
|
|
).getAllByRole("link")[0]!;
|
|
link.focus();
|
|
|
|
navigateByHistory(url);
|
|
|
|
await waitFor(
|
|
() =>
|
|
expect(
|
|
container.querySelector(`[data-surface="${surface}"]`),
|
|
).not.toBeNull(),
|
|
);
|
|
await waitFor(() => expect(document.title).toBe(title));
|
|
expect(
|
|
screen.getByRole("main").contains(document.activeElement),
|
|
).toBe(true);
|
|
expect(record).toHaveBeenCalledWith(
|
|
expect.objectContaining({
|
|
eventId: "route.changed",
|
|
context: expect.objectContaining({ route_id: routeId }),
|
|
}),
|
|
);
|
|
},
|
|
);
|
|
|
|
it("keeps focus and scroll on a control that changes only the URL query", async () => {
|
|
// 08-02. A list filter bound to the query is input on the same screen
|
|
// (WCAG 3.2.2), not a route change: focus stays on the control and no
|
|
// second route.changed is reported.
|
|
const user = userEvent.setup();
|
|
const record = vi.fn();
|
|
window.history.pushState({}, "", "/fixture/items");
|
|
renderRouter({ record }, undefined, createDemoSessionAdapter("authenticated"));
|
|
|
|
const filter = await screen.findByLabelText("Fixture limit");
|
|
await waitFor(() => expect(routeChangeReports(record)).toBe(1));
|
|
await user.selectOptions(filter, "50");
|
|
|
|
await waitFor(() => expect(window.location.search).toBe("?limit=50"));
|
|
expect(filter).toHaveValue("50");
|
|
expect(filter).toHaveFocus();
|
|
expect(routeChangeReports(record)).toBe(1);
|
|
});
|
|
|
|
it("leaves focus on a link that names the page already shown", async () => {
|
|
// 08-02. React Router turns a link to the current URL into a REPLACE; the
|
|
// navigation type changes but the screen does not.
|
|
const user = userEvent.setup();
|
|
const record = vi.fn();
|
|
window.history.pushState({}, "", "/fixture/first");
|
|
renderRouter({ record });
|
|
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByRole("heading", { name: "Fixture first page", level: 1 }),
|
|
).toHaveFocus(),
|
|
);
|
|
const reportsBefore = routeChangeReports(record);
|
|
const link = within(
|
|
screen.getByRole("navigation", { name: "주요 탐색" }),
|
|
).getByRole("link", { name: "Fixture first page" });
|
|
await user.click(link);
|
|
|
|
expect(link).toHaveFocus();
|
|
expect(routeChangeReports(record)).toBe(reportsBefore);
|
|
});
|
|
|
|
it("ignores unknown query parameters on a route without a search codec and keeps the URL", async () => {
|
|
// D-16: `/?utm_source=x` or an OAuth callback parameter is not an invalid
|
|
// address. The `none` codec drops it from the parsed input only.
|
|
window.history.pushState({}, "", "/fixture/first?utm_source=mail#top");
|
|
const { container } = renderRouter();
|
|
|
|
expect(
|
|
await screen.findByRole(
|
|
"heading",
|
|
{ name: "Fixture first page", level: 1 },
|
|
),
|
|
).toBeVisible();
|
|
expect(container.querySelector('[data-surface="invalid-route"]')).toBeNull();
|
|
await waitFor(() =>
|
|
expect(document.title).toBe("Fixture first page · Frontend Skeleton"),
|
|
);
|
|
expect(`${window.location.pathname}${window.location.search}`).toBe(
|
|
"/fixture/first?utm_source=mail",
|
|
);
|
|
});
|
|
|
|
it("focuses the route heading again when the lazy chunk is already cached", async () => {
|
|
// §9.7. The first visit resolves the route module asynchronously, so the
|
|
// router lifecycle and the page header commit separately. A later visit
|
|
// renders the cached module in the same commit, which is the ordering that
|
|
// must still hand focus to the heading rather than leaving it on main.
|
|
const user = userEvent.setup();
|
|
window.history.pushState({}, "", "/");
|
|
renderRouter();
|
|
|
|
for (const label of [
|
|
"Fixture first page",
|
|
"Fixture second page",
|
|
"Fixture first page",
|
|
]) {
|
|
await user.click(await screen.findByRole("link", { name: label }));
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.getByRole("heading", { name: label, level: 1 }),
|
|
).toHaveFocus(),
|
|
);
|
|
}
|
|
});
|
|
});
|