셸 헤더의 세션 버튼과 로그인 안내(StatusPage)의 로그인·복구 버튼이 처리 중에 `disabled`가 된다. 템플릿 action API(`PageActionDefinition`)에는 `pending`이 없어 상태 화면은 끄는 길밖에 없었다. 꺼진 버튼은 키보드 포커스를 잃는다. 키보드로 "로그인 시작"을 누르고 sign-in이 실패하면 실패 알림이 뜰 때 포커스는 이미 body에 있다(결함 패턴 C11). 모든 파생 서비스의 셸이 복제한다. 같은 모양으로 Pagination의 「이전」을 2쪽에서 누르면 1쪽이 되며 그 버튼이 꺼져 포커스가 떨어진다. 고른 방법: `PageActionDefinition` 버튼에 `pending`·`pendingLabel`을 더해 `Button`으로 넘긴다(추가만). 라우터 상태 화면과 셸 세션 버튼은 `disabled` 대신 `pending`을 쓴다. 버튼은 켜진 채 `aria-busy="true"`이고, 처리 중에 그 버튼이나 다른 세션 버튼(셸과 상태 화면)을 누르면 `useSessionAction().run`이 무시한다. `SessionProvider`가 세션 버튼 모두에 잠금 하나를 준다(중복 실행을 `disabled`에 기대지 않는다). Pagination 끝 버튼은 `aria-disabled`와 누름 무시로 바꾸고, 같은 모양(`.ui-button[aria-disabled="true"]`)으로 그린다. 버린 대안: `Button`의 `pending`이 클릭을 삼키게 하기(폼은 이미 자기 `pendingRef`로 막고, 공개 primitive의 동작이 바뀐다). 위험·한계: 다운스트림이 `PageActionDefinition`에 `disabled: pending`을 넘기고 있으면 그대로 동작하지만 포커스를 잃는다. `pending`으로 옮기면 된다. jsdom은 꺼진 버튼의 포커스를 떨어뜨리지 않아 component 시험은 `disabled`가 아님과 `aria-busy`, 실패 뒤 포커스를 본다. 검증: `tests/component/route-status-surfaces.test.tsx` 세 사례와 `tests/component/pagination.test.tsx` 끝 버튼 두 사례가 고치기 전 코드에서 실패하고 고친 뒤 통과한다(desktop, PR 본문). Refs: 1112/05-03, 1112/04-05
174 lines
6.9 KiB
TypeScript
174 lines
6.9 KiB
TypeScript
// @vitest-environment jsdom
|
|
|
|
import { render, screen, waitFor, within } from "@testing-library/react";
|
|
import userEvent from "@testing-library/user-event";
|
|
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 { 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";
|
|
|
|
// Routes and pages come from a test-only feature, not the removable sample
|
|
// (FE-GATE-020 runs the suite after deleting the sample) nor the starter
|
|
// screens a product replaces (0929/10-02; starter-*.test.tsx test those).
|
|
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 page chunk has not been loaded yet, so the route
|
|
// suspends and shows its own loading surface (the context's routes load
|
|
// behind a surface without the route's name).
|
|
it("shows the busy route loading surface while a page chunk loads", async () => {
|
|
const { container } = renderApp("/fixture/first");
|
|
|
|
await waitFor(() =>
|
|
expect(
|
|
container.querySelector('.route-loading[data-surface="fixture-page"]'),
|
|
).not.toBeNull(),
|
|
);
|
|
const surface = container.querySelector<HTMLElement>(
|
|
'.route-loading[data-surface="fixture-page"]',
|
|
)!;
|
|
const copy = within(surface).getByText("화면을 준비하고 있습니다.");
|
|
expect(copy.closest('[aria-busy="true"]')).not.toBeNull();
|
|
expect(
|
|
await screen.findByRole(
|
|
"heading",
|
|
{ name: "Fixture first page", level: 1 },
|
|
),
|
|
).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 },
|
|
);
|
|
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",
|
|
);
|
|
// 1112/05-03: pending, not disabled, so keyboard focus stays on it.
|
|
const busy = screen.getByRole("button", { name: "처리 중…" });
|
|
expect(busy).not.toBeDisabled();
|
|
expect(busy).toHaveAttribute("aria-busy", "true");
|
|
expect(busy).toHaveFocus();
|
|
await user.keyboard("{Enter}");
|
|
expect(beginSignIn).toHaveBeenCalledOnce();
|
|
|
|
pending.reject(new Error("identity provider unavailable"));
|
|
expect(await screen.findByRole("alert")).toHaveTextContent(
|
|
"세션 작업을 완료하지 못했습니다.",
|
|
);
|
|
const retry = screen.getByRole("button", { name: "로그인 시작" });
|
|
expect(retry).toBe(busy);
|
|
expect(retry).toBeEnabled();
|
|
expect(retry).not.toHaveAttribute("aria-busy");
|
|
expect(retry).toHaveFocus();
|
|
});
|
|
|
|
// 1112/05-03. The shell's button and the page's button share one action.
|
|
it("ignores the other session button while one session action runs", async () => {
|
|
const user = userEvent.setup();
|
|
const pending = deferred();
|
|
const beginSignIn = vi.fn(() => pending.promise);
|
|
renderApp("/fixture/items", { session: sessionWithSignIn(beginSignIn) });
|
|
|
|
const shellButton = await within(screen.getByRole("banner")).findByRole("button", {
|
|
name: "로그인",
|
|
});
|
|
await user.click(await screen.findByRole("button", { name: "로그인 시작" }));
|
|
await user.click(shellButton);
|
|
expect(beginSignIn).toHaveBeenCalledOnce();
|
|
|
|
pending.reject(new Error("identity provider unavailable"));
|
|
expect(await screen.findByRole("button", { name: "로그인 시작" })).not.toHaveAttribute("aria-busy");
|
|
});
|
|
|
|
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("/fixture/first#buttons", { session: sessionWithSignIn(beginSignIn) });
|
|
|
|
const banner = screen.getByRole("banner");
|
|
await user.click(
|
|
await within(banner).findByRole("button", { name: "로그인" }),
|
|
);
|
|
expect(beginSignIn).toHaveBeenCalledWith("/fixture/first#buttons");
|
|
const busy = within(banner).getByRole("button", { name: "처리 중…" });
|
|
expect(busy).not.toBeDisabled();
|
|
expect(busy).toHaveAttribute("aria-busy", "true");
|
|
await user.click(busy);
|
|
expect(beginSignIn).toHaveBeenCalledOnce();
|
|
|
|
pending.reject(new Error("identity provider unavailable"));
|
|
expect(await within(banner).findByRole("alert")).toHaveTextContent(
|
|
"세션 작업을 완료하지 못했습니다.",
|
|
);
|
|
expect(within(banner).getByRole("button", { name: "로그인" })).toHaveFocus();
|
|
});
|
|
|
|
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 },
|
|
);
|
|
const page = heading.closest("section");
|
|
expect(page).not.toBeNull();
|
|
expect(
|
|
within(page!).getByRole("link", { name: "홈으로 이동" }),
|
|
).toHaveAttribute("href", "/app");
|
|
});
|
|
});
|