fix(scaffold): 생성 폼이 "변경됨으로 확인" 뒤 목록을 연다
문제 create:feature --with-create가 만드는 작성 폼의 feedback은 form.failure와 결과 불명 두 가지뿐이다. 저장 성공은 상세로 이동해서 알리는데, "변경됨으로 확인"은 reconcileUnknownEffect(...).then(form.settleApplied)이고 이동하지 않는다. settleApplied가 결과를 success로 바꾸고 기본값 resetOnSuccess로 입력을 비우므로, 결과 불명 화면이 사라진 뒤 빈 폼만 남는다. 짝 백엔드 기본(NEVER)에서는 이것이 화면 안의 유일한 행동이다. 사용자는 확인이 받아들여졌는지 모르고, 다시 입력해 저장하면 키 없는 생성이 한 번 더 나간다(실제로 저장됐던 경우 중복). 참조 폼은 같은 경우 "저장했습니다."를 보인다. 고른 방법 확인 뒤 폼을 정리하고(settleApplied, flushSync라 이동 전에 dirty 가드가 풀린다) 목록으로 이동한다. 목록은 항목이 실제로 저장됐는지를 보여 주는 화면이고, reconcileUnknownEffect가 이미 목록 topic을 무효화한다. 라우터가 목록 제목으로 포커스를 옮기므로 08-01의 포커스 문제도 이 폼에서는 생기지 않는다. 생성 기능 테스트에 "응답을 잃은 생성 → 변경됨으로 확인 → 목록 제목과 항목"을 한 행 더했다 (NEVER·KEYED 공통). 매뉴얼 02의 생성 테스트 행에 적었다. 버린 대안 참조 폼처럼 success 가지에 확인 문구를 둔다: 생성 catalog에 키가 하나 늘고, 항목이 실제로 있는지는 여전히 보이지 않는다. 위험·한계 - 짝 백엔드 생성기에는 목록 GET이 아직 없다(1103/03-07 결정 대기). 실제 짝 백엔드에서는 이동한 목록이 405를 받는다(생성 목록 페이지가 지금 그렇다). 생성 테스트는 MSW로 목록을 답한다. - 생성 결과 파일은 단위 테스트가 문자열로만 보고, 동작은 test:feature-scaffold (KEYED, FE-GATE-020)와 test:sample-removal(NEVER)에서 생성한 테스트가 본다. 검증 desktop batch에서 확인: node scripts/run-vitest.ts run tests/unit/create-feature.test.ts corepack pnpm test:feature-scaffold corepack pnpm test:sample-removal Refs: 1105/08-02
This commit is contained in:
@@ -122,7 +122,7 @@ context는 URL 앞부분 하나(라우트 루트)를 가진다. 그 아래 기
|
||||
| `commandEffect.refusedBeforeWrite` | `["<FEATURE>_INVALID"]` | 같다 | 이름 규칙을 트랜잭션 전에 검사한다(4절) |
|
||||
| `acceptedStatuses` | `[201]` | `[201]` | `ResponseEntity.created`. 같은 키 재생도 첫 요청과 같은 201이다 |
|
||||
| 결과 불명 화면 | 확인만. 다시 보내기 버튼 없음 | "같은 요청으로 다시 보내기"가 같은 키로 보낸다 | 키 없는 재전송은 서버가 새 요청으로 본다 |
|
||||
| 생성 테스트 | 응답 유실 → 결과 불명, 다시 보내기 없음, 키 헤더 없음 | 응답 유실 → 같은 키로 다시 보내기. 503 `IDEMPOTENCY_UNAVAILABLE` → 같은 키로 1회 자동 재전송 | `tests/features/<id>/<base>-create-page.test.tsx`, `<base>-http-gateway.test.ts` |
|
||||
| 생성 테스트 | 응답 유실 → 결과 불명, 다시 보내기 없음, 키 헤더 없음. "변경됨으로 확인" → 목록 화면 | 응답 유실 → 같은 키로 다시 보내기. 503 `IDEMPOTENCY_UNAVAILABLE` → 같은 키로 1회 자동 재전송. "변경됨으로 확인" → 목록 화면 | `tests/features/<id>/<base>-create-page.test.tsx`, `<base>-http-gateway.test.ts` |
|
||||
|
||||
- 테스트 하네스의 재시도 상한: 생성된 gateway 테스트는 앱 기본값(`maxRetryAttempts: 2`)으로 돈다. 그래야 `retryBudget: 1`의 재전송이 보인다. 페이지 테스트(`<base>-test-app.tsx`)는 실패를 바로 보이려고 `MAX_RETRY_ATTEMPTS: 0`이다.
|
||||
|
||||
|
||||
@@ -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() {
|
||||
<AsyncSurface
|
||||
state={mutation.state}
|
||||
supportReference={form.supportReference}
|
||||
// The list shows whether the item is there; the form alone
|
||||
// would show nothing but an emptied input (1105/08-02).
|
||||
onReconcileUnknownEffect={(resolution) => {
|
||||
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);
|
||||
});
|
||||
});
|
||||
`;
|
||||
}
|
||||
|
||||
@@ -282,6 +282,23 @@ describe("create:feature --with-create", () => {
|
||||
expect(page).toContain("<AsyncSurface state={mutation.state} />");
|
||||
});
|
||||
|
||||
// 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" });
|
||||
|
||||
Reference in New Issue
Block a user