Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix click-behavior multi-stage e2e flake: settle mapping list between selections (#78602)

github-automation-metabase29cefea9f5be
diff --git a/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js b/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
index 7da0962538d..f4e7ab0d8e8 100644
--- a/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
+++ b/e2e/test/scenarios/dashboard-cards/click-behavior.cy.spec.js
@@ -2115,45 +2115,45 @@ describe("scenarios > dashboard > dashboard cards > click behavior", () => {
// 1st stage - Orders
getClickMapping("ID").click();
- H.popover().findByText("ID").click();
+ selectClickMappingSource("ID");
// 1st stage - Custom columns
getClickMapping("Net").click();
- H.popover().findByText("User → Longitude: 10°").click();
+ selectClickMappingSource("User → Longitude: 10°");
// 1st stage - Reviews #1 (explicit join)
getClickMapping("Reviews - Product → Reviewer").click();
- H.popover().findByText("Product → Category").click();
+ selectClickMappingSource("Product → Category");
// 1st stage - Products (implicit join with Orders)
getClickMapping("Product → Title").first().click();
- H.popover().findByText("Product → Category").click();
+ selectClickMappingSource("Product → Category");
// 1st stage - People (implicit join with Orders)
getClickMapping("User → Longitude").click();
- H.popover().findByText("User → Longitude: 10°").click();
+ selectClickMappingSource("User → Longitude: 10°");
// 1st stage - Products (implicit join with Reviews)
// eslint-disable-next-line metabase/no-unsafe-element-filtering
getClickMapping("Product → Vendor").last().click();
- H.popover().findByText("Product → Category").click();
+ selectClickMappingSource("Product → Category");
// 1st stage - Aggregations & breakouts
getClickMapping("Product → Category").eq(2).click();
- H.popover().findByText("Product → Category").click();
+ selectClickMappingSource("Product → Category");
// 2nd stage - Custom columns
getClickMapping("5 * Count").click();
- H.popover().findByText("Count").click();
+ selectClickMappingSource("Count");
// 2nd stage - Reviews #2 (explicit join)
getClickMapping("Reviews - Created At: Month → Rating").click();
- H.popover().findByText("ID").click();
+ selectClickMappingSource("ID");
// 2nd stage - Aggregations & breakouts
// eslint-disable-next-line metabase/no-unsafe-element-filtering
getClickMapping("Count").last().click();
- H.popover().findByText("User → Longitude: 10°").click();
+ selectClickMappingSource("User → Longitude: 10°");
customizeLinkText(`Created at: {{${CREATED_AT_COLUMN_ID}}} - {{count}}`);
@@ -3005,6 +3005,21 @@ function getClickMapping(columnName) {
.findAllByText(columnName);
}
+// Picks a source from the open click-mapping popover and waits for it to close.
+// Applying a mapping re-renders the unset-mappings list; without this barrier the
+// next index-based lookup (.first()/.last()/.eq()) can resolve mid-re-render and
+// land on the wrong target, producing a stable-but-wrong filter set.
+//
+// The barrier scopes to the *visible* popover: a bare
+// `cy.get(POPOVER_ELEMENT).should("not.exist")` never settles here because the
+// click-behavior sidebar keeps ~60 mantine popover/combobox dropdowns
+// mounted-but-hidden, so they are "continuously found" in the DOM. Filtering to
+// `:visible` leaves only the open source picker, which disappears once selected.
+function selectClickMappingSource(sourceName) {
+ H.popover().findByText(sourceName).click();
+ cy.get(H.POPOVER_ELEMENT).filter(":visible").should("not.exist");
+}
+
function verifyAvailableClickTargetColumns(columns) {
cy.get("aside").within(() => {
for (let index = 0; index < columns.length; ++index) {