refactor(presentation): route status screens share one surface family (Q-6.8-10)
Route-level loading (Suspense fallback, context gateway, chunk check) now renders LoadingSurface, which gains optional visible copy; route-level auth-required, integration-required, invalid-address, disabled-feature, failure and 404 screens render StatusPage, which gains an optional `surface` marker and children slot. Visible copy, h1 headings, data-surface markers and alerts are unchanged; the 404 home link is a router link. The unlabelled context gateway loading now has an accessible name. Session buttons in the shell, the auth-required screen and the auth example share useSessionAction: one pending/failed state and sign-in returns to the current URL including its hash (the auth example dropped the hash). PageActionBar keys actions by position so a pending label does not remount the pressed button. The home and platform overview release loaders now handle a rejected summary instead of showing "checking" forever. Pinned first with tests/component/route-status-surfaces.test.tsx (RED: auth example hash and both loaders; loading, auth-required, shell session and 404 link characterized before the change), plus the lane gates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
a535db6ea1
commit
38db97a564
@@ -3,7 +3,7 @@ import {
|
||||
type ErrorInfo,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { Button } from "../design-system/index.ts";
|
||||
import { Button, LoadingSurface } from "../design-system/index.ts";
|
||||
import { useLocale } from "../i18n/index.ts";
|
||||
|
||||
type RecoveryResult =
|
||||
@@ -99,9 +99,9 @@ function ChunkRecoverySurface({
|
||||
const { message } = useLocale();
|
||||
if (recovery === "checking") {
|
||||
return (
|
||||
<section className="ui-page" aria-live="polite" aria-busy="true">
|
||||
{message("chunk.checking")}
|
||||
</section>
|
||||
<div className="ui-page">
|
||||
<LoadingSurface description={message("chunk.checking")} />
|
||||
</div>
|
||||
);
|
||||
}
|
||||
if (recovery === "reload-requested") {
|
||||
|
||||
@@ -6,9 +6,13 @@ import { useLocale } from "../i18n/index.ts";
|
||||
import { errorMessage } from "./error-copy.ts";
|
||||
import { Button } from "./ui/button.ts";
|
||||
|
||||
export function LoadingSurface({ label }: Readonly<{ label?: string }>) {
|
||||
export function LoadingSurface({
|
||||
label,
|
||||
description,
|
||||
}: Readonly<{ label?: string; description?: string }>) {
|
||||
const { message } = useLocale();
|
||||
const accessibleLabel = label ?? message("async.loading");
|
||||
// Visible copy doubles as the name unless a separate label is given.
|
||||
const accessibleLabel = label ?? description ?? message("async.loading");
|
||||
return (
|
||||
<section
|
||||
className="state-surface state-surface--loading"
|
||||
@@ -18,7 +22,10 @@ export function LoadingSurface({ label }: Readonly<{ label?: string }>) {
|
||||
aria-atomic="true"
|
||||
>
|
||||
<div className="ui-skeleton" aria-hidden="true" />
|
||||
<span className="visually-hidden">{accessibleLabel}</span>
|
||||
{description ? <p>{description}</p> : null}
|
||||
{accessibleLabel === description ? null : (
|
||||
<span className="visually-hidden">{accessibleLabel}</span>
|
||||
)}
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,26 +1,12 @@
|
||||
import { useState } from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
import { PageHeader } from "../design-system/index.ts";
|
||||
import { useSession } from "../providers/session-provider.tsx";
|
||||
import {
|
||||
useSession,
|
||||
useSessionAction,
|
||||
} from "../providers/session-provider.tsx";
|
||||
|
||||
export default function AuthExamplePage() {
|
||||
const location = useLocation();
|
||||
const { sessionState, beginSignIn, signOut, recover } = useSession();
|
||||
const [pending, setPending] = useState(false);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
async function execute(action: () => Promise<unknown>): Promise<void> {
|
||||
setPending(true);
|
||||
setFailed(false);
|
||||
try {
|
||||
await action();
|
||||
} catch {
|
||||
setFailed(true);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
const { sessionState } = useSession();
|
||||
const { pending, failed, run } = useSessionAction();
|
||||
|
||||
return (
|
||||
<section className="ui-page">
|
||||
@@ -41,11 +27,7 @@ export default function AuthExamplePage() {
|
||||
className="ui-button"
|
||||
type="button"
|
||||
disabled={pending || sessionState === "integration-failed"}
|
||||
onClick={() =>
|
||||
void execute(() =>
|
||||
beginSignIn(`${location.pathname}${location.search}`),
|
||||
)
|
||||
}
|
||||
onClick={() => run("sign-in")}
|
||||
>
|
||||
로그인 시작
|
||||
</button>
|
||||
@@ -53,7 +35,7 @@ export default function AuthExamplePage() {
|
||||
className="ui-button ui-button--secondary"
|
||||
type="button"
|
||||
disabled={pending || sessionState !== "authenticated"}
|
||||
onClick={() => void execute(signOut)}
|
||||
onClick={() => run("sign-out")}
|
||||
>
|
||||
로그아웃
|
||||
</button>
|
||||
@@ -61,7 +43,7 @@ export default function AuthExamplePage() {
|
||||
className="ui-button ui-button--secondary"
|
||||
type="button"
|
||||
disabled={pending || sessionState !== "recovery-pending"}
|
||||
onClick={() => void execute(recover)}
|
||||
onClick={() => run("recover")}
|
||||
>
|
||||
세션 복구
|
||||
</button>
|
||||
|
||||
@@ -281,14 +281,19 @@ function buildOperationRows(): readonly OperationRow[] {
|
||||
export default function PlatformOverviewPage() {
|
||||
const runtime = useApplicationRuntime();
|
||||
const [release, setRelease] = useState<
|
||||
Awaited<ReturnType<typeof runtime.getReleaseSummary>> | null
|
||||
Awaited<ReturnType<typeof runtime.getReleaseSummary>> | "failed" | null
|
||||
>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
void runtime.getReleaseSummary().then((summary) => {
|
||||
if (active) setRelease(summary);
|
||||
});
|
||||
runtime.getReleaseSummary().then(
|
||||
(summary) => {
|
||||
if (active) setRelease(summary);
|
||||
},
|
||||
() => {
|
||||
if (active) setRelease("failed");
|
||||
},
|
||||
);
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
@@ -325,7 +330,9 @@ export default function PlatformOverviewPage() {
|
||||
</p>
|
||||
</header>
|
||||
<dl className="platform-metric-grid" aria-live="polite">
|
||||
{release ? (
|
||||
{release === "failed" ? (
|
||||
<Metric label="상태" value="런타임 정보를 확인하지 못했습니다." />
|
||||
) : release ? (
|
||||
<>
|
||||
<Metric label="빌드" value={release.buildId} />
|
||||
<Metric label="릴리스" value={release.releaseId} />
|
||||
|
||||
@@ -21,7 +21,10 @@ import {
|
||||
type MessageKey,
|
||||
} from "../i18n/index.ts";
|
||||
import { useApplicationRuntime } from "../providers/application-provider.tsx";
|
||||
import { useSession } from "../providers/session-provider.tsx";
|
||||
import {
|
||||
useSession,
|
||||
useSessionAction,
|
||||
} from "../providers/session-provider.tsx";
|
||||
import { useTheme } from "../providers/theme-provider.tsx";
|
||||
|
||||
const SESSION_MESSAGE_KEYS = Object.freeze({
|
||||
@@ -33,38 +36,17 @@ const SESSION_MESSAGE_KEYS = Object.freeze({
|
||||
|
||||
export function AppShell() {
|
||||
const location = useLocation();
|
||||
const { sessionState, beginSignIn, signOut, recover } = useSession();
|
||||
const { sessionState } = useSession();
|
||||
const sessionAction = useSessionAction();
|
||||
const { preference, setPreference } = useTheme();
|
||||
const { locale, setLocale, message } = useLocale();
|
||||
const [navigationOpen, setNavigationOpen] = useState(false);
|
||||
const navigationTriggerRef = useRef<HTMLButtonElement | null>(null);
|
||||
const [sessionActionPending, setSessionActionPending] = useState(false);
|
||||
const [sessionActionFailed, setSessionActionFailed] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
setNavigationOpen(false);
|
||||
}, [location.pathname]);
|
||||
|
||||
async function runSessionAction() {
|
||||
setSessionActionPending(true);
|
||||
setSessionActionFailed(false);
|
||||
try {
|
||||
if (sessionState === "authenticated") {
|
||||
await signOut();
|
||||
} else if (sessionState === "recovery-pending") {
|
||||
await recover();
|
||||
} else {
|
||||
await beginSignIn(
|
||||
`${location.pathname}${location.search}${location.hash}`,
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
setSessionActionFailed(true);
|
||||
} finally {
|
||||
setSessionActionPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
const sessionActionLabel =
|
||||
sessionState === "authenticated"
|
||||
? message("action.signOut")
|
||||
@@ -128,17 +110,25 @@ export function AppShell() {
|
||||
</span>
|
||||
{integrationAvailable ? (
|
||||
<Button
|
||||
disabled={sessionActionPending}
|
||||
onClick={() => void runSessionAction()}
|
||||
disabled={sessionAction.pending}
|
||||
onClick={() =>
|
||||
sessionAction.run(
|
||||
sessionState === "authenticated"
|
||||
? "sign-out"
|
||||
: sessionState === "recovery-pending"
|
||||
? "recover"
|
||||
: "sign-in",
|
||||
)
|
||||
}
|
||||
size="compact"
|
||||
>
|
||||
{sessionActionPending
|
||||
{sessionAction.pending
|
||||
? message("common.processing")
|
||||
: sessionActionLabel}
|
||||
</Button>
|
||||
) : null}
|
||||
</div>
|
||||
{sessionActionFailed ? (
|
||||
{sessionAction.failed ? (
|
||||
<p className="app-shell__session-error" role="alert">
|
||||
{message("shell.session.actionFailed")}
|
||||
</p>
|
||||
|
||||
@@ -23,14 +23,19 @@ const READINESS_ITEMS = Object.freeze([
|
||||
export default function HomePage() {
|
||||
const runtime = useApplicationRuntime();
|
||||
const [release, setRelease] = useState<
|
||||
Awaited<ReturnType<typeof runtime.getReleaseSummary>> | null
|
||||
Awaited<ReturnType<typeof runtime.getReleaseSummary>> | "failed" | null
|
||||
>(null);
|
||||
|
||||
useEffect(() => {
|
||||
let active = true;
|
||||
void runtime.getReleaseSummary().then((summary) => {
|
||||
if (active) setRelease(summary);
|
||||
});
|
||||
runtime.getReleaseSummary().then(
|
||||
(summary) => {
|
||||
if (active) setRelease(summary);
|
||||
},
|
||||
() => {
|
||||
if (active) setRelease("failed");
|
||||
},
|
||||
);
|
||||
return () => {
|
||||
active = false;
|
||||
};
|
||||
@@ -52,9 +57,11 @@ export default function HomePage() {
|
||||
))}
|
||||
</div>
|
||||
<p className="ui-runtime-summary" aria-live="polite">
|
||||
{release
|
||||
? `빌드 ${release.buildId} · 릴리스 ${release.releaseId}`
|
||||
: "검증된 런타임 정보를 확인하고 있습니다."}
|
||||
{release === "failed"
|
||||
? "런타임 정보를 확인하지 못했습니다."
|
||||
: release
|
||||
? `빌드 ${release.buildId} · 릴리스 ${release.releaseId}`
|
||||
: "검증된 런타임 정보를 확인하고 있습니다."}
|
||||
</p>
|
||||
<section className="ui-panel starter-actions" aria-labelledby="starter-title">
|
||||
<div>
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
import { Link } from "react-router-dom";
|
||||
|
||||
import { routePath } from "../../features/installed-feature-contracts.ts";
|
||||
import { PageHeader } from "../design-system/index.ts";
|
||||
import { StatusPage } from "../design-system/index.ts";
|
||||
import { useLocale } from "../i18n/index.ts";
|
||||
|
||||
export default function NotFoundPage() {
|
||||
const { message } = useLocale();
|
||||
return (
|
||||
<section className="ui-page">
|
||||
<PageHeader
|
||||
title={message("page.notFound.title")}
|
||||
description={message("page.notFound.description")}
|
||||
/>
|
||||
<div>
|
||||
<Link className="ui-button" to={routePath("APP_HOME")}>
|
||||
{message("action.goHome")}
|
||||
</Link>
|
||||
</div>
|
||||
</section>
|
||||
<StatusPage
|
||||
heading={{
|
||||
title: message("page.notFound.title"),
|
||||
description: message("page.notFound.description"),
|
||||
}}
|
||||
primaryAction={{
|
||||
kind: "link",
|
||||
label: message("action.goHome"),
|
||||
to: routePath("APP_HOME"),
|
||||
}}
|
||||
variant="not-found"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -2,9 +2,11 @@ import {
|
||||
createContext,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
useSyncExternalStore,
|
||||
type ReactNode,
|
||||
} from "react";
|
||||
import { useLocation } from "react-router-dom";
|
||||
|
||||
import type {
|
||||
ApplicationApi,
|
||||
@@ -53,3 +55,36 @@ export function useSession(): SessionContextValue {
|
||||
}
|
||||
return session;
|
||||
}
|
||||
|
||||
export type SessionAction = "sign-in" | "sign-out" | "recover";
|
||||
|
||||
/**
|
||||
* One session action at a time, with the pending and failed state every
|
||||
* session button shows. Sign-in returns to the current URL, hash included.
|
||||
*/
|
||||
export function useSessionAction(): Readonly<{
|
||||
pending: boolean;
|
||||
failed: boolean;
|
||||
run(action: SessionAction): void;
|
||||
}> {
|
||||
const { pathname, search, hash } = useLocation();
|
||||
const { beginSignIn, signOut, recover } = useSession();
|
||||
const [pending, setPending] = useState(false);
|
||||
const [failed, setFailed] = useState(false);
|
||||
|
||||
async function execute(action: SessionAction): Promise<void> {
|
||||
setPending(true);
|
||||
setFailed(false);
|
||||
try {
|
||||
if (action === "sign-out") await signOut();
|
||||
else if (action === "recover") await recover();
|
||||
else await beginSignIn(`${pathname}${search}${hash}`);
|
||||
} catch {
|
||||
setFailed(true);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
return { pending, failed, run: (action) => void execute(action) };
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ import {
|
||||
} from "../boundaries/chunk-recovery-boundary.tsx";
|
||||
import { ContextErrorBoundary } from "../../platform/errors/context-error-boundary.tsx";
|
||||
import { FeatureErrorBoundary } from "../../platform/errors/feature-error-boundary.tsx";
|
||||
import { Button, PageHeader } from "../design-system/index.ts";
|
||||
import { LoadingSurface, StatusPage } from "../design-system/index.ts";
|
||||
import { useLocale } from "../i18n/index.ts";
|
||||
import { AppShell } from "../layouts/app-shell.tsx";
|
||||
import {
|
||||
@@ -49,7 +49,11 @@ import {
|
||||
useApplicationRecovery,
|
||||
useApplicationRuntime,
|
||||
} from "../providers/application-provider.tsx";
|
||||
import { SessionProvider, useSession } from "../providers/session-provider.tsx";
|
||||
import {
|
||||
SessionProvider,
|
||||
useSession,
|
||||
useSessionAction,
|
||||
} from "../providers/session-provider.tsx";
|
||||
import {
|
||||
createRedirectLoopGuard,
|
||||
decideRouteAccess,
|
||||
@@ -63,22 +67,24 @@ import { ROUTE_RUNTIME } from "../../features/installed-feature-runtimes.tsx";
|
||||
import type { ParsedRouteInput } from "./route-contract.ts";
|
||||
import { RouteInputProvider } from "./route-input.tsx";
|
||||
|
||||
function RouteLoadingSurface({ definition }: { definition: RouteDefinition }) {
|
||||
/** Route-level loading: the shared LoadingSurface inside the page frame. */
|
||||
function RouteLoadingSurface({
|
||||
definition,
|
||||
}: Readonly<{ definition?: RouteDefinition }>) {
|
||||
const { message, resolve } = useLocale();
|
||||
const title = resolve(`route.${definition.routeId}.title`);
|
||||
return (
|
||||
<section
|
||||
className="ui-page route-loading"
|
||||
aria-live="polite"
|
||||
aria-busy="true"
|
||||
data-surface={definition.loadingSurface}
|
||||
>
|
||||
<div className="ui-skeleton" aria-hidden="true" />
|
||||
<p>{message("route.loading")}</p>
|
||||
<span className="visually-hidden">
|
||||
{message("route.loadingNamed", { title })}
|
||||
</span>
|
||||
</section>
|
||||
<div className="ui-page route-loading" data-surface={definition?.loadingSurface}>
|
||||
<LoadingSurface
|
||||
description={message("route.loading")}
|
||||
{...(definition
|
||||
? {
|
||||
label: message("route.loadingNamed", {
|
||||
title: resolve(`route.${definition.routeId}.title`),
|
||||
}),
|
||||
}
|
||||
: {})}
|
||||
/>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -89,28 +95,30 @@ function RouteFailureSurface({
|
||||
}) {
|
||||
const { message } = useLocale();
|
||||
return (
|
||||
<section
|
||||
className="ui-page"
|
||||
data-surface={definition?.errorSurface ?? "route-boundary"}
|
||||
>
|
||||
<PageHeader
|
||||
title={message("route.failure.title")}
|
||||
description={message("route.failure.description")}
|
||||
/>
|
||||
</section>
|
||||
<StatusPage
|
||||
heading={{
|
||||
title: message("route.failure.title"),
|
||||
description: message("route.failure.description"),
|
||||
}}
|
||||
surface={definition?.errorSurface ?? "route-boundary"}
|
||||
variant="unexpected"
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
function InvalidRouteSurface({ code }: { code: string }) {
|
||||
const { message } = useLocale();
|
||||
return (
|
||||
<section className="ui-page" data-surface="invalid-route">
|
||||
<PageHeader
|
||||
title={message("route.invalid.title")}
|
||||
description={message("route.invalid.description")}
|
||||
/>
|
||||
<StatusPage
|
||||
heading={{
|
||||
title: message("route.invalid.title"),
|
||||
description: message("route.invalid.description"),
|
||||
}}
|
||||
surface="invalid-route"
|
||||
variant="not-found"
|
||||
>
|
||||
<p data-route-error={code}>{message("route.invalid.action")}</p>
|
||||
</section>
|
||||
</StatusPage>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -122,15 +130,18 @@ function InvalidRouteSurface({ code }: { code: string }) {
|
||||
function DisabledFeatureSurface({ featureId }: { featureId: string }) {
|
||||
const { message } = useLocale();
|
||||
return (
|
||||
<section className="ui-page" data-surface="disabled-feature">
|
||||
<PageHeader
|
||||
title={message("route.disabledFeature.title")}
|
||||
description={message("route.disabledFeature.description")}
|
||||
/>
|
||||
<StatusPage
|
||||
heading={{
|
||||
title: message("route.disabledFeature.title"),
|
||||
description: message("route.disabledFeature.description"),
|
||||
}}
|
||||
surface="disabled-feature"
|
||||
variant="unavailable"
|
||||
>
|
||||
<p data-disabled-feature={featureId}>
|
||||
{message("route.disabledFeature.action")}
|
||||
</p>
|
||||
</section>
|
||||
</StatusPage>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -200,73 +211,57 @@ function ProtectedRoute({
|
||||
routeId: RouteId;
|
||||
children: ReactNode;
|
||||
}) {
|
||||
const location = useLocation();
|
||||
const { sessionState, beginSignIn, recover } = useSession();
|
||||
const { sessionState } = useSession();
|
||||
const { message } = useLocale();
|
||||
const [pending, setPending] = useState(false);
|
||||
const [failed, setFailed] = useState(false);
|
||||
const { pending, failed, run } = useSessionAction();
|
||||
const decision = decideRouteAccess(routeId, sessionState);
|
||||
|
||||
async function continueSession() {
|
||||
setPending(true);
|
||||
setFailed(false);
|
||||
try {
|
||||
if (decision.action === "wait-for-session") {
|
||||
await recover();
|
||||
} else {
|
||||
await beginSignIn(
|
||||
`${location.pathname}${location.search}${location.hash}`,
|
||||
);
|
||||
}
|
||||
} catch {
|
||||
setFailed(true);
|
||||
} finally {
|
||||
setPending(false);
|
||||
}
|
||||
}
|
||||
|
||||
if (decision.allowed) return children;
|
||||
if (sessionState === "integration-failed") {
|
||||
return (
|
||||
<section className="ui-page" data-surface="auth-integration-required">
|
||||
<PageHeader
|
||||
title={message("route.auth.integration.title")}
|
||||
description={message("route.auth.integration.description")}
|
||||
/>
|
||||
</section>
|
||||
<StatusPage
|
||||
heading={{
|
||||
title: message("route.auth.integration.title"),
|
||||
description: message("route.auth.integration.description"),
|
||||
}}
|
||||
surface="auth-integration-required"
|
||||
variant="unavailable"
|
||||
/>
|
||||
);
|
||||
}
|
||||
const recovering = decision.action === "wait-for-session";
|
||||
return (
|
||||
<section className="ui-page" data-surface="authentication-required">
|
||||
<PageHeader
|
||||
title={
|
||||
recovering
|
||||
? message("route.auth.recovering.title")
|
||||
: message("route.auth.required.title")
|
||||
}
|
||||
description={
|
||||
recovering
|
||||
? message("route.auth.recovering.description")
|
||||
: message("route.auth.required.description")
|
||||
}
|
||||
/>
|
||||
<Button
|
||||
disabled={pending}
|
||||
onClick={() => void continueSession()}
|
||||
>
|
||||
{pending
|
||||
<StatusPage
|
||||
heading={
|
||||
recovering
|
||||
? {
|
||||
title: message("route.auth.recovering.title"),
|
||||
description: message("route.auth.recovering.description"),
|
||||
}
|
||||
: {
|
||||
title: message("route.auth.required.title"),
|
||||
description: message("route.auth.required.description"),
|
||||
}
|
||||
}
|
||||
primaryAction={{
|
||||
kind: "button",
|
||||
label: pending
|
||||
? message("common.processing")
|
||||
: recovering
|
||||
? message("action.recoverSession")
|
||||
: message("action.signIn")}
|
||||
</Button>
|
||||
: message("action.signIn"),
|
||||
disabled: pending,
|
||||
onAction: () => run(recovering ? "recover" : "sign-in"),
|
||||
}}
|
||||
surface="authentication-required"
|
||||
variant="unauthenticated"
|
||||
>
|
||||
{failed ? (
|
||||
<p className="ui-terminal-error" role="alert">
|
||||
{message("shell.session.actionFailed")}
|
||||
</p>
|
||||
) : null}
|
||||
</section>
|
||||
</StatusPage>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -402,7 +397,6 @@ function ContextRouteGateway({
|
||||
buildId,
|
||||
}: Readonly<{ routeModule: ContextRouteModule; buildId: string }>) {
|
||||
const location = useLocation();
|
||||
const { message } = useLocale();
|
||||
const recovery = useApplicationRecovery();
|
||||
const [routes, setRoutes] = useState<readonly RouteObject[] | null>(null);
|
||||
const [failure, setFailure] = useState<Readonly<{ error: unknown }> | null>(
|
||||
@@ -451,14 +445,7 @@ function ContextRouteGateway({
|
||||
<RouteFailureSurface />
|
||||
);
|
||||
}
|
||||
if (routes === null) {
|
||||
return (
|
||||
<section className="ui-page route-loading" aria-live="polite" aria-busy="true">
|
||||
<div className="ui-skeleton" aria-hidden="true" />
|
||||
<p>{message("route.loading")}</p>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
if (routes === null) return <RouteLoadingSurface />;
|
||||
|
||||
const selectedMatch = matchRoutes([...routes], location.pathname)?.at(-1);
|
||||
if (!isContextRouteHandle(selectedMatch?.route.handle)) {
|
||||
|
||||
@@ -211,6 +211,10 @@ export function StatusPage(
|
||||
primaryAction?: PageActionDefinition;
|
||||
secondaryAction?: PageActionDefinition;
|
||||
supportReference?: string;
|
||||
/** Names the answer for tests and telemetry, e.g. `invalid-route`. */
|
||||
surface?: string;
|
||||
/** Extra content under the actions, such as a failure alert. */
|
||||
children?: ReactNode;
|
||||
}>,
|
||||
) {
|
||||
const { message } = useLocale();
|
||||
@@ -218,6 +222,7 @@ export function StatusPage(
|
||||
<section
|
||||
className={`ui-page page-template status-page status-page--${props.variant}`}
|
||||
data-status-variant={props.variant}
|
||||
data-surface={props.surface}
|
||||
>
|
||||
<PageHeader {...props.heading} />
|
||||
{props.primaryAction || props.secondaryAction ? (
|
||||
@@ -230,6 +235,7 @@ export function StatusPage(
|
||||
}
|
||||
/>
|
||||
) : null}
|
||||
{props.children}
|
||||
{props.supportReference ? (
|
||||
<p className="status-page__support">
|
||||
{message("template.supportReference", {
|
||||
@@ -247,13 +253,15 @@ function PageActionBar(props: Readonly<{
|
||||
}>) {
|
||||
return (
|
||||
<div className={props.className ?? "page-template__actions"}>
|
||||
{props.actions.map((action) =>
|
||||
{/* Keyed by position: a label that changes while pending must not
|
||||
remount the button the user just pressed. */}
|
||||
{props.actions.map((action, index) =>
|
||||
action.kind === "link" ? (
|
||||
<LinkButton
|
||||
{...(action.to === undefined
|
||||
? { href: action.href }
|
||||
: { to: action.to })}
|
||||
key={`${action.kind}:${action.label}`}
|
||||
key={index}
|
||||
variant={action.variant}
|
||||
>
|
||||
{action.label}
|
||||
@@ -261,7 +269,7 @@ function PageActionBar(props: Readonly<{
|
||||
) : (
|
||||
<Button
|
||||
disabled={action.disabled}
|
||||
key={`${action.kind}:${action.label}`}
|
||||
key={index}
|
||||
onClick={action.onAction}
|
||||
variant={action.variant}
|
||||
>
|
||||
|
||||
@@ -0,0 +1,205 @@
|
||||
// @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";
|
||||
|
||||
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("/examples/reference-resources#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(
|
||||
"/examples/reference-resources#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>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user