From 7cb02ab6be5ccfd80336c91b6066f9f3a6bb29d2 Mon Sep 17 00:00:00 2001
From: "Mahatthana (Kelvin) Nomsawadi" <me@bboykelvin.dev>
Date: Tue, 28 Mar 2023 11:27:51 +0100
Subject: [PATCH] Add a reproduction for dashboard sticky filter incorrectly
 positioned when moving between dashboards (#29497)

* Add a repro for #26230

* Move the prep phase to the `beforeEach`

* Use `visitDashboard` helper

* Wait for the second dashboard to load

* You don't have to use `within` here

* Add a comment

* Add main repro assertion

* Greatly simplify creation of the markdown card

* Update the test title

---------

Co-authored-by: Nemanja <31325167+nemanjaglumac@users.noreply.github.com>
---
 ...y-filter-incorrectly-positioned.cy.spec.js | 94 +++++++++++++++++++
 1 file changed, 94 insertions(+)
 create mode 100644 e2e/test/scenarios/dashboard/reproductions/26230-dashboard-sticky-filter-incorrectly-positioned.cy.spec.js

diff --git a/e2e/test/scenarios/dashboard/reproductions/26230-dashboard-sticky-filter-incorrectly-positioned.cy.spec.js b/e2e/test/scenarios/dashboard/reproductions/26230-dashboard-sticky-filter-incorrectly-positioned.cy.spec.js
new file mode 100644
index 00000000000..b73bf014ecc
--- /dev/null
+++ b/e2e/test/scenarios/dashboard/reproductions/26230-dashboard-sticky-filter-incorrectly-positioned.cy.spec.js
@@ -0,0 +1,94 @@
+import { restore, visitDashboard } from "e2e/support/helpers";
+
+describe("issue 26230", () => {
+  beforeEach(() => {
+    restore();
+    cy.signInAsAdmin();
+
+    prepareAndVisitDashboards();
+  });
+
+  it("should not preserve the sticky filter behavior when navigating to the second dashboard (metabase#26230)", () => {
+    cy.findByRole("main").scrollTo("bottom"); // This line is essential for the reproduction!
+
+    cy.button("Toggle sidebar").click();
+    cy.findByRole("main")
+      .findByDisplayValue("dashboard with a tall card 2")
+      .should("not.be.visible");
+
+    cy.findByTestId("dashboard-parameters-widget-container").should(
+      "have.css",
+      "position",
+      "fixed",
+    );
+
+    cy.intercept("GET", "/api/dashboard/*").as("loadDashboard");
+    cy.findByRole("listitem", { name: "dashboard with a tall card" }).click();
+    cy.wait("@loadDashboard");
+
+    cy.findByTestId("dashboard-parameters-widget-container").should(
+      "not.have.css",
+      "position",
+      "fixed",
+    );
+  });
+});
+
+function prepareAndVisitDashboards() {
+  cy.createDashboard({
+    name: "dashboard with a tall card",
+    parameters: [
+      {
+        id: "12345678",
+        name: "Text",
+        slug: "text",
+        type: "string/=",
+        sectionId: "string",
+      },
+    ],
+  }).then(({ body: { id } }) => {
+    createTextDashcard(id);
+    bookmarkDashboard(id);
+  });
+
+  cy.createDashboard({
+    name: "dashboard with a tall card 2",
+    parameters: [
+      {
+        id: "87654321",
+        name: "Text",
+        slug: "text",
+        type: "string/=",
+        sectionId: "string",
+      },
+    ],
+  }).then(({ body: { id } }) => {
+    createTextDashcard(id);
+    bookmarkDashboard(id);
+    visitDashboard(id);
+  });
+}
+
+function bookmarkDashboard(dashboardId) {
+  cy.request("POST", `/api/bookmark/dashboard/${dashboardId}`);
+}
+
+function createTextDashcard(id) {
+  cy.request("POST", `/api/dashboard/${id}/cards`, {
+    cardId: null,
+    col: 0,
+    row: 0,
+    size_x: 4,
+    size_y: 20,
+    visualization_settings: {
+      virtual_card: {
+        name: null,
+        display: "text",
+        visualization_settings: {},
+        dataset_query: {},
+        archived: false,
+      },
+      text: "I am a tall card",
+    },
+  });
+}
-- 
GitLab