From d9c7abf2abf7b6a4518521100a7a5f4843e3db3c Mon Sep 17 00:00:00 2001 From: Marcel Date: Wed, 29 Apr 2026 01:18:43 +0200 Subject: [PATCH] =?UTF-8?q?test(autosave):=20observe=20saving=E2=86=92save?= =?UTF-8?q?d=20transition=20in=20B12=20retry=20path?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tester #5506 §5: the existing test only asserted the final 'saved' state, which would also pass if the hook skipped the saving state altogether. Hold the second mocked saveFn promise so we can assert the intermediate transition. Co-Authored-By: Claude Sonnet 4.6 --- .../hooks/__tests__/useBlockAutoSave.svelte.test.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) 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'); });