Skip to content

Commit 7352d09

Browse files
fix for cypress race condition on email list refresh
1 parent 4dbecad commit 7352d09

1 file changed

Lines changed: 25 additions & 2 deletions

File tree

cypress/e2e/user-journeys/admin/emails.cy.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,30 @@ import { dataCy, getModalByHeader, logout } from "cypress/support/utils/common";
77

88
const dataInviteUser = mockedInvitedUser();
99

10+
const refreshUntilFirstRowMatches = (
11+
predicate: (firstRowText: string) => boolean,
12+
maxAttempts = 5,
13+
attempts = 0
14+
) => {
15+
cy.get(dataCy("emails-list"))
16+
.find("tbody tr")
17+
.should("have.length.greaterThan", 0)
18+
.first()
19+
.then($row => {
20+
if (predicate($row.text())) {
21+
return;
22+
}
23+
24+
if (attempts >= maxAttempts) {
25+
throw new Error("Timed out waiting for first row to match condition");
26+
}
27+
28+
cy.contains("button", "Update").click();
29+
cy.wait(1000);
30+
refreshUntilFirstRowMatches(predicate, maxAttempts, attempts + 1);
31+
});
32+
};
33+
1034
describe("Resend invite", () => {
1135
before(() => {
1236
loginAdmin();
@@ -29,8 +53,7 @@ describe("Resend invite", () => {
2953
});
3054

3155
it("Shows a list of emails", () => {
32-
cy.contains("button", "Update").click();
33-
56+
refreshUntilFirstRowMatches(text => text.includes(dataInviteUser.email));
3457
cy.get(dataCy("emails-list"))
3558
.find("tbody tr")
3659
.should("exist")

0 commit comments

Comments
 (0)