diff --git a/app/queries/mailboxes.ts b/app/queries/mailboxes.ts index 2aefbb2..f1a3b5c 100644 --- a/app/queries/mailboxes.ts +++ b/app/queries/mailboxes.ts @@ -39,10 +39,14 @@ export function useUpdateMailbox() { return useMutation({ mutationFn: ({ mailboxId, settings }: { mailboxId: string; settings: unknown }) => api.updateMailbox(mailboxId, settings), - onSuccess: (_data, { mailboxId }) => { - qc.invalidateQueries({ queryKey: queryKeys.mailboxes.detail(mailboxId) }); - qc.invalidateQueries({ queryKey: queryKeys.mailboxes.all }); - }, + // The save is over when the app holds what was saved: the two lists are read again before + // the caller is told. Told earlier, a person who saved a signature and wrote at once got a + // message without it. + onSuccess: (_data, { mailboxId }) => + Promise.all([ + qc.invalidateQueries({ queryKey: queryKeys.mailboxes.detail(mailboxId) }), + qc.invalidateQueries({ queryKey: queryKeys.mailboxes.all }), + ]), }); } diff --git a/test/e2e/mailbox.spec.ts b/test/e2e/mailbox.spec.ts index 22f6978..d935a49 100644 --- a/test/e2e/mailbox.spec.ts +++ b/test/e2e/mailbox.spec.ts @@ -656,9 +656,23 @@ test("settings are in tabs; a person's choices take effect at once and stay, a m await page.getByLabel("Add a signature to new messages").check(); await page.locator(".ProseMirror").click(); await page.keyboard.type("Kind regards from the pod bay"); + // The app reads the mailbox again after a save. That answer is held back here, so that + // "saved" said before it arrived would open a window without the signature. + const held: Promise[] = []; + const mailboxRead = (url: URL) => /^\/api\/v1\/mailboxes(\/[^/]+)?$/.test(url.pathname); + await page.route(mailboxRead, (route) => { + if (route.request().method() !== "GET") return route.continue(); + const answered = new Promise((resolve) => setTimeout(resolve, 1000)).then(() => + route.continue(), + ); + held.push(answered); + return answered; + }); await page.getByRole("button", { name: "Save signature" }).click(); await expect(page.getByText("Signature saved")).toBeVisible(); await page.getByRole("button", { name: "Compose" }).click(); + await Promise.all(held); + await page.unroute(mailboxRead); const compose = page.getByRole("region", { name: "Compose" }); await expect(compose.locator(".ProseMirror")).toContainText("Kind regards from the pod bay"); await compose.getByRole("button", { name: "Discard" }).click();