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 <noreply@anthropic.com>
This commit is contained in:
Marcel
2026-05-11 17:40:54 +02:00
parent f2a48f0a34
commit 1b9cefff86

View File

@@ -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 () => {