From 54ffe92a6b6eba8311ec6aba0505bfdc3bf3cdd4 Mon Sep 17 00:00:00 2001
From: Uladzimir Havenchyk <125459446+uladzimirdev@users.noreply.github.com>
Date: Fri, 13 Sep 2024 16:58:27 +0300
Subject: [PATCH] fix broken test about resizing column by readonly user
 (#47916)

* fix broken test about resizing column by readonly user

* Update e2e/test/scenarios/question/saved.cy.spec.js

Co-authored-by: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>

---------

Co-authored-by: Nemanja Glumac <31325167+nemanjaglumac@users.noreply.github.com>
---
 e2e/test/scenarios/question/saved.cy.spec.js | 63 ++++++++------------
 1 file changed, 25 insertions(+), 38 deletions(-)

diff --git a/e2e/test/scenarios/question/saved.cy.spec.js b/e2e/test/scenarios/question/saved.cy.spec.js
index cfb3071c56a..6354e0d5447 100644
--- a/e2e/test/scenarios/question/saved.cy.spec.js
+++ b/e2e/test/scenarios/question/saved.cy.spec.js
@@ -251,44 +251,31 @@ describe("scenarios > question > saved", () => {
     });
   });
 
-  it(
-    "'read-only' user should be able to resize column width (metabase#9772)",
-    { tags: "@flaky" },
-    () => {
-      cy.signIn("readonly");
-      visitQuestion(ORDERS_QUESTION_ID);
-
-      // eslint-disable-next-line no-unscoped-text-selectors -- deprecated usage
-      cy.findByText("Tax")
-        .closest(".test-TableInteractive-headerCellData")
-        .as("headerCell")
-        .then($cell => {
-          const originalWidth = $cell[0].getBoundingClientRect().width;
-
-          // Retries the assertion a few times to ensure it waits for DOM changes
-          // More context: https://github.com/metabase/metabase/pull/21823#discussion_r855302036
-          function assertColumnResized(attempt = 0) {
-            cy.get("@headerCell").then($newCell => {
-              const newWidth = $newCell[0].getBoundingClientRect().width;
-              if (newWidth === originalWidth && attempt < 3) {
-                cy.wait(100);
-                assertColumnResized(++attempt);
-              } else {
-                expect(newWidth).to.be.gt(originalWidth);
-              }
-            });
-          }
-
-          cy.wrap($cell)
-            .find(".react-draggable")
-            .trigger("mousedown", 0, 0, { force: true })
-            .trigger("mousemove", 100, 0, { force: true })
-            .trigger("mouseup", 100, 0, { force: true });
-
-          assertColumnResized();
-        });
-    },
-  );
+  it("'read-only' user should be able to resize column width (metabase#9772)", () => {
+    cy.signIn("readonly");
+    visitQuestion(ORDERS_QUESTION_ID);
+
+    cy.findAllByTestId("header-cell")
+      .filter(":contains(Tax)")
+      .as("headerCell")
+      .then($cell => {
+        const originalWidth = $cell[0].getBoundingClientRect().width;
+        cy.wrap(originalWidth).as("originalWidth");
+      });
+
+    cy.get("@headerCell")
+      .find(".react-draggable")
+      .trigger("mousedown", { which: 1 })
+      .trigger("mousemove", { clientX: 100, clientY: 0 })
+      .trigger("mouseup", { force: true });
+
+    cy.get("@originalWidth").then(originalWidth => {
+      cy.get("@headerCell").should($newCell => {
+        const newWidth = $newCell[0].getBoundingClientRect().width;
+        expect(newWidth).to.be.gt(originalWidth);
+      });
+    });
+  });
 
   it("should always be possible to view the full title text of the saved question", () => {
     visitQuestion(ORDERS_QUESTION_ID);
-- 
GitLab