diff --git a/frontend/src/lib/hooks/__tests__/useBlockAutoSave.svelte.test.ts b/frontend/src/lib/hooks/__tests__/useBlockAutoSave.svelte.test.ts index 93806949..f6a87a8f 100644 --- a/frontend/src/lib/hooks/__tests__/useBlockAutoSave.svelte.test.ts +++ b/frontend/src/lib/hooks/__tests__/useBlockAutoSave.svelte.test.ts @@ -72,8 +72,11 @@ describe('createBlockAutoSave', () => { }); it('preserves the in-flight text + mentionedPersons across a save failure (B12)', async () => { + // Hold the second saveFn so we can observe the saving→saved transition + // (Tester #5506 §5). + let resolveSecond!: () => void; mockSaveFn.mockRejectedValueOnce(new Error('boom')); - mockSaveFn.mockResolvedValueOnce(undefined); + mockSaveFn.mockReturnValueOnce(new Promise((r) => (resolveSecond = r))); const as = createBlockAutoSave({ saveFn: mockSaveFn, documentId: 'doc-1' }); const mentions: PersonMention[] = [{ personId: 'p-aug', displayName: 'Auguste Raddatz' }]; @@ -82,8 +85,14 @@ describe('createBlockAutoSave', () => { expect(as.getSaveState('block-1')).toBe('error'); // Retry without re-passing the data — the hook resends the preserved payload. - await as.handleRetry('block-1', 'should-not-be-used', []); + const retryPromise = as.handleRetry('block-1', 'should-not-be-used', []); + // Yield once so executeSave runs synchronously up to the saveFn await. + await Promise.resolve(); + expect(as.getSaveState('block-1')).toBe('saving'); expect(mockSaveFn).toHaveBeenLastCalledWith('block-1', '@Auguste Raddatz hi', mentions); + + resolveSecond(); + await retryPromise; expect(as.getSaveState('block-1')).toBe('saved'); });