test(e2e): assert reference data and cover save success and retry (11-06)
The route spec only checked that the protected screen opened, so a schema violating 200 or a 503 still passed it. It now asserts the mocked row, and a new spec saves once and retries after a 429 in a real browser. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7870c48b5f
commit
48b84951b8
@@ -29,4 +29,6 @@ test("opens the protected integration route through the local demo seam", async
|
||||
page.getByRole("heading", { name: protectedRoute.title }),
|
||||
).toBeVisible();
|
||||
await expect(page.getByText("인증됨")).toBeVisible();
|
||||
// The mocked row went through the production codec, mapper and query cache.
|
||||
await expect(page.getByText("Browser reference")).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -0,0 +1,100 @@
|
||||
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;
|
||||
}
|
||||
|
||||
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",
|
||||
]);
|
||||
});
|
||||
});
|
||||
@@ -12,8 +12,18 @@ function ignoredConsole(message: ConsoleMessage) {
|
||||
);
|
||||
}
|
||||
|
||||
export const test = base.extend({
|
||||
page: async ({ page }, use) => {
|
||||
export const test = base.extend<{
|
||||
/**
|
||||
* Browser failures a test provokes on purpose, matched against the recorded
|
||||
* `console:…`, `pageerror:…` or `requestfailed:…` line (for example the
|
||||
* browser's log line for a mocked 4xx). Everything else still fails. One
|
||||
* pattern, not an array: `test.use` reads an array as a `[value, options]`
|
||||
* fixture tuple.
|
||||
*/
|
||||
allowedBrowserFailure: RegExp | undefined;
|
||||
}>({
|
||||
allowedBrowserFailure: [undefined, { option: true }],
|
||||
page: async ({ page, allowedBrowserFailure }, use) => {
|
||||
const failures: string[] = [];
|
||||
const onConsole = (message: ConsoleMessage) => {
|
||||
if (
|
||||
@@ -38,7 +48,12 @@ export const test = base.extend({
|
||||
page.off("console", onConsole);
|
||||
page.off("pageerror", onPageError);
|
||||
page.off("requestfailed", onRequestFailed);
|
||||
expect(failures, "unexpected browser console/page errors").toEqual([]);
|
||||
expect(
|
||||
failures.filter(
|
||||
(failure) => !allowedBrowserFailure?.test(failure),
|
||||
),
|
||||
"unexpected browser console/page errors",
|
||||
).toEqual([]);
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user