diff --git a/src/test/app/(protected)/completion-docs/completion-template-dialog.test.tsx b/src/test/app/(protected)/completion-docs/completion-template-dialog.test.tsx index de46b87f..a8d88128 100644 --- a/src/test/app/(protected)/completion-docs/completion-template-dialog.test.tsx +++ b/src/test/app/(protected)/completion-docs/completion-template-dialog.test.tsx @@ -234,6 +234,28 @@ describe("Edit template", { timeout: 15_000 }, () => { await within(dialog).findByText("Created by Jane Doe ยท Updated Sep 25, 2026"), ).toBeInTheDocument(); }); + + it("stays closed when the user closes it while a save is still in flight", async () => { + let finishSave: (value: unknown) => void = () => undefined; + api.apiPut.mockImplementationOnce( + () => + new Promise((resolve) => { + finishSave = resolve; + }), + ); + const dialog = await openTemplate("Backflow Test Report"); + await user.click(within(dialog).getByRole("button", { name: /Edit/ })); + await user.type(within(dialog).getByRole("textbox", { name: /Document Title/ }), " v2"); + await user.click(within(dialog).getByRole("button", { name: /Save changes/ })); + await waitFor(() => expect(api.apiPut).toHaveBeenCalled()); + + await user.click(within(dialog).getByRole("button", { name: "Close" })); + await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument()); + finishSave({ ...BACKFLOW, name: "Backflow Test Report v2" }); + + await waitFor(() => expect(toast.success).toHaveBeenCalledWith("Template updated")); + expect(screen.queryByRole("dialog")).not.toBeInTheDocument(); + }); }); describe("Delete template", { timeout: 15_000 }, () => {