From f7ffdcdf6ada72660fa3f47be5b1f96e8f4e4686 Mon Sep 17 00:00:00 2001 From: Linus Rath <139418639+rathlinus@users.noreply.github.com> Date: Wed, 4 Nov 2026 14:02:27 +0100 Subject: [PATCH] test: check a pop-out's discarded draft is deleted when the page goes away --- components/popout/__tests__/popout-host.test.tsx | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/components/popout/__tests__/popout-host.test.tsx b/components/popout/__tests__/popout-host.test.tsx index 14634634d..6f9a6cdd2 100644 --- a/components/popout/__tests__/popout-host.test.tsx +++ b/components/popout/__tests__/popout-host.test.tsx @@ -24,7 +24,7 @@ const DRAFT: RescuedDraft = { const original = { auth: useAuthStore.getState(), email: useEmailStore.getState(), accounts: useAccountStore.getState() }; let heard: PopoutMessage[]; let popout: NonNullable>; -let client: { createDraft: ReturnType; getAuthHeader: () => string; isOfflineOnly: () => boolean }; +let client: { createDraft: ReturnType; deleteEmail: ReturnType; getAuthHeader: () => string; isOfflineOnly: () => boolean }; let lockRequests: string[]; // Rounds, not one long wait: a message and its answer are two hops, and a busy @@ -63,7 +63,7 @@ beforeEach(() => { sessionStorage.clear(); heard = []; popout = openPopoutChannel((message) => heard.push(message))!; - client = { createDraft: vi.fn(async () => 'new'), getAuthHeader: () => 'Bearer main', isOfflineOnly: () => false }; + client = { createDraft: vi.fn(async () => 'new'), deleteEmail: vi.fn(async () => {}), getAuthHeader: () => 'Bearer main', isOfflineOnly: () => false }; useAccountStore.setState({ accounts: [{ id: 'alice', serverUrl: 'https://mail.example.test', username: 'alice', authMode: 'oauth', cookieSlot: 0 } as never], activeAccountId: 'alice', @@ -347,6 +347,10 @@ describe('PopoutHost', () => { expect(toasts).toHaveLength(1); expect(toasts[0].title).toBe('compose_ux.draft_discarded'); expect(toasts[0].action?.label).toBe('compose_ux.undo'); + // Leaving the page ends the Undo: the draft is deleted then, not left behind. + expect(client.deleteEmail).not.toHaveBeenCalled(); + await act(async () => { window.dispatchEvent(new Event('pagehide')); }); + expect(client.deleteEmail).toHaveBeenCalledWith('d1', undefined); }); it('refreshes the list and counts when a pop-out changed mail, once for a burst', async () => {