From ae1688319e48a80506a4b47607129958dc3dab56 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 12 May 2026 10:21:24 +0200 Subject: [PATCH 1/2] test(annotation): replace synchronous query().toBeNull() with async not.toBeInTheDocument() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Svelte defers DOM updates to microtasks; .query() is a synchronous snapshot that can fire before the element disappears — making the absence assertions in AnnotationShape and AnnotationLayer non-deterministic. Sweeps all 4 instances across both spec files (Sara's ≤5 threshold). Co-Authored-By: Claude Sonnet 4.6 --- .../lib/document/annotation/AnnotationLayer.svelte.spec.ts | 4 ++-- .../lib/document/annotation/AnnotationShape.svelte.spec.ts | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/src/lib/document/annotation/AnnotationLayer.svelte.spec.ts b/frontend/src/lib/document/annotation/AnnotationLayer.svelte.spec.ts index b134c50f..3c5aea0b 100644 --- a/frontend/src/lib/document/annotation/AnnotationLayer.svelte.spec.ts +++ b/frontend/src/lib/document/annotation/AnnotationLayer.svelte.spec.ts @@ -107,7 +107,7 @@ describe('AnnotationLayer', () => { }); await expect.element(page.getByTestId('annotation-ann-1')).toBeInTheDocument(); - expect(page.getByTestId('annotation-delete-ann-1').query()).toBeNull(); + await expect.element(page.getByTestId('annotation-delete-ann-1')).not.toBeInTheDocument(); }); it('does not show delete button when canDraw is false even if annotation is active', async () => { @@ -120,6 +120,6 @@ describe('AnnotationLayer', () => { }); await expect.element(page.getByTestId('annotation-ann-1')).toBeInTheDocument(); - expect(page.getByTestId('annotation-delete-ann-1').query()).toBeNull(); + await expect.element(page.getByTestId('annotation-delete-ann-1')).not.toBeInTheDocument(); }); }); diff --git a/frontend/src/lib/document/annotation/AnnotationShape.svelte.spec.ts b/frontend/src/lib/document/annotation/AnnotationShape.svelte.spec.ts index 87f1cae1..a896489b 100644 --- a/frontend/src/lib/document/annotation/AnnotationShape.svelte.spec.ts +++ b/frontend/src/lib/document/annotation/AnnotationShape.svelte.spec.ts @@ -45,7 +45,7 @@ describe('AnnotationShape', () => { onpointerleave: () => {} }); - expect(page.getByTestId('annotation-delete-ann-1').query()).toBeNull(); + await expect.element(page.getByTestId('annotation-delete-ann-1')).not.toBeInTheDocument(); }); it('does not show delete button when showDelete is true but neither hovered nor active', async () => { @@ -60,7 +60,7 @@ describe('AnnotationShape', () => { onpointerleave: () => {} }); - expect(page.getByTestId('annotation-delete-ann-1').query()).toBeNull(); + await expect.element(page.getByTestId('annotation-delete-ann-1')).not.toBeInTheDocument(); }); it('shows delete button when showDelete is true and isHovered is true', async () => { -- 2.49.1 From 7ee038faaf9c2602ace0ea540c5c74abe8a52d24 Mon Sep 17 00:00:00 2001 From: Marcel Date: Tue, 12 May 2026 10:22:03 +0200 Subject: [PATCH 2/2] test(ocr): fix track_reactivity_loss in OcrTrainingCard spec Two root causes: 1. In-flight test: resolveFetch() was the last line, leaving the async finally-block writing `training = false` after cleanup destroyed the component. Awaiting the button becoming re-enabled ensures the finally block settles before cleanup runs. 2. Success-dismiss test: startTraining() schedules setTimeout(5000) which fired after cleanup destroyed the component. vi.useFakeTimers() + vi.runAllTimers() scoped to the describe block drains the timer while the component is still alive. Co-Authored-By: Claude Sonnet 4.6 --- frontend/src/lib/ocr/OcrTrainingCard.svelte.spec.ts | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/frontend/src/lib/ocr/OcrTrainingCard.svelte.spec.ts b/frontend/src/lib/ocr/OcrTrainingCard.svelte.spec.ts index d1aec9b8..c72e877a 100644 --- a/frontend/src/lib/ocr/OcrTrainingCard.svelte.spec.ts +++ b/frontend/src/lib/ocr/OcrTrainingCard.svelte.spec.ts @@ -1,4 +1,4 @@ -import { afterEach, describe, expect, it, vi } from 'vitest'; +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'; import { cleanup, render } from 'vitest-browser-svelte'; import { page } from 'vitest/browser'; import OcrTrainingCard from './OcrTrainingCard.svelte'; @@ -74,6 +74,12 @@ describe('OcrTrainingCard — enabled state', () => { }); describe('OcrTrainingCard — success dismiss button', () => { + beforeEach(() => vi.useFakeTimers()); + afterEach(() => { + vi.runAllTimers(); + vi.useRealTimers(); + }); + it('dismiss button has 44×44px touch target (h-11 w-11)', async () => { vi.stubGlobal('fetch', vi.fn().mockResolvedValue({ ok: true })); @@ -108,7 +114,9 @@ describe('OcrTrainingCard — in-flight state', () => { // While fetch is still pending the button label becomes "…" await expect.element(page.getByRole('button', { name: '…' })).toBeInTheDocument(); - // Cleanup: resolve the pending promise resolveFetch({ ok: false }); + await expect + .element(page.getByRole('button', { name: /Training starten/i })) + .not.toBeDisabled(); }); }); -- 2.49.1