From 8d5262c2f2b7411d3d4b7f4de02d98d1c15f14ee Mon Sep 17 00:00:00 2001 From: Anthony LC Date: Tue, 14 Oct 2025 14:18:32 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=85(e2e)=20fix=20flaky=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some tests were flaky, we improved their stability. --- .../__tests__/app-impress/doc-routing.spec.ts | 47 +++++++++---------- .../__tests__/app-impress/utils-sub-pages.ts | 6 ++- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts b/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts index 5800a66b..42931b1c 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts @@ -60,35 +60,30 @@ test.describe('Doc Routing', () => { await page.locator('.ProseMirror.bn-editor').fill('Hello World'); - // Wait for the doc link (via its dynamic title) to be visible - const docLink = page.getByRole('link', { name: docTitle }); - await expect(docLink).toBeVisible(); + const responsePromise = page.route( + /.*\/documents\/.*\/$|users\/me\/$/, + async (route) => { + const request = route.request(); - // Intercept GET/PATCH requests to return 401 - await page.route(/.*\/documents\/.*\/$|users\/me\/$/, async (route) => { - const request = route.request(); - if ( - request.method().includes('PATCH') || - request.method().includes('GET') - ) { - await route.fulfill({ - status: 401, - json: { detail: 'Log in to access the document' }, - }); - } else { - await route.continue(); - } - }); - - // Explicitly wait for a 401 response after clicking - const wait401 = page.waitForResponse( - (resp) => - resp.status() === 401 && - /\/(documents\/[^/]+\/|users\/me\/)$/.test(resp.url()), + if ( + request.method().includes('PATCH') || + request.method().includes('GET') + ) { + await route.fulfill({ + status: 401, + json: { + detail: 'Log in to access the document', + }, + }); + } else { + await route.continue(); + } + }, ); - await docLink.click(); - await wait401; + await page.getByRole('link', { name: '401-doc-parent' }).click(); + + await responsePromise; await expect(page.getByText('Log in to access the document.')).toBeVisible({ timeout: 10000, diff --git a/src/frontend/apps/e2e/__tests__/app-impress/utils-sub-pages.ts b/src/frontend/apps/e2e/__tests__/app-impress/utils-sub-pages.ts index 5a0229ff..b4971230 100644 --- a/src/frontend/apps/e2e/__tests__/app-impress/utils-sub-pages.ts +++ b/src/frontend/apps/e2e/__tests__/app-impress/utils-sub-pages.ts @@ -117,6 +117,10 @@ export const navigateToPageFromTree = async ({ title: string; }) => { const docTree = page.getByTestId('doc-tree'); - await docTree.getByText(title).click(); + await docTree + .getByText(title, { + exact: true, + }) + .click(); await verifyDocName(page, title); };