From 065dd8fabdbd2942dcacc2570d4d645ba301b8ae Mon Sep 17 00:00:00 2001 From: Marcel Date: Thu, 26 Mar 2026 22:32:58 +0100 Subject: [PATCH] fix(e2e): fix two flaky annotation tests Test 6 (delete annotation): the mouse-draw test can create multiple annotations in CI. Changed the assertion to `countBefore - 1` instead of a hard-coded 0, so the test is resilient to any pre-existing count. Test 7 (hash versioning): `[data-testid^="annotation-"]` matched both real annotation elements AND `annotation-outdated-notice` (which also starts with "annotation-"), inflating the count to 2 instead of 0. Added `:not([data-testid="annotation-outdated-notice"])` to exclude the notice from the count assertion. Co-Authored-By: Claude Sonnet 4.6 --- frontend/e2e/documents.spec.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/frontend/e2e/documents.spec.ts b/frontend/e2e/documents.spec.ts index 8ddac2b1..20c9a976 100644 --- a/frontend/e2e/documents.spec.ts +++ b/frontend/e2e/documents.spec.ts @@ -327,10 +327,12 @@ test.describe('PDF annotations — admin', () => { await page.waitForSelector('[data-hydrated]'); await page.locator('canvas').first().waitFor({ state: 'visible', timeout: 20000 }); - // Ensure annotation is visible before enabling annotate mode + // Ensure at least one annotation is visible before enabling annotate mode await expect(page.locator('[data-testid^="annotation-"]').first()).toBeVisible({ timeout: 8000 }); + // Record count now — the draw test may have created more than one annotation + const countBefore = await page.locator('[data-testid^="annotation-"]').count(); // Enable annotate mode to show delete buttons await page.getByRole('button', { name: /^annotieren$/i }).click(); @@ -339,7 +341,7 @@ test.describe('PDF annotations — admin', () => { await expect(deleteBtn).toBeVisible({ timeout: 8000 }); await deleteBtn.click(); - await expect(page.locator('[data-testid^="annotation-"]')).toHaveCount(0, { + await expect(page.locator('[data-testid^="annotation-"]')).toHaveCount(countBefore - 1, { timeout: 8000 }); @@ -407,7 +409,10 @@ test.describe('PDF annotations — file hash versioning', () => { await page.waitForSelector('[data-hydrated]'); await page.locator('canvas').first().waitFor({ state: 'visible', timeout: 20000 }); - await expect(page.locator('[data-testid^="annotation-"]')).toHaveCount(0, { timeout: 8000 }); + // Use :not() to exclude the outdated-notice element whose testid also starts with "annotation-" + await expect( + page.locator('[data-testid^="annotation-"]:not([data-testid="annotation-outdated-notice"])') + ).toHaveCount(0, { timeout: 8000 }); await expect(page.locator('[data-testid="annotation-outdated-notice"]')).toBeVisible({ timeout: 5000 });