부트 실패 화면의 유일한 조작인 재시도 버튼에 class가 없어 높이가 24px이다. 정적 class ui-button ui-button--primary만 단다. Button을 import하는 안은 버렸다. 깊은 경로는 import 규칙이 막고, 배럴은 규칙을 통과하지만 앱 그래프 없이 떠야 하는 화면의 부트 의존이 는다. 전용 CSS는 같은 규칙이 둘이 되어 버렸다. 한계: 320px에서 높이와 너비만 쟀다. render-error-boundary의 버튼은 DES-FE-0005가 다룬다. 검증: 고치기 전 component 4개와 세 엔진의 e2e(높이 24) 실패, 고친 뒤 component 12개와 responsive spec 27개 통과. Refs: DES-FE-0009
225 lines
7.6 KiB
TypeScript
225 lines
7.6 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 } 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(
|
|
"네트워크 연결을 확인한 뒤 다시 시도해 주세요.",
|
|
);
|
|
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);
|
|
},
|
|
);
|
|
|
|
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">
|
|
<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();
|
|
});
|
|
});
|