diff --git a/docs/manual/02-decision-tables.md b/docs/manual/02-decision-tables.md index 7a8ae6b3..6f764c45 100644 --- a/docs/manual/02-decision-tables.md +++ b/docs/manual/02-decision-tables.md @@ -122,7 +122,7 @@ context는 URL 앞부분 하나(라우트 루트)를 가진다. 그 아래 기 | `commandEffect.refusedBeforeWrite` | `["_INVALID"]` | 같다 | 이름 규칙을 트랜잭션 전에 검사한다(4절) | | `acceptedStatuses` | `[201]` | `[201]` | `ResponseEntity.created`. 같은 키 재생도 첫 요청과 같은 201이다 | | 결과 불명 화면 | 확인만. 다시 보내기 버튼 없음 | "같은 요청으로 다시 보내기"가 같은 키로 보낸다 | 키 없는 재전송은 서버가 새 요청으로 본다 | -| 생성 테스트 | 응답 유실 → 결과 불명, 다시 보내기 없음, 키 헤더 없음 | 응답 유실 → 같은 키로 다시 보내기. 503 `IDEMPOTENCY_UNAVAILABLE` → 같은 키로 1회 자동 재전송 | `tests/features//-create-page.test.tsx`, `-http-gateway.test.ts` | +| 생성 테스트 | 응답 유실 → 결과 불명, 다시 보내기 없음, 키 헤더 없음. "변경됨으로 확인" → 목록 화면 | 응답 유실 → 같은 키로 다시 보내기. 503 `IDEMPOTENCY_UNAVAILABLE` → 같은 키로 1회 자동 재전송. "변경됨으로 확인" → 목록 화면 | `tests/features//-create-page.test.tsx`, `-http-gateway.test.ts` | - 테스트 하네스의 재시도 상한: 생성된 gateway 테스트는 앱 기본값(`maxRetryAttempts: 2`)으로 돈다. 그래야 `retryBudget: 1`의 재전송이 보인다. 페이지 테스트(`-test-app.tsx`)는 실패를 바로 보이려고 `MAX_RETRY_ATTEMPTS: 0`이다. diff --git a/scripts/create-feature-write-slice.ts b/scripts/create-feature-write-slice.ts index 83e147eb..45f20b1d 100644 --- a/scripts/create-feature-write-slice.ts +++ b/scripts/create-feature-write-slice.ts @@ -617,7 +617,8 @@ import { use${pascal}Create } from "./use-${base}-create.ts"; * of the name (400 ${write.invalidCode}, refused before the write) shows on * the field and the form saves again. A save whose result is unknown (the * response was lost) keeps the form: the user checks, or, for a KEYED - * command, resends the same request with the same key. + * command, resends the same request with the same key. Confirming it was + * applied opens the list, which shows whether the item is there. */ export default function ${pascal}CreatePage() { const navigate = useNavigate(); @@ -714,8 +715,13 @@ export default function ${pascal}CreatePage() { { - void mutation.reconcileUnknownEffect(resolution).then(form.settleApplied); + void mutation.reconcileUnknownEffect(resolution).then(() => { + form.settleApplied(); + void navigate(${camel}RouteUrl("${routeId}")); + }); }} // Drawn only for a request with a key (a KEYED command). onResendUnknownEffect={() => { @@ -842,6 +848,14 @@ function answerItem(body: JsonBodyType = { id: ITEM_ID, name: "First item" }) { ); } +function answerList() { + api.use( + http.get(\`\${API}${apiPath}\`, () => + HttpResponse.json({ success: true, data: [{ id: ITEM_ID, name: "First item" }], meta: META }), + ), + ); +} + async function openForm() { const user = await openSignedIn(${camel}RouteUrl("${write.create.routeId}")); expect( @@ -890,6 +904,27 @@ describe("${names.id} create form on the paired backend", () => { }); ${unknownTest} + + // 1105/08-02. Confirming an unknown create opens the list, which shows + // whether the item was saved; the form alone showed nothing. + it("opens the list after the user confirms a create whose response was lost", async () => { + const posts = answerCreate(() => HttpResponse.error()); + answerList(); + const user = await openForm(); + await user.type(await nameField(), "First item"); + await user.click(saveButton()); + expect(await screen.findByText(KO_MESSAGES["async.mutationEffectUnknown"])).toBeVisible(); + + await user.click( + screen.getByRole("button", { name: KO_MESSAGES["action.confirmMutationApplied"] }), + ); + + expect( + await screen.findByRole("heading", { level: 1, name: MESSAGES["${camel}.list.title"] }), + ).toBeVisible(); + expect(await screen.findByText("First item")).toBeVisible(); + expect(posts).toHaveLength(1); + }); }); `; } diff --git a/tests/unit/create-feature.test.ts b/tests/unit/create-feature.test.ts index 51e50a56..2e291100 100644 --- a/tests/unit/create-feature.test.ts +++ b/tests/unit/create-feature.test.ts @@ -282,6 +282,23 @@ describe("create:feature --with-create", () => { expect(page).toContain(""); }); + // 1105/08-02. Confirming an unknown create used to leave an emptied form + // that said nothing. It opens the list, which shows whether the item is + // there, and the generated page test walks that path. + it.each(["NEVER", "KEYED"] as const)( + "opens the list after the user confirms an unknown %s create", + (write) => { + const { files } = plan({ id: "invoice-feature", write }); + + expect( + files.get("src/features/invoice-feature/presentation/invoice-create-page.tsx"), + ).toContain('void navigate(invoiceRouteUrl("INVOICE_LIST"));'); + expect( + files.get("tests/features/invoice-feature/invoice-create-page.test.tsx"), + ).toContain('it("opens the list after the user confirms a create whose response was lost"'); + }, + ); + // 1103/16-07. A backend create made KEYED (IdempotencyExecutor) takes these. it("writes the KEYED values for a backend create made KEYED", () => { const { files } = plan({ id: "invoice-feature", write: "KEYED" });