test(completion-docs): keep the dialog closed when a save finishes after closing

This commit is contained in:
Alexandre Brandizzi 2026-09-25 12:53:43 -03:00
parent d5cd0659a2
commit 9c19287172

View file

@ -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 }, () => {