Skip to content

Commit 8d5262c

Browse files
committed
✅(e2e) fix flaky tests
Some tests were flaky, we improved their stability.
1 parent 1125f44 commit 8d5262c

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

src/frontend/apps/e2e/__tests__/app-impress/doc-routing.spec.ts

Lines changed: 22 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -60,35 +60,30 @@ test.describe('Doc Routing', () => {
6060

6161
await page.locator('.ProseMirror.bn-editor').fill('Hello World');
6262

63-
// Wait for the doc link (via its dynamic title) to be visible
64-
const docLink = page.getByRole('link', { name: docTitle });
65-
await expect(docLink).toBeVisible();
66-
67-
// Intercept GET/PATCH requests to return 401
68-
await page.route(/.*\/documents\/.*\/$|users\/me\/$/, async (route) => {
69-
const request = route.request();
70-
if (
71-
request.method().includes('PATCH') ||
72-
request.method().includes('GET')
73-
) {
74-
await route.fulfill({
75-
status: 401,
76-
json: { detail: 'Log in to access the document' },
77-
});
78-
} else {
79-
await route.continue();
80-
}
81-
});
82-
83-
// Explicitly wait for a 401 response after clicking
84-
const wait401 = page.waitForResponse(
85-
(resp) =>
86-
resp.status() === 401 &&
87-
/\/(documents\/[^/]+\/|users\/me\/)$/.test(resp.url()),
63+
const responsePromise = page.route(
64+
/.*\/documents\/.*\/$|users\/me\/$/,
65+
async (route) => {
66+
const request = route.request();
67+
68+
if (
69+
request.method().includes('PATCH') ||
70+
request.method().includes('GET')
71+
) {
72+
await route.fulfill({
73+
status: 401,
74+
json: {
75+
detail: 'Log in to access the document',
76+
},
77+
});
78+
} else {
79+
await route.continue();
80+
}
81+
},
8882
);
8983

90-
await docLink.click();
91-
await wait401;
84+
await page.getByRole('link', { name: '401-doc-parent' }).click();
85+
86+
await responsePromise;
9287

9388
await expect(page.getByText('Log in to access the document.')).toBeVisible({
9489
timeout: 10000,

src/frontend/apps/e2e/__tests__/app-impress/utils-sub-pages.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,10 @@ export const navigateToPageFromTree = async ({
117117
title: string;
118118
}) => {
119119
const docTree = page.getByTestId('doc-tree');
120-
await docTree.getByText(title).click();
120+
await docTree
121+
.getByText(title, {
122+
exact: true,
123+
})
124+
.click();
121125
await verifyDocName(page, title);
122126
};

0 commit comments

Comments
 (0)