문제
1103/08-02 수정으로 저장이 실패 상태나 결과 불명으로 끝나면 포커스가 feedback
자리로 가고, Tab 한 번에 복구 버튼("변경됨으로 확인", "같은 요청으로 다시
보내기", "다시 시도")에 닿는다. 그런데 그 버튼을 키보드로 눌러 일이 끝나면
버튼을 그리던 상태가 "저장했습니다."로 바뀌며 버튼이 문서에서 빠지고, 브라우저가
포커스를 body로 돌린다. 폼은 실패 결과일 때만 포커스를 옮기고 성공 쪽
settleSuccessfulValues는 옮기지 않는다(리뷰 08-R2: chromium·firefox·webkit × 세
경우 9건 모두 body, jsdom 08-R1 B1~B3도 BODY).
고른 방법
useAppForm의 포커스 effect가 직전에 그린 결과를 기억한다. 결과가 상태
결과(reauth-required·forbidden·retry-later·unavailable)나 effect-unknown에서
success로 바뀌었고 그때 포커스가 body(잃음)이면 feedback 자리로 옮긴다. 페이지마다
복사하지 않고 폼 하나에서 고친다. 포커스를 잃었을 때만 옮기므로 버튼이나 필드에
남아 있는 포커스는 빼앗지 않고, 처음 저장이 그냥 성공할 때는 옮기지 않는다
(1103/08-02의 보존 조건). success를 그릴 feedback이 없는 화면(생성 폼은 저장 뒤
상세로 이동)에서는 아무것도 하지 않는다.
버린 대안
settleSuccessfulValues에서 늘 feedback으로 옮긴다: 마우스로 누른 첫 저장에서도
포커스가 움직인다. 리뷰 문서의 (2)(확인 중에도 feedback 자리를 비우지 않는다)는
08-04에서 다룬다. 자리를 유지해도 눌렀던 버튼은 빠지므로 끝난 뒤 포커스는 이
커밋이 정한다.
위험·한계
- 확인·재전송이 진행되는 동안(끝나기 전)에는 포커스가 잠깐 body에 있다. 끝난
뒤만 고친다(완료 기준).
- 포커스를 받는 feedback 자리에 역할·이름이 없어 스크린 리더가 어떻게 읽는지는
확인하지 않았다(리뷰 3.5절 관찰 그대로).
검증
desktop batch에서 확인:
node scripts/run-vitest.ts run tests/features/reference-feature/reference-page.test.tsx
tests/component/form-foundation.test.tsx
corepack pnpm exec playwright test tests/e2e/reference-save.spec.ts
--project=chromium --project=firefox --project=webkit
Refs: 1105/08-01
238 lines
8.0 KiB
TypeScript
238 lines
8.0 KiB
TypeScript
import type { Page, Route } from "@playwright/test";
|
|
import { expect, test } from "../support/browser/strict-browser-test.ts";
|
|
|
|
const CREATE_URL = "http://localhost:8080/api/reference-resources";
|
|
|
|
type CreateCall = Readonly<{ name: unknown; idempotencyKey: string | null }>;
|
|
|
|
async function openForm(page: Page) {
|
|
await page.route(`${CREATE_URL}?*`, (route) => route.fulfill({ json: [] }));
|
|
await page.goto("/examples/reference-resources/new");
|
|
await page.getByRole("button", { name: "로그인 시작" }).click();
|
|
await expect(
|
|
page.getByRole("heading", { name: "Reference resource 만들기" }),
|
|
).toBeVisible();
|
|
}
|
|
|
|
/** Answers each POST with the next responder and records what was sent. */
|
|
async function routeCreate(
|
|
page: Page,
|
|
responders: readonly ((route: Route) => Promise<void>)[],
|
|
): Promise<CreateCall[]> {
|
|
const calls: CreateCall[] = [];
|
|
await page.route(CREATE_URL, async (route) => {
|
|
const request = route.request();
|
|
if (request.method() !== "POST") return route.fallback();
|
|
calls.push({
|
|
name: (request.postDataJSON() as { name?: unknown }).name,
|
|
idempotencyKey: await request.headerValue("idempotency-key"),
|
|
});
|
|
const respond = responders[calls.length - 1];
|
|
if (!respond) throw new Error(`unexpected create call ${calls.length}`);
|
|
await respond(route);
|
|
});
|
|
return calls;
|
|
}
|
|
|
|
/**
|
|
* 1103/08-02. Saves from the keyboard and checks where focus lands: in the
|
|
* failure status above the form, one Tab away from its first action, not on
|
|
* the body after the page disabled the save button.
|
|
*/
|
|
async function saveFromKeyboard(page: Page, expectedFirstAction: string) {
|
|
await page
|
|
.getByRole("textbox", { name: /새 항목 이름/ })
|
|
.fill("Saved in the browser");
|
|
await page.getByRole("button", { name: "저장" }).focus();
|
|
await page.keyboard.press("Enter");
|
|
|
|
await expect(page.locator(".page-template__feedback")).toBeFocused();
|
|
await page.keyboard.press("Tab");
|
|
await expect(
|
|
page.getByRole("button", { name: expectedFirstAction }),
|
|
).toBeFocused();
|
|
}
|
|
|
|
const created = (route: Route) =>
|
|
route.fulfill({
|
|
status: 201,
|
|
json: {
|
|
id: "browser-created",
|
|
name: "Saved in the browser",
|
|
createdAt: "2026-07-26T00:00:00.000Z",
|
|
},
|
|
});
|
|
|
|
test("saves a new reference resource through the production command path", async ({
|
|
page,
|
|
}) => {
|
|
await openForm(page);
|
|
const calls = await routeCreate(page, [created]);
|
|
|
|
await page
|
|
.getByRole("textbox", { name: /새 항목 이름/ })
|
|
.fill("Saved in the browser");
|
|
await page.getByRole("button", { name: "저장" }).click();
|
|
|
|
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
|
expect(calls).toHaveLength(1);
|
|
expect(calls[0]?.name).toBe("Saved in the browser");
|
|
expect(calls[0]?.idempotencyKey).toBeTruthy();
|
|
});
|
|
|
|
test.describe("after a rate-limited save", () => {
|
|
// Chromium and WebKit log a 4xx fetch response to the console, and the
|
|
// client cancels the 429 body unread, which Chromium reports as aborted.
|
|
test.use({
|
|
allowedBrowserFailure:
|
|
/^console:error:.*status of 429|^requestfailed:POST:\/api\/reference-resources:net::ERR_ABORTED$/u,
|
|
});
|
|
|
|
test("keeps the input and saves on retry", async ({ page }) => {
|
|
await openForm(page);
|
|
const calls = await routeCreate(page, [
|
|
(route) =>
|
|
route.fulfill({
|
|
status: 429,
|
|
headers: { "retry-after": "1" },
|
|
json: { title: "Too many requests" },
|
|
}),
|
|
created,
|
|
]);
|
|
|
|
const name = page.getByRole("textbox", { name: /새 항목 이름/ });
|
|
await name.fill("Saved in the browser");
|
|
await page.getByRole("button", { name: "저장" }).click();
|
|
|
|
await expect(
|
|
page.getByText("요청이 많습니다. 잠시 후 다시 시도해 주세요."),
|
|
).toBeVisible();
|
|
await expect(name).toHaveValue("Saved in the browser");
|
|
await page.getByRole("button", { name: "다시 시도" }).click();
|
|
|
|
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
|
expect(calls.map((call) => call.name)).toEqual([
|
|
"Saved in the browser",
|
|
"Saved in the browser",
|
|
]);
|
|
});
|
|
|
|
test("keeps keyboard focus in the failure status", async ({ page }) => {
|
|
await openForm(page);
|
|
await routeCreate(page, [
|
|
(route) =>
|
|
route.fulfill({
|
|
status: 429,
|
|
headers: { "retry-after": "1" },
|
|
json: { title: "Too many requests" },
|
|
}),
|
|
]);
|
|
|
|
await saveFromKeyboard(page, "다시 시도");
|
|
});
|
|
|
|
// 1105/08-01. The retry button goes away with the status once the save
|
|
// succeeds; focus stays in the feedback area, not on the body.
|
|
test("keeps keyboard focus in the feedback after retrying from the keyboard", async ({
|
|
page,
|
|
}) => {
|
|
await openForm(page);
|
|
await routeCreate(page, [
|
|
(route) =>
|
|
route.fulfill({
|
|
status: 429,
|
|
headers: { "retry-after": "1" },
|
|
json: { title: "Too many requests" },
|
|
}),
|
|
created,
|
|
]);
|
|
await saveFromKeyboard(page, "다시 시도");
|
|
|
|
await page.keyboard.press("Enter");
|
|
|
|
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
|
await expect(page.locator(".page-template__feedback")).toBeFocused();
|
|
});
|
|
});
|
|
|
|
test.describe("after a save whose result is unknown", () => {
|
|
// The browsers log the 500 response to the console.
|
|
test.use({
|
|
allowedBrowserFailure: /^console:error:.*status of 500/u,
|
|
});
|
|
|
|
// 0929/08-04. The case a user most wants to report shows the id support
|
|
// can find in the server logs.
|
|
test("shows the request id the server echoed", async ({ page }) => {
|
|
await openForm(page);
|
|
await routeCreate(page, [
|
|
(route) =>
|
|
route.fulfill({
|
|
status: 500,
|
|
headers: {
|
|
"x-correlation-id": "corr-save-500",
|
|
"access-control-expose-headers": "x-correlation-id",
|
|
},
|
|
json: { title: "Internal error" },
|
|
}),
|
|
]);
|
|
|
|
await page
|
|
.getByRole("textbox", { name: /새 항목 이름/ })
|
|
.fill("Saved in the browser");
|
|
await page.getByRole("button", { name: "저장" }).click();
|
|
|
|
await expect(page.getByText("변경 결과를 확인할 수 없습니다.")).toBeVisible();
|
|
await expect(page.getByText("지원 참조: corr-save-500")).toBeVisible();
|
|
});
|
|
|
|
test("keeps keyboard focus in the unknown-result status", async ({ page }) => {
|
|
await openForm(page);
|
|
await routeCreate(page, [
|
|
(route) => route.fulfill({ status: 500, json: { title: "Internal error" } }),
|
|
]);
|
|
|
|
await saveFromKeyboard(page, "변경됨으로 확인");
|
|
});
|
|
|
|
// 1105/08-01. Confirming or resending removes the button that had focus;
|
|
// focus stays in the feedback area that shows the result.
|
|
test("keeps keyboard focus in the feedback after confirming from the keyboard", async ({
|
|
page,
|
|
}) => {
|
|
await openForm(page);
|
|
const calls = await routeCreate(page, [
|
|
(route) => route.fulfill({ status: 500, json: { title: "Internal error" } }),
|
|
]);
|
|
await saveFromKeyboard(page, "변경됨으로 확인");
|
|
|
|
await page.keyboard.press("Enter");
|
|
|
|
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
|
await expect(page.locator(".page-template__feedback")).toBeFocused();
|
|
expect(calls).toHaveLength(1);
|
|
});
|
|
|
|
test("keeps keyboard focus in the feedback after resending from the keyboard", async ({
|
|
page,
|
|
}) => {
|
|
await openForm(page);
|
|
const calls = await routeCreate(page, [
|
|
(route) => route.fulfill({ status: 500, json: { title: "Internal error" } }),
|
|
created,
|
|
]);
|
|
await saveFromKeyboard(page, "변경됨으로 확인");
|
|
await page.keyboard.press("Tab");
|
|
await expect(
|
|
page.getByRole("button", { name: "같은 요청으로 다시 보내기" }),
|
|
).toBeFocused();
|
|
|
|
await page.keyboard.press("Enter");
|
|
|
|
await expect(page.getByRole("status")).toHaveText("저장했습니다.");
|
|
await expect(page.locator(".page-template__feedback")).toBeFocused();
|
|
expect(calls).toHaveLength(2);
|
|
expect(calls[1]?.idempotencyKey).toBe(calls[0]?.idempotencyKey);
|
|
});
|
|
});
|