From eb666b2eb34c62c09f8e9acd4a06ad6db3ba882e Mon Sep 17 00:00:00 2001 From: Marcel Date: Mon, 11 May 2026 17:40:54 +0200 Subject: [PATCH] test(transcription): replace 3 setTimeout sleeps in TranscriptionEditView with vi.waitFor Also replaces a vacuous expect(true).toBe(true) with a real behavioral assertion that both block texts remain rendered after rerender. Co-Authored-By: Claude Opus 4.7 --- .../TranscriptionEditView.svelte.test.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/frontend/src/lib/document/transcription/TranscriptionEditView.svelte.test.ts b/frontend/src/lib/document/transcription/TranscriptionEditView.svelte.test.ts index dddcfb3f..6253c16a 100644 --- a/frontend/src/lib/document/transcription/TranscriptionEditView.svelte.test.ts +++ b/frontend/src/lib/document/transcription/TranscriptionEditView.svelte.test.ts @@ -172,8 +172,7 @@ describe('TranscriptionEditView', () => { expect(chip).toBeDefined(); chip?.click(); - await new Promise((r) => setTimeout(r, 30)); - expect(onToggleTrainingLabel).toHaveBeenCalled(); + await vi.waitFor(() => expect(onToggleTrainingLabel).toHaveBeenCalled()); }); it('renders blocks sorted by sortOrder', async () => { @@ -195,7 +194,7 @@ describe('TranscriptionEditView', () => { expect(idxSecond).toBeLessThan(idxThird); }); - it('reactivates the active block when activeAnnotationId changes to one with a matching annotation', async () => { + it('renders both blocks with their text after rerender with a new activeAnnotationId', async () => { const { rerender } = render(TranscriptionEditView, { props: baseProps({ blocks: [ @@ -206,7 +205,8 @@ describe('TranscriptionEditView', () => { }) }); - // re-render with activeAnnotationId set to ann-2 — block b2 should become active + // re-render with activeAnnotationId set to ann-2 — the activeBlockId $effect re-runs + // and both blocks must still be present in the rendered list. await rerender({ ...baseProps({ blocks: [ @@ -217,9 +217,10 @@ describe('TranscriptionEditView', () => { }) }); - await new Promise((r) => setTimeout(r, 30)); - // No throw is the assertion — the $effect that syncs activeBlockId fires - expect(true).toBe(true); + await vi.waitFor(() => { + expect(document.body.textContent).toContain('First'); + expect(document.body.textContent).toContain('Second'); + }); }); it('handleMarkAllReviewed calls onMarkAllReviewed when clicked', async () => { @@ -235,8 +236,7 @@ describe('TranscriptionEditView', () => { .getByRole('button', { name: /alle als fertig/i }) .element()) as HTMLButtonElement; btn.click(); - await new Promise((r) => setTimeout(r, 30)); - expect(onMarkAllReviewed).toHaveBeenCalledOnce(); + await vi.waitFor(() => expect(onMarkAllReviewed).toHaveBeenCalledOnce()); }); it('renders all blocks with their text', async () => {