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