(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');
// 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,

View File

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