The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
Fix flaky dashboard parameter-removal e2e test (#78302)
github-automation-metabasedc81dff8700f
diff --git a/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js b/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.jsindex a5d9fb4f952..21b532ebfb1 100644--- a/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js+++ b/e2e/test/scenarios/dashboard-filters/parameters.cy.spec.js@@ -17,6 +17,18 @@ import {const { ORDERS_ID, ORDERS, PRODUCTS, PRODUCTS_ID, PEOPLE, PEOPLE_ID } =SAMPLE_DATABASE;+// Assert the dashboard URL's query params match `expected`, regardless of the+// order in which the slugs are serialized. That order is not deterministic, so+// asserting on the exact search string is flaky (metabase#17933). Comparing the+// parsed params also sidesteps async-update timing, since `.should(callback)`+// retries until the URL settles.+const expectSearchParams = (expected) =>+ cy.location("search").should((search) => {+ expect(Object.fromEntries(new URLSearchParams(search))).to.deep.eq(+ expected,+ );+ });+describe("scenarios > dashboard > parameters", () => {const cards = [{@@ -135,10 +147,7 @@ describe("scenarios > dashboard > parameters", () => {cy.button("Add filter").click();- cy.location("search").should(- "eq",- `?${endsWith.slug}=&${startsWith.slug}=G`,- );+ expectSearchParams({ [endsWith.slug]: "", [startsWith.slug]: "G" });// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("37.65").should("not.exist");@@ -153,10 +162,7 @@ describe("scenarios > dashboard > parameters", () => {cy.button("Add filter").click();- cy.location("search").should(- "eq",- `?${endsWith.slug}=zmo&${startsWith.slug}=G`,- );+ expectSearchParams({ [endsWith.slug]: "zmo", [startsWith.slug]: "G" });// eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usagecy.findByText("52.72").should("not.exist");@@ -164,9 +170,17 @@ describe("scenarios > dashboard > parameters", () => {cy.icon("pencil").click();H.filterWidget({ isEditing: true, name: startsWith.name }).click();- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText("Remove").click();- cy.location("search").should("eq", `?${endsWith.slug}=zmo`);+ // The sidebar's Remove button is disabled until the dashboard's+ // subscriptions have loaded (it warns before archiving any bound to this+ // filter). Target the button element itself — not its inner label — so+ // Cypress's actionability check waits for it to become enabled; clicking+ // the label span while the button is still disabled is a silent no-op, and+ // the filter is never removed (metabase#17933).+ cy.findByTestId("dashboard-parameter-sidebar")+ .findByRole("button", { name: "Remove" })+ .should("be.enabled")+ .click();+ expectSearchParams({ [endsWith.slug]: "zmo" });H.saveDashboard();@@ -176,7 +190,7 @@ describe("scenarios > dashboard > parameters", () => {H.filterWidget().contains(new RegExp(`${endsWith.name}`, "i"));- cy.location("search").should("eq", `?${endsWith.slug}=zmo`);+ expectSearchParams({ [endsWith.slug]: "zmo" });});it("should handle mismatch between filter types (metabase#9299, metabase#16181)", () => {