diff --git a/src/presentation/forms/use-app-form.ts b/src/presentation/forms/use-app-form.ts index 9f859164..47abaea5 100644 --- a/src/presentation/forms/use-app-form.ts +++ b/src/presentation/forms/use-app-form.ts @@ -235,15 +235,18 @@ export function useAppForm< const submittedValues = unknownSubmissionRef.current; if (!submittedValues) { // 1106/08-01. After a remount the form no longer holds the submitted - // values. As a resend does (resendUnknown), the confirmed save settles - // with the values on screen, and focus, lost with the confirm button, - // goes to the feedback area that shows it. + // values. The confirmed save is shown, and focus, lost with the + // confirm button, goes to the feedback area that shows it. The values + // on screen were never sent, so they and the dirty state stay as they + // are (diff review of 1106/08-01). focusFeedbackRef.current = focusIsLost(); - settleSuccessfulValues(values); + setFieldErrors({} as FieldErrors); + setFormErrors([]); + setResult("success"); return; } settleSuccessfulValues(submittedValues); - }, [settleSuccessfulValues, values]); + }, [settleSuccessfulValues]); const settleNotApplied = useCallback(() => { if (!unknownSubmissionRef.current) return; diff --git a/tests/features/reference-feature/reference-page.test.tsx b/tests/features/reference-feature/reference-page.test.tsx index be84b7e0..71052085 100644 --- a/tests/features/reference-feature/reference-page.test.tsx +++ b/tests/features/reference-feature/reference-page.test.tsx @@ -789,6 +789,35 @@ describe("reference feature page states", () => { ); }); + // 1106/08-01, diff review. What the user typed on the remounted form was + // never sent. Confirming the earlier save shows that save and leaves the + // new input, and its leave guard, in place. + it("keeps what the user typed on a remounted form when confirming the earlier save", async () => { + const { user, release } = await leaveDuringSaveAndComeBack(); + release({ + ok: false, + error: createFailure("SERVER_FAILURE", "CREATE_REFERENCE_RESOURCE", 0, { + effect: "MAYBE_APPLIED", + }), + }); + await screen.findByRole("button", { name: "변경됨으로 확인" }); + const name = screen.getByRole("textbox", { name: /새 항목 이름/ }); + await user.type(name, "Second item"); + screen.getByRole("button", { name: "변경됨으로 확인" }).focus(); + + await user.keyboard("{Enter}"); + + const saved = await screen.findByText("저장했습니다."); + await waitFor(() => + expect(saved.closest(".page-template__feedback")).toHaveFocus(), + ); + expect(name).toHaveValue("Second item"); + await user.click(screen.getByRole("button", { name: "목록으로 돌아가기" })); + expect( + await screen.findByRole("button", { name: "변경 버리고 이동" }), + ).toBeVisible(); + }); + // 1106/08-01 (B). That save succeeding left the remounted form saying // nothing. The form cannot know its result, so it points to the list. it("points to the list once a save the remounted form did not start ends", async () => {