Skip to content

Commit 70b9cab

Browse files
authored
test: deflake indexed e2e (#11911)
### What? This PR aims to deflake the indexed fields e2e test in `test/fields/collections/Indexed/e2e.spec.ts`. The issue is that this test is setup in a way where sometimes two toasts will present themselves in the ui. The second toast assertion will fail with a strict mode violation as the toast locator will resolve to two elements. ### Why? To prevent this test from flaking in ci. ### How? Adding a new `dismissAfterAssertion` flag to the `assertToastErrors` helper function which dismisses the toasts. This way, the toasts will not raise the aforementioned error as they will be dismissed from the ui. The logic is handled in a separate loop through such that the assertions occur first. This is done so that dismissing a toast does not surface errors due to the order of toasts being shown changing.
1 parent 4a0bc86 commit 70b9cab

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

test/fields/collections/Indexed/e2e.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ describe('Radio', () => {
100100
await assertToastErrors({
101101
page,
102102
errors: ['uniqueText'],
103+
dismissAfterAssertion: true,
103104
})
104105

105106
await expect.poll(() => page.url(), { timeout: POLL_TOPASS_TIMEOUT }).toContain('create')

test/helpers/assertToastErrors.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { expect } from '@playwright/test'
55
export async function assertToastErrors({
66
page,
77
errors,
8+
dismissAfterAssertion,
89
}: {
10+
dismissAfterAssertion?: boolean
911
errors: string[]
1012
page: Page
1113
}): Promise<void> {
@@ -24,4 +26,13 @@ export async function assertToastErrors({
2426
).toHaveText(error)
2527
}
2628
}
29+
30+
if (dismissAfterAssertion) {
31+
const closeButtons = page.locator('.payload-toast-container button.payload-toast-close-button')
32+
const count = await closeButtons.count()
33+
34+
for (let i = 0; i < count; i++) {
35+
await closeButtons.nth(i).click()
36+
}
37+
}
2738
}

0 commit comments

Comments
 (0)