fix(presentation): draw query access failures with the access surfaces (08-11)

AsyncSurface drew auth-required, forbidden and not-found query failures with
its own copy while the gallery used AccessSurface. Both now use one set, and
a state surface without a handler shows no dead button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donghyeon-ka
2026-09-27 13:03:27 +09:00
co-authored by Claude Opus 5.5
parent ee9b09563a
commit a5fff8f4b7
5 changed files with 79 additions and 6 deletions
+2 -2
View File
@@ -306,8 +306,8 @@ Pattern은 여러 primitive를 조합해 반복되는 사용자 문제를 해결
| Pattern | 필수 내용 |
| --- | --- |
| `AsyncSurface` | loading, success, empty, terminal error, stale, refresh |
| `AccessSurface` | auth required, forbidden, not found |
| `AsyncSurface` | loading, success, empty, terminal error, stale, refresh. 조회 실패가 `AUTH_REQUIRED`·`FORBIDDEN`·`NOT_FOUND`이면 `AccessSurface`와 같은 화면(`state-surfaces.tsx`)을 그린다(`async-surface.tsx`의 `ACCESS_SURFACES`) |
| `AccessSurface` | auth required, forbidden, not found. 조회 실패와 갤러리가 이 한 벌을 쓴다 |
| `Form` | submit, error summary, first-invalid focus, pending |
| `ConfirmationDialog` | destructive action 설명과 명시적 확인 |
| `ToastRegion` | queue, announcement, dismiss, focus policy |
@@ -4,6 +4,11 @@ import type { AsyncState } from "../../application/view-models/async-state.ts";
import type { AppFailure } from "../../contracts/errors.ts";
import { useLocale } from "../i18n/index.ts";
import { errorMessage } from "./error-copy.ts";
import {
AuthRequiredSurface,
ForbiddenSurface,
NotFoundSurface,
} from "./state-surfaces.tsx";
import { Button } from "./ui/button.ts";
export function LoadingSurface({
@@ -131,6 +136,23 @@ export function AsyncSurface({
if (state.base === "initial-loading") return <LoadingSurface />;
if (state.base === "empty") return <EmptySurface />;
if (state.base === "terminal-error" && state.failure) {
const AccessState = ACCESS_SURFACES[state.failure.kind];
if (AccessState) {
// 08-11. Access failures use the same surfaces as the design system's
// AccessSurface, so a query and the gallery show one copy.
return (
<div role="alert" data-message-key={state.failure.userMessageKey}>
<AccessState onAction={onAction} />
{state.failure.requestId ? (
<p>
{message("template.supportReference", {
reference: state.failure.requestId,
})}
</p>
) : null}
</div>
);
}
return (
<TerminalErrorSurface
userMessageKey={state.failure.userMessageKey}
@@ -188,3 +210,16 @@ export function AsyncSurface({
</section>
);
}
const ACCESS_SURFACES: Readonly<
Partial<
Record<
AppFailure["kind"],
(props: Readonly<{ onAction?: () => void }>) => ReactNode
>
>
> = Object.freeze({
AUTH_REQUIRED: ({ onAction }) => <AuthRequiredSurface onSignIn={onAction} />,
FORBIDDEN: ({ onAction }) => <ForbiddenSurface onNavigate={onAction} />,
NOT_FOUND: ({ onAction }) => <NotFoundSurface onNavigate={onAction} />,
});
@@ -23,7 +23,9 @@ function StateSurface({
<p className="state-surface__eyebrow">{eyebrow}</p>
<h2>{title}</h2>
<p>{description}</p>
{actionLabel ? <Button onClick={onAction}>{actionLabel}</Button> : null}
{actionLabel && onAction ? (
<Button onClick={onAction}>{actionLabel}</Button>
) : null}
</section>
);
}
+36
View File
@@ -7,6 +7,7 @@ import { describe, expect, it, vi } from "vitest";
import { deriveAsyncState } from "../../src/application/view-models/async-state.ts";
import { AsyncSurface } from "../../src/presentation/components/async-surface.tsx";
import { createFailure } from "../../src/contracts/errors.ts";
import { AccessSurface } from "../../src/presentation/design-system/index.ts";
describe("async UI state matrix", () => {
it.each([
@@ -233,6 +234,41 @@ describe("async UI state matrix", () => {
expect(screen.getByText("표시할 항목이 없습니다.")).toBeVisible();
});
// 08-11. A query failure and the gallery draw one access set, not two.
it.each([
["AUTH_REQUIRED", "auth-required"],
["FORBIDDEN", "forbidden"],
["NOT_FOUND", "not-found"],
] as const)(
"renders a %s query failure with the gallery's access surface",
async (kind, accessKind) => {
const user = userEvent.setup();
const action = vi.fn();
const failure = createFailure(kind, "LIST", 0);
const gallery = render(
<AccessSurface kind={accessKind} onAction={() => {}} />,
);
const expected = gallery.container.querySelector(".state-surface");
expect(expected).not.toBeNull();
const expectedText = expected?.textContent;
gallery.unmount();
render(
<AsyncSurface
state={deriveAsyncState({ failure })}
onAction={action}
/>,
);
const alert = screen.getByRole("alert");
expect(alert).toHaveAttribute("data-message-key", failure.userMessageKey);
expect(alert.querySelector(".state-surface")?.textContent).toBe(
expectedText,
);
await user.click(screen.getByRole("button"));
expect(action).toHaveBeenCalledOnce();
},
);
it("does not retain a terminal error after usable data is restored", () => {
const failed = deriveAsyncState({
failure: createFailure("SERVER_FAILURE", "LIST", 0),
@@ -262,7 +262,7 @@ describe("reference feature page states", () => {
}),
);
expect(await screen.findByRole("alert")).toHaveTextContent(
"이 작업을 수행할 권한이 없습니다.",
"접근할 수 없습니다.",
);
await user.click(
screen.getByRole("button", { name: "안전한 화면으로 이동" }),
@@ -295,7 +295,7 @@ describe("reference feature page states", () => {
session,
);
await user.click(await screen.findByRole("button", { name: "로그인" }));
await user.click(await screen.findByRole("button", { name: "로그인 시작" }));
expect(beginSignIn).toHaveBeenCalledWith(
"/examples/reference-resources?limit=5",
);
@@ -322,7 +322,7 @@ describe("reference feature page states", () => {
{ ...demoSession, beginSignIn },
);
await user.click(await screen.findByRole("button", { name: "로그인" }));
await user.click(await screen.findByRole("button", { name: "로그인 시작" }));
expect(
await screen.findByRole("heading", {
level: 1,