mirror of
https://github.com/Sea-Haven-Industries/shoc-frontend-new.git
synced 2026-09-30 04:33:11 +00:00
test(completion-docs): keep the dialog closed when dismissed mid-save
Dismissing the edit dialog with Escape or the Close button while an update is still in flight must not bring it back when the save lands. The per-call mutate callbacks that reopen it in view mode are dropped by TanStack Query once the dialog unmounts, so this pins that behaviour: the test fails if the save is moved to mutateAsync().then(), which would reopen the dialog.
This commit is contained in:
parent
d866cf1b87
commit
2b338b36c6
1 changed files with 33 additions and 0 deletions
|
|
@ -234,6 +234,39 @@ describe("Edit template", { timeout: 15_000 }, () => {
|
|||
await within(dialog).findByText("Created by Jane Doe · Updated Sep 25, 2026"),
|
||||
).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it.each([
|
||||
[
|
||||
"Escape",
|
||||
async () => {
|
||||
// The disabled Save button drops focus; Escape is pressed from inside the form.
|
||||
screen.getByRole("textbox", { name: /Document Title/ }).focus();
|
||||
await user.keyboard("{Escape}");
|
||||
},
|
||||
],
|
||||
["the Close button", () => user.click(screen.getByRole("button", { name: "Close" }))],
|
||||
])("stays closed when dismissed with %s while a save is in flight", async (_, dismiss) => {
|
||||
let finishSave: () => void = () => {};
|
||||
const respond = api.apiPut.getMockImplementation()!;
|
||||
api.apiPut.mockImplementation(
|
||||
(...args: unknown[]) =>
|
||||
new Promise((resolve) => {
|
||||
finishSave = () => resolve(respond(...args));
|
||||
}),
|
||||
);
|
||||
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 dismiss();
|
||||
await waitFor(() => expect(screen.queryByRole("dialog")).not.toBeInTheDocument());
|
||||
finishSave();
|
||||
|
||||
await waitFor(() => expect(toast.success).toHaveBeenCalledWith("Template updated"));
|
||||
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
|
||||
});
|
||||
});
|
||||
|
||||
describe("Delete template", { timeout: 15_000 }, () => {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue