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
Deflake dashboard title-drill anchor href assertions (#80739)
Andersonadc97eaff25c
diff --git a/e2e/test/scenarios/dashboard/title-drill.cy.spec.js b/e2e/test/scenarios/dashboard/title-drill.cy.spec.jsindex 1b3c9267864..0a77181095f 100644--- a/e2e/test/scenarios/dashboard/title-drill.cy.spec.js+++ b/e2e/test/scenarios/dashboard/title-drill.cy.spec.js@@ -499,12 +499,12 @@ describe("scenarios > dashboard > title drill", () => {{ row: 6, col: 6, size_x: 6, size_y: 6 },],}).then(({ dashboard, questions }) => {- H.visitDashboard(dashboard.id);+ // Park the cursor off the grid before the dashcards render: a pointer+ // resting over a title computes that title's href before it is asserted.+ cy.get("body").realHover({ position: "topLeft" });- // make cursor start from a place where subsequent realHover() calls- // won't make the cursor move over the other cards during test- // (which would interfere with assertions)- cy.findByTestId("sidebar-toggle").realHover();+ H.visitDashboard(dashboard.id);+ H.waitForDashcardsToLoad({ count: 4 });H.getDashboardCard(0).findByRole("link", { name: "Line chart" })@@ -519,35 +519,58 @@ describe("scenarios > dashboard > title drill", () => {.findByRole("link", { name: "Funnel chart" }).as("funnel-chart-title");- assertTitleHrefOnFocus({- elementAlias: "@line-chart-title",- href: `/question/${questions[0].id}-line-chart`,- });- assertTitleHrefOnFocus({- elementAlias: "@row-chart-title",- href: `/question/${questions[1].id}-row-chart`,- });- assertTitleHrefOnHover({- elementAlias: "@map-chart-title",- href: `/question/${questions[2].id}-map-chart`,- });- assertTitleHrefOnHover({- elementAlias: "@funnel-chart-title",- href: `/question/${questions[3].id}-funnel-chart`,+ const titles = [+ {+ elementAlias: "@line-chart-title",+ href: `/question/${questions[0].id}-line-chart`,+ trigger: focusTitle,+ },+ {+ elementAlias: "@row-chart-title",+ href: `/question/${questions[1].id}-row-chart`,+ trigger: focusTitle,+ },+ {+ elementAlias: "@map-chart-title",+ href: `/question/${questions[2].id}-map-chart`,+ trigger: hoverTitle,+ },+ {+ elementAlias: "@funnel-chart-title",+ href: `/question/${questions[3].id}-funnel-chart`,+ trigger: hoverTitle,+ },+ ];++ cy.log("every title is an inert placeholder before focus and hover");+ titles.forEach(({ elementAlias }) => {+ cy.get(elementAlias).should("have.attr", "href", "#");});++ cy.log("focusing or hovering a title turns it into a question anchor");+ titles.forEach(assertTitleBecomesQuestionAnchor);});});- function assertTitleHrefOnFocus({ elementAlias, href }) {- cy.get(elementAlias).should("have.attr", "href", "#");- cy.get(elementAlias).focus();- cy.get(elementAlias).should("have.attr", "href", href);+ function focusTitle(element) {+ element.focus();+ }++ function hoverTitle(element) {+ const { MouseEvent } = element.ownerDocument.defaultView;+ element.dispatchEvent(new MouseEvent("mouseover", { bubbles: true }));}- function assertTitleHrefOnHover({ elementAlias, href }) {- cy.get(elementAlias).should("have.attr", "href", "#");- cy.get(elementAlias).realHover();- cy.get(elementAlias).should("have.attr", "href", href);+ /**+ * The question href is computed lazily on focus/mouseenter, and the anchor+ * is replaced when it resolves. Re-evaluating the trigger on each retry+ * keeps the assertion anchored to the node currently in the DOM.+ */+ function assertTitleBecomesQuestionAnchor({ elementAlias, href, trigger }) {+ cy.get(elementAlias).should(($el) => {+ trigger($el[0]);+ expect($el).to.have.attr("href", href);+ });}});