Files
clean-architecture-frontend…/tests/component/route-status-surfaces.test.tsx
T
DongHyeonkaandClaude Opus 5.5 a8111f7647 fix(features): apply VITE_PRODUCT_FEATURES in the index generator (09-02)
The bundle applied the selection at runtime while Node build scripts and the
context router ignored it, and a typo only failed in the browser. The generator
now imports only the selected features and rejects unknown ids (D-9); declared
ids stay in the index for NOT_INSTALLED reporting. Default build modules are
unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-25 22:29:51 +09:00

216 lines
7.5 KiB
TypeScript

// @vitest-environment jsdom
import { render, screen, waitFor, within } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import { MemoryRouter } from "react-router-dom";
import { describe, expect, it, vi } from "vitest";
import { createAnonymousSessionAdapter } from "../../src/adapters/auth/external-session-adapter.ts";
import type { ApplicationOutputPorts } from "../../src/application/create-application.ts";
import HomePage from "../../src/presentation/pages/home-page.tsx";
import PlatformOverviewPage from "../../src/presentation/examples/platform-overview-page.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";
// Feature-route surfaces run against a test-only feature, not the removable
// sample (FE-GATE-020 runs the suite after deleting the sample).
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 deferred() {
let reject: (error: unknown) => void = () => {};
const promise = new Promise<void>((_, fail) => {
reject = fail;
});
return { promise, reject };
}
function renderApp(
url: string,
overrides: Partial<ApplicationOutputPorts> = {},
basename?: string,
) {
window.history.pushState({}, "", url);
return render(
<ApplicationProvider application={createTestApplication(overrides)}>
<PreferenceProviders>
<AppRouter {...(basename ? { basename } : {})} />
</PreferenceProviders>
</ApplicationProvider>,
);
}
function sessionWithSignIn(beginSignIn: (returnTo?: string) => Promise<void>) {
return { ...createAnonymousSessionAdapter(), beginSignIn };
}
describe("route-level status surfaces", () => {
// First in the file: the home chunk has not been loaded yet, so the route
// suspends and shows its loading surface.
it("shows the busy route loading surface while a page chunk loads", async () => {
renderApp("/");
const copy = screen.getByText("화면을 준비하고 있습니다.");
expect(copy.closest('[aria-busy="true"]')).not.toBeNull();
expect(
await screen.findByRole(
"heading",
{ name: "Clean Architecture Frontend", level: 1 },
{ timeout: 5000 },
),
).toBeVisible();
});
it("keeps the auth-required surface, its pending label and its failure alert", async () => {
const user = userEvent.setup();
const pending = deferred();
const beginSignIn = vi.fn(() => pending.promise);
const { container } = renderApp("/fixture/items#results", {
session: sessionWithSignIn(beginSignIn),
});
const heading = await screen.findByRole(
"heading",
{ name: "세션이 필요합니다.", level: 1 },
{ timeout: 5000 },
);
const surface = container.querySelector(
'[data-surface="authentication-required"]',
);
expect(surface).not.toBeNull();
expect(surface).toContainElement(heading);
await user.click(screen.getByRole("button", { name: "로그인 시작" }));
expect(beginSignIn).toHaveBeenCalledWith(
"/fixture/items#results",
);
expect(screen.getByRole("button", { name: "처리 중…" })).toBeDisabled();
pending.reject(new Error("identity provider unavailable"));
expect(await screen.findByRole("alert")).toHaveTextContent(
"세션 작업을 완료하지 못했습니다.",
);
expect(screen.getByRole("button", { name: "로그인 시작" })).toBeEnabled();
});
it("returns to the current URL with its hash from the shell session action", async () => {
const user = userEvent.setup();
const pending = deferred();
const beginSignIn = vi.fn(() => pending.promise);
renderApp("/examples/ui#buttons", { session: sessionWithSignIn(beginSignIn) });
const banner = screen.getByRole("banner");
await user.click(
await within(banner).findByRole("button", { name: "로그인" }),
);
expect(beginSignIn).toHaveBeenCalledWith("/examples/ui#buttons");
expect(within(banner).getByRole("button", { name: "처리 중…" })).toBeDisabled();
pending.reject(new Error("identity provider unavailable"));
expect(await within(banner).findByRole("alert")).toHaveTextContent(
"세션 작업을 완료하지 못했습니다.",
);
});
it("returns to the current URL with its hash from the auth example page", async () => {
const user = userEvent.setup();
const beginSignIn = vi.fn(async () => {});
renderApp("/examples/auth#session", {
session: sessionWithSignIn(beginSignIn),
});
await user.click(
await screen.findByRole(
"button",
{ name: "로그인 시작" },
{ timeout: 5000 },
),
);
expect(beginSignIn).toHaveBeenCalledWith("/examples/auth#session");
});
it("answers an unknown address with a home link that keeps the basename", async () => {
renderApp("/app/missing", {}, "/app");
const heading = await screen.findByRole(
"heading",
{ name: "페이지를 찾을 수 없습니다.", level: 1 },
{ timeout: 5000 },
);
const page = heading.closest("section");
expect(page).not.toBeNull();
expect(
within(page!).getByRole("link", { name: "홈으로 이동" }),
).toHaveAttribute("href", "/app");
});
});
describe("temporary release loaders", () => {
function failingReleaseApplication() {
return createTestApplication({
releaseInfo: {
getCurrent: async () => {
throw new Error("manifest unavailable");
},
refresh: async () => {
throw new Error("manifest unavailable");
},
},
});
}
it("stops the home page release summary from loading forever", async () => {
window.history.pushState({}, "", "/");
render(
<ApplicationProvider application={failingReleaseApplication()}>
<LocaleProvider>
<AppRouterlessHome />
</LocaleProvider>
</ApplicationProvider>,
);
await waitFor(() =>
expect(
screen.getByText("런타임 정보를 확인하지 못했습니다."),
).toBeVisible(),
);
expect(
screen.queryByText("검증된 런타임 정보를 확인하고 있습니다."),
).not.toBeInTheDocument();
});
it("stops the platform overview release metrics from loading forever", async () => {
render(
<ApplicationProvider application={failingReleaseApplication()}>
<LocaleProvider>
<PlatformOverviewPage />
</LocaleProvider>
</ApplicationProvider>,
);
await waitFor(() =>
expect(
screen.getByText("런타임 정보를 확인하지 못했습니다."),
).toBeVisible(),
);
expect(
screen.queryByText("런타임 정보를 확인하고 있습니다."),
).not.toBeInTheDocument();
});
});
/** HomePage renders router links, so it needs a router but not the app one. */
function AppRouterlessHome() {
return (
<MemoryRouter>
<HomePage />
</MemoryRouter>
);
}