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
committed by marcel
parent b4c249c489
commit eb666b2eb3

View File

@@ -172,8 +172,7 @@ describe('TranscriptionEditView', () => {
expect(chip).toBeDefined(); expect(chip).toBeDefined();
chip?.click(); chip?.click();
await new Promise((r) => setTimeout(r, 30)); await vi.waitFor(() => expect(onToggleTrainingLabel).toHaveBeenCalled());
expect(onToggleTrainingLabel).toHaveBeenCalled();
}); });
it('renders blocks sorted by sortOrder', async () => { it('renders blocks sorted by sortOrder', async () => {
@@ -195,7 +194,7 @@ describe('TranscriptionEditView', () => {
expect(idxSecond).toBeLessThan(idxThird); 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, { const { rerender } = render(TranscriptionEditView, {
props: baseProps({ props: baseProps({
blocks: [ 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({ await rerender({
...baseProps({ ...baseProps({
blocks: [ blocks: [
@@ -217,9 +217,10 @@ describe('TranscriptionEditView', () => {
}) })
}); });
await new Promise((r) => setTimeout(r, 30)); await vi.waitFor(() => {
// No throw is the assertion — the $effect that syncs activeBlockId fires expect(document.body.textContent).toContain('First');
expect(true).toBe(true); expect(document.body.textContent).toContain('Second');
});
}); });
it('handleMarkAllReviewed calls onMarkAllReviewed when clicked', async () => { it('handleMarkAllReviewed calls onMarkAllReviewed when clicked', async () => {
@@ -235,8 +236,7 @@ describe('TranscriptionEditView', () => {
.getByRole('button', { name: /alle als fertig/i }) .getByRole('button', { name: /alle als fertig/i })
.element()) as HTMLButtonElement; .element()) as HTMLButtonElement;
btn.click(); btn.click();
await new Promise((r) => setTimeout(r, 30)); await vi.waitFor(() => expect(onMarkAllReviewed).toHaveBeenCalledOnce());
expect(onMarkAllReviewed).toHaveBeenCalledOnce();
}); });
it('renders all blocks with their text', async () => { it('renders all blocks with their text', async () => {