From 6c9099bfd50e9030a9919add2e71fa60dc0d7d15 Mon Sep 17 00:00:00 2001 From: Kamil Mielnik <kamil@kamilmielnik.com> Date: Thu, 9 May 2024 19:02:25 +0700 Subject: [PATCH] Fix flaky question management e2e test (#42444) * Fix flaky question management test * Update assertions order to reduce probability of a flake * Use explicit assertions * Change assertion order * Decrease flakiness --- .../question/question-management.cy.spec.js | 62 +++++++++++-------- 1 file changed, 37 insertions(+), 25 deletions(-) diff --git a/e2e/test/scenarios/question/question-management.cy.spec.js b/e2e/test/scenarios/question/question-management.cy.spec.js index ec553bfb96a..95893d331e0 100644 --- a/e2e/test/scenarios/question/question-management.cy.spec.js +++ b/e2e/test/scenarios/question/question-management.cy.spec.js @@ -59,7 +59,8 @@ describe( .click() .type("1") .blur(); - assertOnRequest("updateQuestion"); + assertRequestNot403("updateQuestion"); + assertNoPermissionsError(); // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage cy.findByText("Orders1"); }); @@ -71,7 +72,8 @@ describe( .type("foo", { delay: 0 }) .blur(); - assertOnRequest("updateQuestion"); + assertRequestNot403("updateQuestion"); + assertNoPermissionsError(); // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage cy.findByText("foo"); @@ -91,16 +93,17 @@ describe( }); moveQuestionTo(/Personal Collection/); - assertOnRequest("updateQuestion"); - // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage - cy.contains("37.65"); - - // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage - cy.contains( - `Question moved to ${getPersonalCollectionName( - USERS[user], - )}`, - ); + assertRequestNot403("updateQuestion"); + + cy.findAllByRole("status") + .contains( + `Question moved to ${getPersonalCollectionName( + USERS[user], + )}`, + ) + .should("exist"); + assertNoPermissionsError(); + cy.findAllByRole("gridcell").contains("37.65"); navigationSidebar().within(() => { // Highlight "Your personal collection" after move @@ -135,7 +138,7 @@ describe( cy.get("header").findByText(NEW_COLLECTION_NAME); }); - it("should be able to move models", () => { + it("should be able to move models", { tags: "@flaky" }, () => { // TODO: Currently nodata users can't turn a question into a model cy.skipOn(user === "nodata"); @@ -153,14 +156,17 @@ describe( }); moveQuestionTo(/Personal Collection/); - assertOnRequest("updateQuestion"); - // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage - cy.contains("37.65"); - - // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage - cy.contains( - `Model moved to ${getPersonalCollectionName(USERS[user])}`, - ); + assertRequestNot403("updateQuestion"); + + cy.findAllByRole("status") + .contains( + `Model moved to ${getPersonalCollectionName( + USERS[user], + )}`, + ) + .should("exist"); + assertNoPermissionsError(); + cy.findAllByRole("gridcell").contains("37.65"); navigationSidebar().within(() => { // Highlight "Your personal collection" after move @@ -185,7 +191,8 @@ describe( "It will also be removed from the filter that uses it to populate values.", ).should("not.exist"); clickButton("Archive"); - assertOnRequest("updateQuestion"); + assertRequestNot403("updateQuestion"); + assertNoPermissionsError(); cy.wait("@getItems"); // pinned items cy.wait("@getItems"); // unpinned items cy.location("pathname").should("eq", "/collection/root"); @@ -447,11 +454,13 @@ function clickButton(name) { cy.button(name).should("not.be.disabled").click(); } -function assertOnRequest(xhr_alias) { +function assertRequestNot403(xhr_alias) { cy.wait("@" + xhr_alias).then(xhr => { expect(xhr.status).not.to.eq(403); }); +} +function assertNoPermissionsError() { cy.findByText("Sorry, you don’t have permission to see that.").should( "not.exist", ); @@ -459,8 +468,11 @@ function assertOnRequest(xhr_alias) { function turnIntoModel() { openQuestionActions(); - cy.findByText("Turn into a model").click(); - cy.findByText("Turn this into a model").click(); + cy.findByRole("dialog").contains("Turn into a model").click(); + cy.findByRole("dialog").contains("Turn this into a model").click(); + assertRequestNot403("updateQuestion"); + cy.findAllByRole("status").contains("This is a model now.").should("exist"); + assertNoPermissionsError(); } function findPickerItem(name) { -- GitLab