From a5fff8f4b7bcaf43099ba8e2e68a4df4d90bc46f Mon Sep 17 00:00:00 2001 From: donghyeon-ka Date: Sun, 27 Sep 2026 13:03:27 +0900 Subject: [PATCH] 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 --- docs/styling/design-system-platform.md | 4 +-- src/presentation/components/async-surface.tsx | 35 ++++++++++++++++++ .../components/state-surfaces.tsx | 4 ++- tests/component/async-surface.test.tsx | 36 +++++++++++++++++++ .../reference-feature/reference-page.test.tsx | 6 ++-- 5 files changed, 79 insertions(+), 6 deletions(-) diff --git a/docs/styling/design-system-platform.md b/docs/styling/design-system-platform.md index 48f16cfd..0f25b452 100644 --- a/docs/styling/design-system-platform.md +++ b/docs/styling/design-system-platform.md @@ -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 | diff --git a/src/presentation/components/async-surface.tsx b/src/presentation/components/async-surface.tsx index 74ab5536..834fd8a9 100644 --- a/src/presentation/components/async-surface.tsx +++ b/src/presentation/components/async-surface.tsx @@ -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 ; if (state.base === "empty") return ; 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 ( +
+ + {state.failure.requestId ? ( +

+ {message("template.supportReference", { + reference: state.failure.requestId, + })} +

+ ) : null} +
+ ); + } return ( ); } + +const ACCESS_SURFACES: Readonly< + Partial< + Record< + AppFailure["kind"], + (props: Readonly<{ onAction?: () => void }>) => ReactNode + > + > +> = Object.freeze({ + AUTH_REQUIRED: ({ onAction }) => , + FORBIDDEN: ({ onAction }) => , + NOT_FOUND: ({ onAction }) => , +}); diff --git a/src/presentation/components/state-surfaces.tsx b/src/presentation/components/state-surfaces.tsx index d48c546a..c7400d5d 100644 --- a/src/presentation/components/state-surfaces.tsx +++ b/src/presentation/components/state-surfaces.tsx @@ -23,7 +23,9 @@ function StateSurface({

{eyebrow}

{title}

{description}

- {actionLabel ? : null} + {actionLabel && onAction ? ( + + ) : null} ); } diff --git a/tests/component/async-surface.test.tsx b/tests/component/async-surface.test.tsx index 9bf6b36d..558cb74c 100644 --- a/tests/component/async-surface.test.tsx +++ b/tests/component/async-surface.test.tsx @@ -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( + {}} />, + ); + const expected = gallery.container.querySelector(".state-surface"); + expect(expected).not.toBeNull(); + const expectedText = expected?.textContent; + gallery.unmount(); + + render( + , + ); + 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), diff --git a/tests/features/reference-feature/reference-page.test.tsx b/tests/features/reference-feature/reference-page.test.tsx index f68f96c9..2c0da30f 100644 --- a/tests/features/reference-feature/reference-page.test.tsx +++ b/tests/features/reference-feature/reference-page.test.tsx @@ -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,