(e2e) fix flaky tests

Some tests were flaky, we improved their stability.
This commit is contained in:
Anthony LC
2025-10-14 14:18:32 +02:00
parent 1125f441dc
commit 8d5262c2f2
2 changed files with 26 additions and 27 deletions

View File

@@ -60,35 +60,30 @@ test.describe('Doc Routing', () => {
await page.locator('.ProseMirror.bn-editor').fill('Hello World'); await page.locator('.ProseMirror.bn-editor').fill('Hello World');
// Wait for the doc link (via its dynamic title) to be visible const responsePromise = page.route(
const docLink = page.getByRole('link', { name: docTitle }); /.*\/documents\/.*\/$|users\/me\/$/,
await expect(docLink).toBeVisible(); async (route) => {
// Intercept GET/PATCH requests to return 401
await page.route(/.*\/documents\/.*\/$|users\/me\/$/, async (route) => {
const request = route.request(); const request = route.request();
if ( if (
request.method().includes('PATCH') || request.method().includes('PATCH') ||
request.method().includes('GET') request.method().includes('GET')
) { ) {
await route.fulfill({ await route.fulfill({
status: 401, status: 401,
json: { detail: 'Log in to access the document' }, json: {
detail: 'Log in to access the document',
},
}); });
} else { } else {
await route.continue(); 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()),
); );
await docLink.click(); await page.getByRole('link', { name: '401-doc-parent' }).click();
await wait401;
await responsePromise;
await expect(page.getByText('Log in to access the document.')).toBeVisible({ await expect(page.getByText('Log in to access the document.')).toBeVisible({
timeout: 10000, timeout: 10000,

View File

@@ -117,6 +117,10 @@ export const navigateToPageFromTree = async ({
title: string; title: string;
}) => { }) => {
const docTree = page.getByTestId('doc-tree'); const docTree = page.getByTestId('doc-tree');
await docTree.getByText(title).click(); await docTree
.getByText(title, {
exact: true,
})
.click();
await verifyDocName(page, title); await verifyDocName(page, title);
}; };