문제: 지원 locale 목록, 언어 대체, 글 방향, 문구 표, 셸의 언어 선택지가 템플릿 파일 다섯 곳에 손으로 적혀 있다. 한 언어 제품은 가짜 en-US 문구를 만들거나 템플릿 파일을 고쳐야 하고, 운영 셸 메뉴에 Pseudo·RTL 시험 locale이 보인다(0929/08-01). 고른 방법(1101 결정 (가), 템플릿이 확장 지점을 연다): - 제품 소유 src/contracts/product-contracts.ts에 PRODUCT_LOCALES (기본 ko-KR, en-US)와 DEV_LOCALES(기본 en-XA, ar-EG)를 둔다. - message-contract가 둘에서 SUPPORTED_LOCALES, 언어 대체(같은 언어의 첫 선언 locale, 없으면 첫 제품 locale), 글 방향(RTL 언어 집합), DEFAULT_LOCALE을 만든다. 시험 locale은 en-US 문구를, en-US가 없으면 첫 제품 locale 문구를 보인다. - catalog.ts는 선언한 제품 locale마다 문구 표 하나를 둔다. en-US 표는 en-US를 선언했을 때만 모든 키를 요구한다. - 셸 언어 선택지는 선언에서 나오고, locale이 하나면 선택을 그리지 않는다. 템플릿 문구에 없는 locale은 Intl.DisplayNames의 자기 이름으로 적는다. 버린 대안: 운영 환경(APP_ENV)에서 시험 locale을 자동으로 숨기기 — presentation이 실행 환경을 읽는 포트가 없고, e2e가 production 빌드로 시험 locale을 고른다. 제품이 DEV_LOCALES를 비우는 쪽이 명시적이다. 위험·한계: ko-KR은 다른 표를 대조하는 원본이라 남겨야 한다. 템플릿에 없는 언어를 선언하면 그 문구 표가 catalog.ts에 있어야 한다(타입 오류로 알린다). 시험 locale을 빼는 것은 제품이 DEV_LOCALES를 비울 때다. 검증: desktop 결과는 PR 본문. Refs: 0929/08-01
220 lines
7.5 KiB
TypeScript
220 lines
7.5 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { render, screen } from "@testing-library/react";
|
|
import type { ReactNode } from "react";
|
|
import userEvent from "@testing-library/user-event";
|
|
import { describe, expect, it, vi } from "vitest";
|
|
|
|
import { createFailure } from "../../src/contracts/errors.ts";
|
|
import { deriveAsyncState } from "../../src/application/view-models/async-state.ts";
|
|
import { AsyncSurface } from "../../src/presentation/components/async-surface.tsx";
|
|
import { BootErrorShell } from "../../src/presentation/boundaries/boot-error-shell.tsx";
|
|
import { FeatureBoundary } from "../../src/presentation/boundaries/render-error-boundary.tsx";
|
|
import { LocaleProvider, type SupportedLocale } from "../../src/presentation/i18n/index.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";
|
|
|
|
// The test-only feature's broken page stands in for any route page with a
|
|
// programmer defect; the starter screens are the product's to replace
|
|
// (0929/10-02).
|
|
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 Defect(): ReactNode {
|
|
throw new Error("raw render stack");
|
|
}
|
|
|
|
describe("render recovery boundaries", () => {
|
|
it("catches programmer defects and emits best-effort safe telemetry", () => {
|
|
const onRenderFailure = vi.fn();
|
|
render(
|
|
<FeatureBoundary
|
|
routeId="APP_HOME"
|
|
buildId="build-a"
|
|
onRenderFailure={onRenderFailure}
|
|
>
|
|
<Defect />
|
|
</FeatureBoundary>,
|
|
);
|
|
|
|
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
"화면을 표시하지 못했습니다.",
|
|
);
|
|
expect(onRenderFailure).toHaveBeenCalledWith({
|
|
routeId: "APP_HOME",
|
|
buildId: "build-a",
|
|
boundaryName: "feature",
|
|
incidentId: expect.stringMatching(/^[0-9a-f]{8}$/),
|
|
});
|
|
});
|
|
|
|
// 08-07. The route failure page shows the reference the user quotes, the
|
|
// same id the render diagnostic records, and a way out besides the URL.
|
|
it("shows a route render failure's support reference and records it", async () => {
|
|
const record = vi.fn();
|
|
window.history.pushState({}, "", "/fixture/broken");
|
|
render(
|
|
<ApplicationProvider
|
|
application={createTestApplication({ diagnostics: { record } })}
|
|
>
|
|
<PreferenceProviders>
|
|
<AppRouter buildId="build-a" />
|
|
</PreferenceProviders>
|
|
</ApplicationProvider>,
|
|
);
|
|
|
|
const reference = await screen.findByText(/^지원 참조: build-a:[0-9a-f]{8}$/);
|
|
const incidentId = reference.textContent?.split(":").at(-1);
|
|
expect(record).toHaveBeenCalledWith({
|
|
level: "error",
|
|
eventId: "ui.render.failed",
|
|
context: expect.objectContaining({
|
|
route_id: "FIXTURE_BROKEN_PAGE",
|
|
build_id: "build-a",
|
|
correlation_id: incidentId,
|
|
}),
|
|
});
|
|
expect(screen.getByRole("button", { name: "한 번 새로고침" })).toBeVisible();
|
|
});
|
|
|
|
it("keeps normalized operational failures in normal async state", () => {
|
|
const state = deriveAsyncState({
|
|
failure: createFailure("SERVER_FAILURE", "LIST", 0),
|
|
});
|
|
render(
|
|
<FeatureBoundary routeId="APP_HOME" buildId="build-a">
|
|
<AsyncSurface state={state} />
|
|
</FeatureBoundary>,
|
|
);
|
|
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
"요청을 완료하지 못했습니다.",
|
|
);
|
|
expect(screen.getByRole("alert")).toHaveAttribute(
|
|
"data-message-key",
|
|
"error.server_failure",
|
|
);
|
|
});
|
|
|
|
it("renders a safe boot shell with no endpoint or stack", () => {
|
|
render(
|
|
<BootErrorShell
|
|
kind="BOOT_CONFIG_FAILURE"
|
|
code="CONFIG_SCHEMA_INVALID"
|
|
buildId="build-a"
|
|
configSchemaVersion="1"
|
|
supportReference="build-a:CONFIG_SCHEMA_INVALID"
|
|
/>,
|
|
);
|
|
const shell = screen.getByRole("alert");
|
|
expect(shell).toHaveTextContent("build-a:CONFIG_SCHEMA_INVALID");
|
|
expect(shell).not.toHaveTextContent("https://");
|
|
expect(shell).not.toHaveTextContent("stack");
|
|
});
|
|
|
|
it.each(["CONFIG_FETCH_FAILED", "CONFIG_TIMEOUT", "MANIFEST_FETCH_FAILED", "MANIFEST_TIMEOUT"])(
|
|
"offers a retry for the network failure %s (09-10)",
|
|
async (code) => {
|
|
const onRetry = vi.fn();
|
|
const user = userEvent.setup();
|
|
render(
|
|
<BootErrorShell
|
|
kind="BOOT_CONFIG_FAILURE"
|
|
code={code}
|
|
supportReference={`build-a:${code}`}
|
|
onRetry={onRetry}
|
|
/>,
|
|
);
|
|
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
"네트워크 연결을 확인한 뒤 다시 시도해 주세요.",
|
|
);
|
|
await user.click(screen.getByRole("button", { name: "다시 시도" }));
|
|
expect(onRetry).toHaveBeenCalledTimes(1);
|
|
},
|
|
);
|
|
|
|
it("offers no retry for a failure a reload cannot fix (09-10)", () => {
|
|
render(
|
|
<BootErrorShell
|
|
kind="BOOT_CONFIG_FAILURE"
|
|
code="CONFIG_SCHEMA_INVALID"
|
|
supportReference="build-a:CONFIG_SCHEMA_INVALID"
|
|
onRetry={() => {}}
|
|
/>,
|
|
);
|
|
expect(screen.queryByRole("button")).toBeNull();
|
|
});
|
|
|
|
it("allows a boundary reset action without reloading the page", async () => {
|
|
let shouldThrow = true;
|
|
function Recoverable() {
|
|
if (shouldThrow) throw new Error("defect");
|
|
return <p>recovered</p>;
|
|
}
|
|
const user = userEvent.setup();
|
|
const view = render(
|
|
<FeatureBoundary routeId="APP_HOME" buildId="build-a">
|
|
<Recoverable />
|
|
</FeatureBoundary>,
|
|
);
|
|
shouldThrow = false;
|
|
await user.click(screen.getByRole("button", { name: "다시 시도" }));
|
|
view.rerender(
|
|
<FeatureBoundary routeId="APP_HOME" buildId="build-a">
|
|
<Recoverable />
|
|
</FeatureBoundary>,
|
|
);
|
|
expect(screen.getByText("recovered")).toBeVisible();
|
|
});
|
|
|
|
it("resets a route failure when the registered location key changes", async () => {
|
|
let shouldThrow = true;
|
|
function RouteContent() {
|
|
if (shouldThrow) throw new Error("route defect");
|
|
return <p>next route</p>;
|
|
}
|
|
const view = render(
|
|
<FeatureBoundary
|
|
routeId="APP_HOME"
|
|
buildId="build-a"
|
|
resetKey="/first"
|
|
>
|
|
<RouteContent />
|
|
</FeatureBoundary>,
|
|
);
|
|
expect(screen.getByRole("alert")).toBeVisible();
|
|
|
|
shouldThrow = false;
|
|
view.rerender(
|
|
<FeatureBoundary
|
|
routeId="APP_HOME"
|
|
buildId="build-a"
|
|
resetKey="/second"
|
|
>
|
|
<RouteContent />
|
|
</FeatureBoundary>,
|
|
);
|
|
expect(await screen.findByText("next route")).toBeVisible();
|
|
});
|
|
|
|
it("renders the default fallback in the current locale", () => {
|
|
render(
|
|
<LocaleProvider initialLocale={"en-US" as string as SupportedLocale}>
|
|
<FeatureBoundary routeId="APP_HOME" buildId="build-a">
|
|
<Defect />
|
|
</FeatureBoundary>
|
|
</LocaleProvider>,
|
|
);
|
|
expect(screen.getByRole("alert")).toHaveTextContent(
|
|
"The page could not be displayed.",
|
|
);
|
|
expect(screen.getByRole("button", { name: "Try again" })).toBeVisible();
|
|
});
|
|
});
|