test: fix flaky browser-mode tests in AnnotationShape and OcrTrainingCard specs #547

Merged
marcel merged 2 commits from feat/issue-541-flaky-browser-tests into main 2026-05-12 11:14:22 +02:00
Showing only changes of commit 7ee038faaf - Show all commits

View File

@@ -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();
});
});