Skip to content

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

Deflake maps zoom/pan settle detection (#76383)

github-automation-metabase3b340f98e54b
diff --git a/e2e/test/scenarios/visualizations-charts/maps.cy.spec.js b/e2e/test/scenarios/visualizations-charts/maps.cy.spec.js
index 47d57ad87cf..76eeac4d4e8 100644
--- a/e2e/test/scenarios/visualizations-charts/maps.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-charts/maps.cy.spec.js
@@ -512,21 +512,38 @@ function zoomIn(times) {
}
}
-// Resolve the first marker's rect only once its position stops changing between polls,
-// so we read a settled position instead of racing leaflet's animation (metabase#11211).
+// Resolve the first marker's rect only once its position has held steady for a real
+// time window, so we read a settled position instead of racing leaflet's animation
+// (metabase#11211). Comparing only two consecutive `.should()` retries is not enough:
+// Cypress retries faster than the browser repaints, so two reads can land within the
+// same animation frame and return an identical `getBoundingClientRect()` mid-animation
+// — a false settle. Anchoring on elapsed time (performance.now) instead of read-count
+// guarantees the marker has genuinely stopped moving before we sample it.
+const SETTLE_TOLERANCE_PX = 0.5;
+const SETTLE_HOLD_MS = 200;
+
function getSettledMarkerPosition() {
- let previous;
+ let anchor = null;
+ let anchorAt = 0;
return cy
.get(".leaflet-marker-icon")
.first()
.should(($marker) => {
const rect = $marker[0].getBoundingClientRect();
- const settled =
- previous != null &&
- Math.abs(rect.left - previous.left) < 0.5 &&
- Math.abs(rect.top - previous.top) < 0.5;
- previous = rect;
- expect(settled, "leaflet marker position should be settled").to.be.true;
+ const now = performance.now();
+ const stable =
+ anchor != null &&
+ Math.abs(rect.left - anchor.left) < SETTLE_TOLERANCE_PX &&
+ Math.abs(rect.top - anchor.top) < SETTLE_TOLERANCE_PX;
+ if (!stable) {
+ // Position moved (or first read) — reset the anchor and restart the timer.
+ anchor = rect;
+ anchorAt = now;
+ }
+ expect(
+ stable && now - anchorAt >= SETTLE_HOLD_MS,
+ "leaflet marker position should be settled",
+ ).to.be.true;
})
- .then(() => previous);
+ .then(() => anchor);
}