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
Replace flaky help text docs link e2e test with a unit test (#82954)
Nemanja Glumac9b193b09378a
diff --git a/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.js b/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.jsindex 288963c4a7f..246438972db 100644--- a/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.js+++ b/e2e/test/scenarios/custom-column/custom-column-reproductions-2.cy.spec.js@@ -6,35 +6,6 @@ import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";const { PRODUCTS, PRODUCTS_ID, ORDERS, ORDERS_ID } = SAMPLE_DATABASE;-describe("issue 54638", () => {- beforeEach(() => {- H.restore();- cy.signInAsNormalUser();- H.openOrdersTable({ mode: "notebook" });- H.addCustomColumn();- });-- it("should be possible to click documentation links in the expression editor help text popover (metabase#54638)", () => {- H.CustomExpressionEditor.type("case(");- H.CustomExpressionEditor.helpText().within(() => {- cy.findByText("Learn more")- .scrollIntoView()- .should("be.visible")- .then(($a) => {- expect($a).to.have.attr("target", "_blank");- // Update attr to open in same tab, since Cypress does not support- // testing in multiple tabs.- $a.attr("target", "_self");- })- .click();- cy.url().should(- "equal",- "https://www.metabase.com/docs/latest/questions/query-builder/expressions/case.html",- );- });- });-});-describe("issue #54722", () => {beforeEach(() => {H.restore();diff --git a/frontend/src/metabase/querying/components/expressions/Editor/HelpText/tests/common.unit.spec.tsx b/frontend/src/metabase/querying/components/expressions/Editor/HelpText/tests/common.unit.spec.tsxindex 0cb6da43be8..19f1b7c447f 100644--- a/frontend/src/metabase/querying/components/expressions/Editor/HelpText/tests/common.unit.spec.tsx+++ b/frontend/src/metabase/querying/components/expressions/Editor/HelpText/tests/common.unit.spec.tsx@@ -1,4 +1,4 @@-import { screen, within } from "@testing-library/react";+import { fireEvent, screen, within } from "@testing-library/react";import { getBrokenUpTextMatcher, waitFor } from "__support__/ui";@@ -32,6 +32,33 @@ describe("HelpText (OSS)", () => {);});+ it("should keep documentation link clicks from reaching the editor (metabase#54638)", async () => {+ await setup({+ enclosingFunction: {+ name: "case",+ },+ });++ const onDocumentMouseDown = jest.fn();+ document.addEventListener("mousedown", onDocumentMouseDown);++ const link = screen.getByRole("link", { name: /Learn more/ });+ expect(link).toHaveAttribute("target", "_blank");+ expect(link).toHaveAttribute(+ "href",+ "https://www.metabase.com/docs/latest/questions/query-builder/expressions/case.html",+ );++ fireEvent.mouseDown(link);+ expect(onDocumentMouseDown).not.toHaveBeenCalled();++ expect(link).toBeInTheDocument();+ // `false` when a handler calls `preventDefault()`, which cancels navigation+ expect(fireEvent.click(link)).toBe(true);++ document.removeEventListener("mousedown", onDocumentMouseDown);+ });+it("should handle expression function without arguments", async () => {await setup({enclosingFunction: {