Skip to content

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

Fix flaky homepage x-ray save test (#75424)

Nemanja Glumac7c0b9e43e252
diff --git a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
index 65c6ff52199..153d3ee4045 100644
--- a/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
+++ b/e2e/test/scenarios/onboarding/home/homepage.cy.spec.js
@@ -93,9 +93,26 @@ describe("scenarios > home > homepage", () => {
triggered_from: "suggestion_sidebar",
});
- cy.intercept("POST", "/api/dashboard/save").as("saveDashboard");
+ // Wait for the final x-ray dashboard to actually be ready before saving.
+ // `@getXrayDashboard` only confirms the automagic metadata GET; the dashboard isn't in
+ // the store yet. Once it is, `useDashboardUrlQuery`
+ // (frontend/src/metabase/dashboard/hooks/use-dashboard-url-query.ts) syncs the
+ // dashboard's parameters into the URL (dispatch(replace(...))), so the query string
+ // becomes populated. That is a reliable "dashboard is ready" signal; clicking
+ // "Save this" before it means the dashboard isn't ready and the save is lost.
+ cy.location("search").should("not.be.empty");
+
cy.findByTestId("automatic-dashboard-header").button("Save this").click();
- cy.wait("@saveDashboard");
+
+ // Assert the save succeeded via the resulting UI — the header switches to a "Saved"
+ // button + "See it" link — rather than waiting on the POST /api/dashboard/save
+ // request. The request-alias wait was timing-sensitive and flaked with "No request
+ // ever occurred"; the saved-state UI is the real user-observable outcome and Cypress
+ // retries it until the save completes.
+ cy.findByTestId("automatic-dashboard-header").within(() => {
+ cy.findByText("See it").should("be.visible");
+ cy.findByText("Saved").should("be.visible");
+ });
H.expectUnstructuredSnowplowEvent({
event: "x-ray_saved",
diff --git a/frontend/src/metabase/dashboard/containers/AutomaticDashboardApp/AutomaticDashboardApp.tsx b/frontend/src/metabase/dashboard/containers/AutomaticDashboardApp/AutomaticDashboardApp.tsx
index 60a538f9b31..70ef750a57d 100644
--- a/frontend/src/metabase/dashboard/containers/AutomaticDashboardApp/AutomaticDashboardApp.tsx
+++ b/frontend/src/metabase/dashboard/containers/AutomaticDashboardApp/AutomaticDashboardApp.tsx
@@ -146,6 +146,11 @@ const AutomaticDashboardAppInner = () => {
className={cx(CS.mlAuto, CS.textNoWrap)}
success
borderless
+ // The dashboard isn't always loaded when the header first
+ // renders. Without this guard, "Save this" is clickable while
+ // `dashboard` is undefined, which fires a false `x-ray_saved`
+ // event and no-ops `save()` (no save request is sent).
+ disabled={!dashboard}
actionFn={() => {
trackXRaySaved();
return save();