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
Consolidate dashcard layout and editing e2e specs (#83872)
Nemanja Glumac8b8748477463
diff --git a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.jsindex fdd3ab5a7f8..9640c2fcc15 100644--- a/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashboard-reproductions.cy.spec.js@@ -96,76 +96,46 @@ describe("issue 12926", () => {}).as("dashcardQueryRestored");}- function removeCard() {- H.editDashboard();-- H.showDashboardCardActions();-- cy.findByTestId("dashboardcard-actions-panel")- .findByLabelText("close icon")- .click();- }-beforeEach(() => {H.restore();cy.signInAsAdmin();});- describe("card removal while query is in progress", () => {- it("should stop the ongoing query when removing a card from a dashboard", () => {- slowDownDashcardQuery();-- H.createNativeQuestionAndDashboard({- questionDetails,- }).then(({ body: { dashboard_id } }) => {- cy.visit(`/dashboard/${dashboard_id}`);- });-- // The query is deliberately slowed, so it is still in-flight here.- // The API client uses fetch, so cancelling the query aborts its- // AbortController rather than calling XMLHttpRequest.abort().- cy.window().then((win) => {- cy.spy(win.AbortController.prototype, "abort").as("queryAbort");- });+ it("should stop the ongoing query when removing a card, re-fetch it on undo, and undo a virtual card removal (metabase#35545)", () => {+ slowDownDashcardQuery();- removeCard();-- cy.get("@queryAbort").should("have.been.called");+ H.createNativeQuestionAndDashboard({+ questionDetails,+ }).then(({ body: { dashboard_id } }) => {+ cy.visit(`/dashboard/${dashboard_id}`);});- it("should re-fetch the query when doing undo on the removal", () => {- slowDownDashcardQuery();-- H.createNativeQuestionAndDashboard({- questionDetails,- }).then(({ body: { dashboard_id } }) => {- cy.visit(`/dashboard/${dashboard_id}`);- });-- removeCard();-- restoreDashcardQuery();-- H.undo();-- cy.wait("@dashcardQueryRestored");-- H.getDashboardCard().findByText(queryResult);+ // The API client uses fetch, so cancelling the query aborts its+ // AbortController rather than calling XMLHttpRequest.abort().+ cy.window().then((win) => {+ cy.spy(win.AbortController.prototype, "abort").as("queryAbort");});- it("should not break virtual cards (metabase#35545)", () => {- H.createDashboard().then(({ body: { id: dashboardId } }) => {- H.visitDashboard(dashboardId);- });-- H.addTextBox("Text card content");-- H.removeDashboardCard();+ H.editDashboard();+ H.showDashboardCardActions();+ H.getDashboardCard().findByTestId("loading-indicator").should("exist");+ cy.get("@queryAbort").invoke("resetHistory");+ cy.findByTestId("dashboardcard-actions-panel")+ .findByLabelText("close icon")+ .click();+ cy.get("@queryAbort").should("have.been.called");- H.undo();+ restoreDashcardQuery();+ H.undo();+ cy.wait("@dashcardQueryRestored");+ H.getDashboardCard().findByText(queryResult);- H.getDashboardCard().findByText("Text card content");- });+ H.addTextBoxWhileEditing("Text card content");+ H.getDashboardCards().should("have.length", 2);+ H.removeDashboardCard(1);+ H.getDashboardCards().should("have.length", 1);+ H.undo();+ H.getDashboardCard(1).findByText("Text card content");});describe("saving a dashboard that retriggers a non saved query (negative id)", () => {@@ -518,51 +488,6 @@ describe("issue 17879", () => {});});-describe("issue 21830", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("slow loading card visualization options click shouldn't lead to error (metabase#21830)", () => {- cy.intercept("GET", "/api/dashboard/*").as("getDashboard");- cy.intercept(- {- method: "POST",- url: "/api/dashboard/*/dashcard/*/card/*/query",- middleware: true,- },- (req) => {- req.on("response", (res) => {- // throttle the response to simulate a mobile 3G connection- res.setThrottle(100);- });- },- ).as("getCardQuery");-- cy.visit(`/dashboard/${ORDERS_DASHBOARD_ID}`);- cy.wait("@getDashboard");-- // it's crucial that we try to click on this icon BEFORE we wait for the `getCardQuery` response!- H.editDashboard();- H.showDashboardCardActions();-- H.getDashboardCard().within(() => {- cy.icon("close").should("be.visible");- cy.icon("click").should("not.exist");- cy.icon("palette").should("not.exist");- });-- cy.wait("@getCardQuery");-- H.getDashboardCard().within(() => {- cy.icon("close").should("be.visible");- cy.icon("click").should("be.visible");- cy.icon("palette").should("be.visible");- });- });-});-describe("issue 28756", () => {const UNRESTRICTED_COLLECTION_NAME = "Unrestricted collection";const RESTRICTED_COLLECTION_NAME = "Restricted collection";@@ -686,74 +611,44 @@ describe("issue 29076", () => {});describe("issue 31274", () => {- const createTextCards = (length) => {- return Array.from({ length }).map((_, index) => {- return H.getTextCardDetails({- size_x: 2,- size_y: 2,- row: (length - index - 1) * 2,- text: `Text ${index + 1}`,- });- });- };-- function visibleActionsPanel() {- return cy.findAllByTestId("dashboardcard-actions-panel").filter(":visible");- }-beforeEach(() => {H.restore();cy.signInAsAdmin();});it("should not clip dashcard actions (metabase#31274)", () => {- H.createDashboard().then(({ body: dashboard }) => {- const dashcards = createTextCards(3);- cy.request("PUT", `/api/dashboard/${dashboard.id}`, {- dashcards,- });-- H.visitDashboard(dashboard.id);- H.editDashboard(dashboard.id);-- H.assertTabSelected("Tab 1");-- H.getDashboardCard(1).realHover({- scrollBehavior: false, // prevents flaky tests- });-- cy.log(- "Make sure cypress can click the element, which means it is not covered by another",- );-- visibleActionsPanel().should("have.length", 1).icon("close").click({- position: "top",- scrollBehavior: false, // prevents flaky tests+ H.createDashboard().then(({ body: { id: dashboard_id } }) => {+ // The top card is created last, so it would come last in the DOM and+ // cover the actions of the card below if dashcards render in creation order+ H.updateDashboardCards({+ dashboard_id,+ cards: [H.getTextCardDetails({ row: 6, text: "Bottom card" })],+ }).then(({ body: { dashcards } }) => {+ H.updateDashboardCards({+ dashboard_id,+ cards: [+ ...dashcards,+ H.getTextCardDetails({ row: 0, text: "Top card" }),+ ],+ });});-- cy.findAllByTestId("dashcard").should("have.length", 2);- });- });-- it("renders cross icon on the link card without clipping", () => {- H.createDashboard().then(({ body: dashboard }) => {- H.visitDashboard(dashboard.id);- H.editDashboard(dashboard.id);+ H.visitDashboard(dashboard_id);});- cy.findByLabelText("Add a link or iframe").click();- H.popover().findByText("Link").click();- cy.findByPlaceholderText("https://example.com").realHover();+ H.editDashboard();+ H.getDashboardCards().should("have.length", 2);cy.log(- "Make sure cypress can click the element, which means it is not covered by another",+ "Make sure cypress can click the element, which means it is not covered by the card above",);+ H.getDashboardCards()+ .filter(":contains('Bottom card')")+ .realHover({ scrollBehavior: false })+ .findByTestId("dashboardcard-actions-panel")+ .icon("close")+ .click({ position: "top", scrollBehavior: false });- cy.findByTestId("dashboardcard-actions-panel").within(() => {- cy.icon("close").closest("a").click({ position: "bottom" });- });-- cy.findByTestId("dashcard").should("not.exist");+ H.getDashboardCards().should("have.length", 1);});});@@ -1665,19 +1560,30 @@ describe("issue 64138", () => {});cy.log("hovering marker icons should not open their tooltips");- getMarkerIcon(0).realHover();- H.popover({ skipVisibilityCheck: true }).should("not.exist");+ getMarkerIcon(0).trigger("mousemove", { force: true });+ H.tooltip().should("not.exist");cy.log("clicking marker icons should not navigate to the question");getMarkerIcon(0).click({ force: true });cy.location("pathname").should("match", /^\/dashboard\/[0-9]+$/);H.modal().should("not.exist");++ cy.log(+ "outside of edit mode, the map shows its controls and handles markers",+ );+ cy.findByTestId("edit-bar").button("Cancel").click();+ H.getDashboardCard(0).findByLabelText("Zoom in").should("exist");+ getMarkerIcon(0).trigger("mousemove", { force: true });+ H.tooltip().should("be.visible");+ getMarkerIcon(0).click({ force: true });+ cy.location("pathname").should("match", /^\/question/);+ cy.location("search").should("match", /objectId=\d+/);});function getMarkerIcon(index) {// pick the last one so it will be on topreturn H.getDashboardCard(index)- .get(".leaflet-marker-icon")+ .find(".leaflet-marker-icon").should("have.length.gt", 0).last();}diff --git a/e2e/test/scenarios/dashboard/dashcard-replace-question.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-replace-question.cy.spec.jsindex 3adaebb0d1c..8cfa42f5e2c 100644--- a/e2e/test/scenarios/dashboard/dashcard-replace-question.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-replace-question.cy.spec.js@@ -130,44 +130,7 @@ describe("scenarios > dashboard cards > replace question", () => {H.expectNoBadSnowplowEvents();});- it("should replace a dashboard card question (metabase#36984)", () => {- visitDashboardAndEdit();-- findHeadingDashcard()- .realHover({ scrollBehavior: "bottom" })- .findByLabelText("Replace")- .should("not.exist");-- // Ensure can replace with a question- replaceQuestion(findTargetDashcard(), {- nextQuestionName: "Orders",- });- H.expectUnstructuredSnowplowEvent({ event: "dashboard_card_replaced" });- findTargetDashcard().within(() => {- assertDashCardTitle("Orders");- cy.findByText("Product ID").should("exist");- });-- // Ensure can replace with a model- replaceQuestion(findTargetDashcard(), {- nextQuestionName: "Orders Model",- });- findTargetDashcard().within(() => {- assertDashCardTitle("Orders Model");- cy.findByText("Product ID").should("exist");- cy.findByText("User ID").should("exist");- });-- // Ensure changes are persisted- H.saveDashboard();- findTargetDashcard().within(() => {- assertDashCardTitle("Orders Model");- cy.findByText("Product ID").should("exist");- cy.findByText("User ID").should("exist");- });- });-- it("should undo the question replace action", () => {+ it("should undo the question replace action, then replace a dashboard card question (metabase#36984)", () => {visitDashboardAndEdit();overwriteDashCardTitle("Custom name");@@ -179,6 +142,7 @@ describe("scenarios > dashboard cards > replace question", () => {replaceQuestion(findTargetDashcard(), {nextQuestionName: "Orders",});+ findTargetDashcard().findByText("Product ID").should("exist");// There're two toasts: "Undo replace" and "Auto-connect"H.undoToastList()@@ -195,8 +159,7 @@ describe("scenarios > dashboard cards > replace question", () => {findTargetDashcard().within(() => {assertDashCardTitle("Custom name");cy.findByText("18,760").should("exist");- cy.findByText("Ean").should("not.exist");- cy.findByText("Rustic Paper Wallet").should("not.exist");+ cy.findByText("Product ID").should("not.exist");});assertDashboardFilterMapping(findTargetDashcard(), {filterName: PARAMETER.UNUSED.name,@@ -208,13 +171,48 @@ describe("scenarios > dashboard cards > replace question", () => {findTargetDashcard().within(() => {assertDashCardTitle("Custom name");cy.findByText("18,760").should("exist");- cy.findByText("Ean").should("not.exist");- cy.findByText("Rustic Paper Wallet").should("not.exist");+ cy.findByText("Product ID").should("not.exist");+ });++ cy.log("metabase#36984");+ H.editDashboard();++ findHeadingDashcard()+ .realHover({ scrollBehavior: "bottom" })+ .findByLabelText("Duplicate")+ .should("be.visible");+ findHeadingDashcard().findByLabelText("Replace").should("not.exist");++ // Ensure can replace with a question+ replaceQuestion(findTargetDashcard(), {+ nextQuestionName: "Orders",+ });+ H.expectUnstructuredSnowplowEvent({ event: "dashboard_card_replaced" }, 2);+ findTargetDashcard().within(() => {+ assertDashCardTitle("Orders");+ cy.findByText("Product ID").should("exist");+ });++ // Ensure can replace with a model+ replaceQuestion(findTargetDashcard(), {+ nextQuestionName: "Orders Model",+ });+ findTargetDashcard().within(() => {+ assertDashCardTitle("Orders Model");+ cy.findByText("Product ID").should("exist");+ cy.findByText("User ID").should("exist");+ });++ // Ensure changes are persisted+ H.saveDashboard();+ findTargetDashcard().within(() => {+ assertDashCardTitle("Orders Model");+ cy.findByText("Product ID").should("exist");+ cy.findByText("User ID").should("exist");});});it("should handle questions with limited permissions", () => {- cy.signInAsAdmin();cy.updateCollectionGraph({[USER_GROUPS.ALL_USERS_GROUP]: { [FIRST_COLLECTION_ID]: "read" },});diff --git a/e2e/test/scenarios/dashboard/dashcard-reproductions.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-reproductions.cy.spec.jsindex fd2f3c73473..ac466e980ce 100644--- a/e2e/test/scenarios/dashboard/dashcard-reproductions.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-reproductions.cy.spec.js@@ -502,8 +502,7 @@ describe("issue 18454", () => {cy.findByTestId("dashcard-container").within(() => {cy.icon("info").trigger("mouseenter", { force: true });});- // eslint-disable-next-line metabase/no-unscoped-text-selectors -- deprecated usage- cy.findByText(CARD_DESCRIPTION);+ H.tooltip().should("contain", CARD_DESCRIPTION);});});@@ -631,7 +630,7 @@ describe("issue 29304", () => {display: "smartscalar",};- const SMART_SCALAR_QUESTION_CARD = SCALAR_QUESTION_CARD;+ const SMART_SCALAR_QUESTION_CARD = { ...SCALAR_QUESTION_CARD, col: 4 };// Use full-app embedding to test because `ExplicitSize` checks for `isCypressActive`,// which checks `window.Cypress`, and will disable the refresh mode on Cypress test.@@ -648,92 +647,54 @@ describe("issue 29304", () => {});};- describe("display: scalar", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- cy.intercept("api/dashboard/*/dashcard/*/card/*/query").as(- "getDashcardQuery",- );- cy.intercept("api/dashboard/*").as("getDashboard");- cy.clock();- });-- it("should render scalar with correct size on the first render (metabase#29304)", () => {- H.createDashboard().then(({ body: dashboard }) => {- H.createQuestionAndAddToDashboard(- SCALAR_QUESTION,- dashboard.id,- SCALAR_QUESTION_CARD,- );-- visitFullAppEmbeddingUrl({ url: `/dashboard/${dashboard.id}` });-- cy.wait("@getDashboard");- cy.wait("@getDashcardQuery");- // This extra 1ms is crucial, without this the test would fail.- cy.tick(WAIT_TIME + 1);-- const expectedWidth = 100;- cy.findByTestId("scalar-value").should(([$scalarValue]) => {- expect($scalarValue.offsetWidth).to.be.closeTo(- expectedWidth,- expectedWidth * 0.2, // 20% tolerance for font rendering differences across Chrome versions- );- });- });- });-- it("should render smart scalar with correct size on the first render (metabase#29304)", () => {- H.createDashboard().then(({ body: dashboard }) => {- H.createQuestionAndAddToDashboard(- SMART_SCALAR_QUESTION,- dashboard.id,- SMART_SCALAR_QUESTION_CARD,- );+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ cy.intercept("api/dashboard/*/dashcard/*/card/*/query").as(+ "getDashcardQuery",+ );+ cy.intercept("api/dashboard/*").as("getDashboard");+ cy.clock();+ });- visitFullAppEmbeddingUrl({ url: `/dashboard/${dashboard.id}` });+ it("should render scalar and smart scalar with correct size on the first render (metabase#29304)", () => {+ H.createDashboard().then(({ body: dashboard }) => {+ H.createQuestionAndAddToDashboard(+ SCALAR_QUESTION,+ dashboard.id,+ SCALAR_QUESTION_CARD,+ );+ H.createQuestionAndAddToDashboard(+ SMART_SCALAR_QUESTION,+ dashboard.id,+ SMART_SCALAR_QUESTION_CARD,+ );- cy.wait("@getDashboard");- cy.wait("@getDashcardQuery");- // This extra 1ms is crucial, without this the test would fail.- cy.tick(WAIT_TIME + 1);+ visitFullAppEmbeddingUrl({ url: `/dashboard/${dashboard.id}` });- const expectedWidth = 47;- cy.findByTestId("scalar-value").should(([$scalarValue]) => {- expect($scalarValue.offsetWidth).to.be.closeTo(- expectedWidth,- expectedWidth * 0.2, // 20% tolerance for font rendering differences across Chrome versions- );- });+ cy.wait("@getDashboard");+ cy.wait(["@getDashcardQuery", "@getDashcardQuery"]);+ // This extra 1ms is crucial, without this the test would fail.+ cy.tick(WAIT_TIME + 1);++ [+ { index: 0, expectedWidth: 100 },+ { index: 1, expectedWidth: 47 },+ ].forEach(({ index, expectedWidth }) => {+ H.getDashboardCard(index)+ .findByTestId("scalar-value")+ .should(([$scalarValue]) => {+ expect($scalarValue.offsetWidth).to.be.closeTo(+ expectedWidth,+ expectedWidth * 0.2, // 20% tolerance for font rendering differences across Chrome versions+ );+ });});});});});-/**- * This test suite reduces the number of "it" calls for performance reasons.- * Every block with JSDoc within "it" callbacks should ideally be a separate "it" call.- * @see https://github.com/metabase/metabase/pull/31722#discussion_r1246165418- */describe("issue 31628", () => {- const createCardsRow = ({ size_y }) => [- { size_x: 6, size_y, row: 0, col: 0 },- { size_x: 5, size_y, row: 0, col: 6 },- { size_x: 4, size_y, row: 0, col: 11 },- { size_x: 3, size_y, row: 0, col: 15 },- { size_x: 2, size_y, row: 0, col: 18 },- ];-- const VIEWPORTS = [- // { width: 375, height: 667, openSidebar: false },- // { width: 820, height: 800, openSidebar: true },- // { width: 820, height: 800, openSidebar: false },- // { width: 1200, height: 800, openSidebar: true },- { width: 1440, height: 800, openSidebar: true },- // { width: 1440, height: 800, openSidebar: false },- ];-const SCALAR_QUESTION = {name: "31628 Question - This is a rather lengthy question name",description: "This is a rather lengthy question description",@@ -744,18 +705,10 @@ describe("issue 31628", () => {display: "scalar",};- const SCALAR_QUESTION_CARDS = [- { cards: createCardsRow({ size_y: 2 }), name: "cards 2 cells high" },- { cards: createCardsRow({ size_y: 3 }), name: "cards 3 cells high" },- { cards: createCardsRow({ size_y: 4 }), name: "cards 4 cells high" },- ];-const SMART_SCALAR_QUESTION = {- name: "31628 Question - This is a rather lengthy question name",- description: "This is a rather lengthy question description",+ ...SCALAR_QUESTION,query: {- "source-table": ORDERS_ID,- aggregation: [["count"]],+ ...SCALAR_QUESTION.query,breakout: [["field",@@ -770,329 +723,308 @@ describe("issue 31628", () => {display: "smartscalar",};- const SMART_SCALAR_QUESTION_CARDS = [- { cards: createCardsRow({ size_y: 2 }), name: "cards 2 cells high" },- // { cards: createCardsRow({ size_y: 3 }), name: "cards 3 cells high" },- // { cards: createCardsRow({ size_y: 4 }), name: "cards 4 cells high" },- ];-- const setupDashboardWithQuestionInCards = (question, cards) => {- H.createDashboard().then(({ body: dashboard }) => {- H.cypressWaitAll(- cards.map((card) => {- return H.createQuestionAndAddToDashboard(- question,- dashboard.id,- card,- );- }),- );-- H.visitDashboard(dashboard.id);- });+ const TREND_QUESTION = {+ display: "smartscalar",+ query: {+ "source-table": ORDERS_ID,+ aggregation: [+ ["count"],+ ["sum", ["field", ORDERS.TOTAL, null]],+ [+ "aggregation-options",+ ["*", ["count"], 10000],+ { name: "Mega Count", "display-name": "Mega Count" },+ ],+ ],+ breakout: [["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }]],+ },+ visualization_settings: {+ "scalar.comparisons": [+ {+ id: "fecd2c69-4d43-57d0-6d60-6781a54beceb",+ type: "previousPeriod",+ },+ {+ id: "e8b8d831-d2a9-9fd7-17a7-db8b4834ac5a",+ type: "periodsAgo",+ value: 2,+ },+ {+ id: "9712f309-6849-20ba-7cef-54ae899a0e41",+ type: "anotherColumn",+ label: "Sum of Total",+ column: "sum",+ },+ ],+ },};- const assertDescendantsNotOverflowDashcards = (descendantsSelector) => {- cy.findAllByTestId("dashcard").should((dashcards) => {- dashcards.each((dashcardIndex, dashcard) => {- const descendants = dashcard.querySelectorAll(descendantsSelector);-- descendants.forEach((descendant) => {- H.assertDescendantNotOverflowsContainer(- descendant,- dashcard,- `dashcard[${dashcardIndex}] [data-testid="${descendant.dataset.testid}"]`,- );- });- });- });+ const OVERFLOW_CHECKED_TEST_IDS = {+ scalar: ["scalar-container", "scalar-title"],+ smartscalar: ["scalar-container", "scalar-title", "scalar-previous-value"],};- describe("display: scalar", () => {- const descendantsSelector = [- "[data-testid='scalar-container']",- "[data-testid='scalar-title']",- "[data-testid='scalar-description']",- ].join(",");-- VIEWPORTS.forEach(({ width, height, openSidebar }) => {- SCALAR_QUESTION_CARDS.forEach(({ cards, name }) => {- const sidebar = openSidebar ? "sidebar open" : "sidebar closed";-- describe(`${width}x${height} - ${sidebar} - ${name}`, () => {- beforeEach(() => {- H.restore();- cy.viewport(width, height);- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SCALAR_QUESTION, cards);-- if (openSidebar) {- cy.wait(100);- H.openNavigationSidebar();- }- });+ const ROW_WIDTHS = [6, 5, 4, 3, 2];- it("should render descendants of a 'scalar' without overflowing it (metabase#31628)", () => {- assertDescendantsNotOverflowDashcards(descendantsSelector);- });- });- });- });-- describe("1x2 card", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SCALAR_QUESTION, [- { size_x: 1, size_y: 2, row: 0, col: 0 },- ]);- });+ const OVERFLOW_ROWS = [+ { display: "scalar", size_y: 2, row: 0 },+ { display: "scalar", size_y: 3, row: 2 },+ { display: "scalar", size_y: 4, row: 5 },+ { display: "smartscalar", size_y: 2, row: 9 },+ ];- it("should follow truncation rules", () => {- cy.log("should truncate value and show value tooltip on hover");+ const OVERFLOW_CARDS = OVERFLOW_ROWS.flatMap(({ display, size_y, row }) =>+ ROW_WIDTHS.map((size_x, index) => ({+ display,+ size_x,+ size_y,+ row,+ col: ROW_WIDTHS.slice(0, index).reduce((sum, width) => sum + width, 0),+ })),+ );- scalarContainer().then(($element) =>- H.assertIsEllipsified($element[0]),- );- //TODO: Need to hover on the actual text, not just the container. This is a weird one- scalarContainer().realHover({ position: "bottom" });+ const TRUNCATION_CARDS = {+ scalar1x2: { display: "scalar", size_x: 1, size_y: 2, row: 0, col: 0 },+ scalar2x2: { display: "scalar", size_x: 2, size_y: 2, row: 0, col: 1 },+ scalar6x3: { display: "scalar", size_x: 6, size_y: 3, row: 0, col: 3 },+ smart2x2: { display: "smartscalar", size_x: 2, size_y: 2, row: 0, col: 9 },+ smart7x3: { display: "smartscalar", size_x: 7, size_y: 3, row: 0, col: 11 },+ smart7x4: { display: "smartscalar", size_x: 7, size_y: 4, row: 4, col: 0 },+ trend4x3: { display: "trend", size_x: 4, size_y: 3, row: 4, col: 7 },+ };- cy.findByRole("tooltip").findByText("18,760").should("exist");+ const setupDashboard = (cards) => {+ H.createDashboardWithQuestions({+ questions: [SCALAR_QUESTION, SMART_SCALAR_QUESTION, TREND_QUESTION],+ }).then(({ dashboard, questions: [scalar, smartScalar, trend] }) => {+ const cardIds = {+ scalar: scalar.id,+ smartscalar: smartScalar.id,+ trend: trend.id,+ };+ H.updateDashboardCards({+ dashboard_id: dashboard.id,+ cards: cards.map(({ display, ...layout }) => ({+ card_id: cardIds[display],+ ...layout,+ })),+ }).then(({ body: { dashcards } }) => {+ cy.wrap(+ cards.map(+ ({ row, col }) =>+ dashcards.find(+ (dashcard) => dashcard.row === row && dashcard.col === col,+ ).id,+ ),+ ).as("dashcardIds");});+ H.visitDashboard(dashboard.id);});+ };- describe("2x2 card", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SCALAR_QUESTION, [- { size_x: 2, size_y: 2, row: 0, col: 0 },- ]);- });+ const getCard = (index) =>+ cy+ .get("@dashcardIds")+ .then((ids) => cy.get(`[data-dashcard-key="${ids[index]}"]`));- it("should follow truncation rules", () => {- cy.log("should not truncate value");- scalarContainer().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );+ const scalarContainer = (card) => card.findByTestId("scalar-container");+ const previousValue = (card) => card.findByTestId("scalar-previous-value");- cy.log(- "should show the title tooltip on hover because the smallest cards hide the inline title",- );- scalarContainer().realHover();+ const moveMouseAway = () => {+ H.dashboardHeader().realHover({ position: "left" });+ cy.findByRole("tooltip").should("not.exist");+ };- cy.findByRole("tooltip")- .findByText(SCALAR_QUESTION.name)- .should("exist");- });- });+ beforeEach(() => {+ H.restore();+ cy.signInAsAdmin();+ });- describe("5x3 card", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SCALAR_QUESTION, [- { size_x: 6, size_y: 3, row: 0, col: 0 },- ]);- });+ it("should render descendants of scalar and smart scalar cards without overflowing them (metabase#31628)", () => {+ cy.viewport(1440, 800);+ setupDashboard(OVERFLOW_CARDS);+ H.getDashboardCards().should("have.length", OVERFLOW_CARDS.length);- it("should follow truncation rules", () => {- cy.log(- "should not truncate value and should not show value tooltip on hover",- );- scalarContainer().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );- scalarContainer().realHover();+ cy.wait(100);+ H.openNavigationSidebar();- cy.findByRole("tooltip").should("not.exist");- });+ cy.log("The dashboard fits the viewport, so no scrollbar narrows the grid");+ cy.get("main").should(([main]) => {+ expect(main.scrollHeight).to.be.at.most(main.clientHeight);});- });- describe("display: smartscalar", () => {- const descendantsSelector = [- "[data-testid='scalar-title']",- "[data-testid='scalar-container']",- "[data-testid='scalar-previous-value']",- ].join(",");-- VIEWPORTS.forEach(({ width, height, openSidebar }) => {- SMART_SCALAR_QUESTION_CARDS.forEach(({ cards, name }) => {- const sidebar = openSidebar ? "sidebar open" : "sidebar closed";-- describe(`${width}x${height} - ${sidebar} - ${name}`, () => {- beforeEach(() => {- H.restore();- cy.viewport(width, height);- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SMART_SCALAR_QUESTION, cards);-- if (openSidebar) {- H.openNavigationSidebar();- }- });+ cy.get("@dashcardIds").then((ids) => {+ cy.findAllByTestId("dashcard").should((dashcards) => {+ OVERFLOW_CARDS.forEach(({ display, size_x, size_y }, index) => {+ const dashcard = dashcards.filter(+ `[data-dashcard-key="${ids[index]}"]`,+ )[0];+ const label = `${display} ${size_x}x${size_y}`;++ expect(+ dashcard.querySelectorAll("[data-testid='scalar-container']"),+ `${label} scalar-container`,+ ).to.have.length(1);+ if (display === "smartscalar") {+ expect(+ dashcard.querySelectorAll(+ "[data-testid='scalar-previous-value']",+ ),+ `${label} scalar-previous-value`,+ ).to.have.length(1);+ }- it("should render descendants of a 'smartscalar' without overflowing it (metabase#31628)", () => {- assertDescendantsNotOverflowDashcards(descendantsSelector);+ OVERFLOW_CHECKED_TEST_IDS[display].forEach((testId) => {+ dashcard+ .querySelectorAll(`[data-testid='${testId}']`)+ .forEach((descendant) => {+ H.assertDescendantNotOverflowsContainer(+ descendant,+ dashcard,+ `${label} [data-testid="${testId}"]`,+ );+ });});});});});+ });- describe("2x2 card", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SMART_SCALAR_QUESTION, [- { size_x: 2, size_y: 2, row: 0, col: 0 },- ]);- });-- it("should follow truncation rules", () => {- cy.log("it should not truncate value");- scalarContainer().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );+ it("should follow truncation rules for scalar, smart scalar and trend cards (metabase#31628)", () => {+ const cards = Object.values(TRUNCATION_CARDS);+ const card = (key) => getCard(cards.indexOf(TRUNCATION_CARDS[key]));- cy.log(- "it should show the title tooltip on hover because the smallest cards hide the inline title",- );- scalarContainer().realHover();+ setupDashboard(cards);+ H.getDashboardCards().should("have.length", cards.length);- cy.findByRole("tooltip")- .findByText(SMART_SCALAR_QUESTION.name)- .should("exist");+ cy.log("scalar 1x2: should truncate value and show value tooltip on hover");+ scalarContainer(card("scalar1x2")).then(($element) =>+ H.assertIsEllipsified($element[0]),+ );+ //TODO: Need to hover on the actual text, not just the container. This is a weird one+ scalarContainer(card("scalar1x2")).realHover({ position: "bottom" });+ cy.findByRole("tooltip").findByText("18,760").should("exist");+ moveMouseAway();++ cy.log("scalar 2x2: should not truncate value");+ scalarContainer(card("scalar2x2")).then(($element) =>+ H.assertIsNotEllipsified($element[0]),+ );+ cy.log(+ "scalar 2x2: should show the title tooltip on hover because the smallest cards hide the inline title",+ );+ scalarContainer(card("scalar2x2")).realHover();+ cy.findByRole("tooltip").findByText(SCALAR_QUESTION.name).should("exist");+ moveMouseAway();- cy.log("it should not display the period on dashboard cards");- cy.findByTestId("scalar-period").should("not.exist");+ cy.log(+ "scalar 6x3: should not truncate value and should not show value tooltip on hover",+ );+ scalarContainer(card("scalar6x3")).then(($element) =>+ H.assertIsNotEllipsified($element[0]),+ );+ scalarContainer(card("scalar6x3")).realHover();+ cy.findByRole("tooltip").should("not.exist");+ moveMouseAway();- cy.log(- "it should show the previous value as a percentage only (without truncation)",- );- previousValue().should("contain", "-34.72%").and("not.contain", "527");+ cy.log("smart scalar 2x2: should not truncate value");+ scalarContainer(card("smart2x2")).then(($element) =>+ H.assertIsNotEllipsified($element[0]),+ );+ cy.log(+ "smart scalar 2x2: should show the title tooltip on hover because the smallest cards hide the inline title",+ );+ scalarContainer(card("smart2x2")).realHover();+ cy.findByRole("tooltip")+ .findByText(SMART_SCALAR_QUESTION.name)+ .should("exist");+ moveMouseAway();- previousValue().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );+ cy.log(+ "smart scalar 2x2: should not display the period, which wider cards show",+ );+ card("smart7x3")+ .findByTestId("scalar-period")+ .should("have.text", "Apr 2029");+ card("smart2x2").findByTestId("scalar-period").should("not.exist");- cy.log("it should show the full comparison in a panel on hover");- previousValue().realHover();+ cy.log(+ "smart scalar 2x2: should show the previous value as a percentage only (without truncation)",+ );+ previousValue(card("smart2x2"))+ .should("contain", "-34.72%")+ .and("not.contain", "527");+ previousValue(card("smart2x2")).then(($element) =>+ H.assertIsNotEllipsified($element[0]),+ );- cy.findByRole("tooltip").within(() => {- cy.contains("34.72%").should("exist");- cy.contains("vs. previous month").should("exist");- cy.contains("527").should("exist");- });- });+ cy.log(+ "smart scalar 2x2: should show the full comparison in a panel on hover",+ );+ previousValue(card("smart2x2")).realHover();+ cy.findByRole("tooltip").within(() => {+ cy.contains("34.72%").should("exist");+ cy.contains("vs. previous month").should("exist");+ cy.contains("527").should("exist");});+ moveMouseAway();++ ["smart7x3", "smart7x4"].forEach((key) => {+ cy.log(`${key}: should truncate the inline title and show it on hover`);+ card(key).findByTestId("scalar-title").realHover();+ cy.findByRole("tooltip")+ .findByText(SMART_SCALAR_QUESTION.name)+ .should("exist");+ moveMouseAway();++ cy.log(`${key}: should show description tooltip on hover`);+ card(key).findByTestId("scalar-title").icon("info").realHover();+ cy.findByRole("tooltip")+ .findByText(SMART_SCALAR_QUESTION.description)+ .should("exist");+ moveMouseAway();++ cy.log(+ `${key}: should not truncate value and should not show value tooltip on hover`,+ );+ scalarContainer(card(key)).then(($element) =>+ H.assertIsNotEllipsified($element[0]),+ );+ scalarContainer(card(key)).realHover();+ cy.findByRole("tooltip").should("not.exist");+ moveMouseAway();++ cy.log(`${key}: should display the period as part of the comparison`);+ previousValue(card(key)).should("contain", "Apr 2029");++ cy.log(`${key}: should show previous value in full`);+ previousValue(card(key))+ .should("contain", "-34.72% MoM")+ .and("contain", "(527)");+ previousValue(card(key)).then(($element) =>+ H.assertIsNotEllipsified($element[0]),+ );- describe("7x3 card", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SMART_SCALAR_QUESTION, [- { size_x: 7, size_y: 3, row: 0, col: 0 },- ]);- });-- it("should follow truncation rules", () => {- cy.log(- "should not truncate value and should not show value tooltip on hover",- );- scalarContainer().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );- scalarContainer().realHover();-- cy.findByRole("tooltip").should("not.exist");-- cy.log("it should display the period as part of the comparison");- previousValue().should("contain", "Apr 2029");-- cy.log("should truncate the inline title and show it on hover");- cy.findByTestId("scalar-title").realHover();-- cy.findByRole("tooltip")- .findByText(SMART_SCALAR_QUESTION.name)- .should("exist");-- cy.log("should show description tooltip on hover");- cy.findByTestId("scalar-title").icon("info").realHover();-- cy.findByRole("tooltip")- .findByText(SMART_SCALAR_QUESTION.description)- .should("exist");-- cy.log("should show previous value in full");- previousValue()- .should("contain", "-34.72% MoM")- .and("contain", "(527)");- previousValue().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );-- cy.log(- "should not show a panel for a single fully-displayed comparison",- );- cy.findByTestId("scalar-previous-value").realHover();-- cy.findByRole("tooltip").should("not.exist");- });+ cy.log(+ `${key}: should not show a panel for a single fully-displayed comparison`,+ );+ previousValue(card(key)).realHover();+ cy.findByRole("tooltip").should("not.exist");+ moveMouseAway();});- describe("7x4 card", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- setupDashboardWithQuestionInCards(SMART_SCALAR_QUESTION, [- { size_x: 7, size_y: 4, row: 0, col: 0 },- ]);- });-- it("should follow truncation rules", () => {- cy.log(- "should not truncate value and should not show value tooltip on hover",- );- scalarContainer().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );- scalarContainer().realHover();-- cy.findByRole("tooltip").should("not.exist");-- cy.log("it should display the period as part of the comparison");- previousValue().should("contain", "Apr 2029");-- cy.log("should truncate the inline title and show it on hover");- cy.findByTestId("scalar-title").realHover();-- cy.findByRole("tooltip")- .findByText(SMART_SCALAR_QUESTION.name)- .should("exist");-- cy.log("should show description tooltip on hover");- cy.findByTestId("scalar-title").icon("info").realHover();-- cy.findByRole("tooltip")- .findByText(SMART_SCALAR_QUESTION.description)- .should("exist");-- cy.log("should show previous value in full");- previousValue()- .should("contain", "-34.72% MoM")- .and("contain", "(527)");- previousValue().then(($element) =>- H.assertIsNotEllipsified($element[0]),- );-- cy.log(- "should not show a panel for a single fully-displayed comparison",- );- cy.findByTestId("scalar-previous-value").realHover();-- cy.findByRole("tooltip").should("not.exist");- });+ cy.log(+ "trend 4x3: extra comparisons should only be shown in the hover panel",+ );+ previousValue(card("trend4x3"))+ .should("contain", "-34.72%")+ .and("not.contain", "36.65%")+ .and("not.contain", "98.88%");+ previousValue(card("trend4x3")).realHover();+ H.tooltip().within(() => {+ cy.findByText("34.72%").should("be.visible");+ cy.findByText("36.65%").should("be.visible");+ cy.findByText("98.88%").should("be.visible");});});});@@ -1200,20 +1132,7 @@ describe("issue 48878", () => {cy.intercept("GET", "/api/dashboard/*").as("getDashboard");cy.intercept("PUT", "/api/dashboard/*").as("updateDashboard");- let fetchCardRequestsCount = 0;-- cy.intercept("GET", "/api/card/*", (request) => {- // we only want to simulate the race condition 4th time this request is triggered- if (fetchCardRequestsCount === 2) {- request.continue(- () => new Promise((resolve) => setTimeout(resolve, 2000)),- );- } else {- request.continue();- }-- ++fetchCardRequestsCount;- }).as("fetchCard");+ cy.intercept("GET", "/api/card/*").as("fetchCard");setup();});@@ -1225,16 +1144,6 @@ describe("issue 48878", () => {});function setup() {- cy.log("create dummy model");-- // Create a dummy model so that GET /api/search does not return the model want to test.- // If we don't do this, GET /api/search will return and put card object with dataset_query- // attribute in the redux store (entity framework) which would prevent the issue from happening.- createModel({- name: "Dummy model",- query: "select 1",- });-cy.log("create model");createModel({@@ -1392,9 +1301,6 @@ SELECT 'group_2', 'sub_group_2', 52, 'group_2__sub_group_2';});});-const scalarContainer = () => cy.findByTestId("scalar-container");-const previousValue = () => cy.findByTestId("scalar-previous-value");-describe("issue 67432", () => {beforeEach(() => {H.restore();@@ -1440,66 +1346,55 @@ describe("issue 67432", () => {.icon("chevrondown").should("exist");- // Collect the visual order of categories from the table- const visualCategories = [];+ // Products 1-5 sorted by Category descending; equal categories keep their row order+ const EXPECTED_ROWS = [+ ["Rustic Paper Wallet", "Gizmo"],+ ["Enormous Marble Wallet", "Gadget"],+ ["Small Marble Shoes", "Doohickey"],+ ["Synergistic Granite Chair", "Doohickey"],+ ["Enormous Aluminum Shirt", "Doohickey"],+ ];+H.tableInteractiveBody().find('[data-column-id="CATEGORY"]')- .each(($cell) => {- visualCategories.push($cell.text());- })- .then(() => {- // Select multiple cells across rows by dragging- const getNonPKCells = () =>- H.tableInteractiveBody().find(- '[data-selectable-cell]:not([data-column-id="ID"])',- );-- // Select cells in first two rows (4 cells: Title+Category for 2 rows)- getNonPKCells()- .eq(0)- .trigger("mousedown", { which: 1 })- .then(() => {- const lastCellIndex = ROWS_LIMIT * 2 - 1;- getNonPKCells()- .should("have.length", ROWS_LIMIT * 2)- .eq(lastCellIndex)- .trigger("mouseover", { buttons: 1 });- getNonPKCells()- .should("have.length", ROWS_LIMIT * 2)- .eq(lastCellIndex)- .trigger("mouseup");- });-- // Copy to clipboard- cy.realPress(["Meta", "c"]);-- // Verify clipboard content has rows in sorted order- H.readClipboard().then((clipboardText) => {- // The clipboard should contain properly tab-separated content- // with newlines between rows (not a single cell)- const lines = clipboardText.split("\n");+ .should(($cells) => {+ expect($cells.toArray().map((cell) => cell.textContent)).to.deep.equal(+ EXPECTED_ROWS.map(([, category]) => category),+ );+ });- // Should have header row + data rows (at least 6 lines: header + 5 data rows)- expect(lines.length).to.be.eq(ROWS_LIMIT + 1);+ // Select multiple cells across rows by dragging+ const getNonPKCells = () =>+ H.tableInteractiveBody().find(+ '[data-selectable-cell]:not([data-column-id="ID"])',+ );- // Header should be tab-separated with both columns- const headerCells = lines[0].split("\t");- expect(headerCells).to.include("Title");- expect(headerCells).to.include("Category");+ // Select Title and Category cells in every row+ getNonPKCells()+ .eq(0)+ .trigger("mousedown", { which: 1 })+ .then(() => {+ const lastCellIndex = ROWS_LIMIT * 2 - 1;+ getNonPKCells()+ .should("have.length", ROWS_LIMIT * 2)+ .eq(lastCellIndex)+ .trigger("mouseover", { buttons: 1 });+ getNonPKCells()+ .should("have.length", ROWS_LIMIT * 2)+ .eq(lastCellIndex)+ .trigger("mouseup");+ });- // Verify each data row is tab-separated and in the correct sorted order- const clipboardCategories = lines.slice(1).map((line) => {- const cells = line.split("\t");- // Category is the second column- return cells[1];- });+ // Copy to clipboard+ cy.realPress(["Meta", "c"]);- // The categories in clipboard should match the visual order- for (let i = 0; i < clipboardCategories.length; i++) {- expect(clipboardCategories[i]).to.equal(visualCategories[i]);- }- });- });+ // The clipboard holds tab-separated rows in the sorted order+ H.readClipboard().should(+ "equal",+ [["Title", "Category"], ...EXPECTED_ROWS]+ .map((cells) => cells.join("\t"))+ .join("\n"),+ );});});@@ -1584,6 +1479,9 @@ describe("issue 63416", () => {cy.log("Make this a visualizer card");H.saveDashcardVisualizerModal();+ H.showDashboardCardActions(0);+ H.getDashboardCard(0).findByLabelText("Edit visualization").should("exist");+H.saveDashboard();H.toggleFilterWidgetValues(["Doohickey"]);diff --git a/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.jsindex a6b525326ee..9dfe8848ec4 100644--- a/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-resizing.cy.spec.js@@ -233,6 +233,7 @@ describe(H.saveDashboard();cy.request("GET", `/api/dashboard/${dashId}`).then(({ body }) => {+ expect(body.dashcards).to.have.length(TEST_QUESTIONS.length);body.dashcards.forEach(({ card, size_x, size_y }) => {const { height, width } = getDefaultSize(card.display);expect(size_x).to.equal(width);@@ -339,6 +340,7 @@ describe(H.saveDashboard();cy.request("GET", `/api/dashboard/${dashId}`).then(({ body }) => {+ expect(body.dashcards).to.have.length(TEST_QUESTIONS.length);body.dashcards.forEach(({ card, size_x, size_y }) => {const { height, width } = getMinSize(card.display);expect(size_x).to.equal(width);@@ -351,95 +353,15 @@ describe(},);-describe("trend charts", () => {- beforeEach(() => {- H.restore();- cy.signInAsAdmin();- });-- it("extra comparisons should only be shown in the hover panel", () => {- H.createDashboardWithQuestions({- dashboardDetails: {},- questions: [- {- display: "smartscalar",- query: {- "source-table": ORDERS_ID,- aggregation: [- ["count"],- ["sum", ["field", ORDERS.TOTAL, null]],- [- "aggregation-options",- ["*", ["count"], 10000],- { name: "Mega Count", "display-name": "Mega Count" },- ],- ],- breakout: [- ["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],- ],- },- visualization_settings: {- "scalar.comparisons": [- {- id: "fecd2c69-4d43-57d0-6d60-6781a54beceb",- type: "previousPeriod",- },- {- id: "e8b8d831-d2a9-9fd7-17a7-db8b4834ac5a",- type: "periodsAgo",- value: 2,- },- {- id: "9712f309-6849-20ba-7cef-54ae899a0e41",- type: "anotherColumn",- label: "Sum of Total",- column: "sum",- },- ],- },- },- ],- }).then(({ dashboard, questions: cards }) => {- const [card] = cards;-- H.updateDashboardCards({- dashboard_id: dashboard.id,- cards: [{ card_id: card.id, size_x: 4, size_y: 3 }],- });-- H.visitDashboard(dashboard.id);- });-- H.getDashboardCard().within(() => {- cy.findByTestId("scalar-previous-value")- .should("contain", "-34.72%")- .and("not.contain", "36.65%")- .and("not.contain", "98.88%");-- cy.findByTestId("scalar-previous-value").realHover();- });-- H.tooltip().within(() => {- cy.findByText("34.72%").should("be.visible");- cy.findByText("36.65%").should("be.visible");- cy.findByText("98.88%").should("be.visible");- });- });-});-describe("issue 31701", () => {const entityCard = () => H.getDashboardCard(0);const customCard = () => H.getDashboardCard(1);- const editEntityLinkContainer = () =>- cy.findByTestId("entity-edit-display-link");- const editCustomLinkContainer = () =>- cy.findByTestId("custom-edit-text-link");+ const editEntityLinkContainer = "[data-testid='entity-edit-display-link']";+ const editCustomLinkContainer = "[data-testid='custom-edit-text-link']";- const viewEntityLinkContainer = () =>- cy.findByTestId("entity-view-display-link");- const viewCustomLinkContainer = () =>- cy.findByTestId("custom-view-text-link");+ const viewEntityLinkContainer = "[data-testid='entity-view-display-link']";+ const viewCustomLinkContainer = "[data-testid='custom-view-text-link']";beforeEach(() => {H.restore();@@ -451,7 +373,9 @@ describe("issue 31701", () => {"source-table": ORDERS_ID,},});+ });+ it("should prevent link dashboard card overflows and not clip the link card cross icon (metabase#31701, metabase#31274)", () => {H.createDashboard({name: TEST_DASHBOARD_NAME,}).then(({ body: { id: dashId } }) => {@@ -460,6 +384,19 @@ describe("issue 31701", () => {H.editDashboard();+ cy.log("Remove an empty link card through its cross icon (metabase#31274)");+ cy.findByLabelText("Add a link or iframe").click();+ H.popover().findByText("Link").click();+ cy.findByPlaceholderText("https://example.com").realHover();+ H.getDashboardCards().should("have.length", 1);+ cy.log(+ "Make sure cypress can click the element, which means it is not covered by another",+ );+ cy.findByTestId("dashboardcard-actions-panel").within(() => {+ cy.icon("close").closest("a").click({ position: "bottom" });+ });+ cy.findByTestId("dashcard").should("not.exist");+cy.log("Add first link card (connected to an entity");cy.findByLabelText("Add a link or iframe").click();H.popover().findByText("Link").click();@@ -477,16 +414,14 @@ describe("issue 31701", () => {.click().type(TEST_QUESTION_NAME).realPress("Tab");- });- it("should prevent link dashboard card overflows (metabase#31701)", () => {cy.log("when editing dashboard");viewports.forEach(([width, height]) => {cy.log(`Testing on resolution ${width} x ${height}`);cy.viewport(width, height);- assertLinkCardOverflow(editEntityLinkContainer(), entityCard());- assertLinkCardOverflow(editCustomLinkContainer(), customCard());+ assertLinkCardOverflow(editEntityLinkContainer, entityCard());+ assertLinkCardOverflow(editCustomLinkContainer, customCard());});H.saveDashboard();@@ -496,18 +431,18 @@ describe("issue 31701", () => {cy.log(`Testing on resolution ${width} x ${height}`);cy.viewport(width, height);- assertLinkCardOverflow(viewEntityLinkContainer(), entityCard());- assertLinkCardOverflow(viewCustomLinkContainer(), customCard());+ assertLinkCardOverflow(viewEntityLinkContainer, entityCard());+ assertLinkCardOverflow(viewCustomLinkContainer, customCard());});});});const assertLinkCardOverflow = (link, card) => {- link.then((linkElem) => {- card.then((dashCardElem) => {- expect(linkElem[0].scrollHeight).to.eq(- dashCardElem[0].firstChild.scrollHeight,- );- });+ card.should((dashCardElem) => {+ const linkElem = dashCardElem.find(link);+ expect(linkElem).to.have.length(1);+ expect(linkElem[0].scrollHeight).to.eq(+ dashCardElem[0].firstChild.scrollHeight,+ );});};diff --git a/e2e/test/scenarios/dashboard/dashcard-sections.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-sections.cy.spec.jsindex ee85589d58a..2982f8e92d6 100644--- a/e2e/test/scenarios/dashboard/dashcard-sections.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-sections.cy.spec.js@@ -103,6 +103,8 @@ describe("scenarios > dashboard cards > sections", () => {// Ensure parameter mapping is persistedH.editDashboard();+ // Empty placeholders still exist, but only edit mode shows their button+ H.dashboardGrid().findAllByText("Select question").should("have.length", 3);filterPanel().findByText("Category").click();H.getDashboardCard(1).findByText("Product.Category").should("exist");});diff --git a/e2e/test/scenarios/dashboard/dashcard-undo.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-undo.cy.spec.jsindex 08fb3e521bb..f507d7cccab 100644--- a/e2e/test/scenarios/dashboard/dashcard-undo.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-undo.cy.spec.js@@ -17,6 +17,28 @@ describe("scenarios > dashboard cards > undo", () => {H.getDashboardCard(3).findByText("Text card 4");};+ const getPositions = ($grid) => {+ const gridRect = $grid[0].getBoundingClientRect();+ return $grid+ .find("[data-testid='dashcard-container']")+ .toArray()+ .map((dashcard) => {+ const rect = dashcard.getBoundingClientRect();+ return {+ left: Math.round(rect.left - gridRect.left),+ top: Math.round(rect.top - gridRect.top),+ };+ });+ };++ const checkPositions = () => {+ cy.get("@originalPositions").then((originalPositions) => {+ H.dashboardGrid().should(($grid) => {+ expect(getPositions($grid)).to.deep.equal(originalPositions);+ });+ });+ };+const cards = [H.getTextCardDetails({text: "Text card 1",@@ -57,6 +79,7 @@ describe("scenarios > dashboard cards > undo", () => {checkOrder();H.editDashboard();+ H.dashboardGrid().then(getPositions).as("originalPositions");for (let i = 0; i < cards.length; i++) {H.removeDashboardCard(i);@@ -65,6 +88,7 @@ describe("scenarios > dashboard cards > undo", () => {H.undo();H.getDashboardCards().should("have.length", cards.length);checkOrder();+ checkPositions();// Seems to be needed to allow the UI to catch up before hovering the next element.// TODO: improve this.cy.wait(200);@@ -80,6 +104,7 @@ describe("scenarios > dashboard cards > undo", () => {H.undo();H.getDashboardCards().should("have.length", cards.length);checkOrder();+ checkPositions();cy.wait(200);}},diff --git a/e2e/test/scenarios/dashboard/dashcard-visualization-options.cy.spec.js b/e2e/test/scenarios/dashboard/dashcard-visualization-options.cy.spec.jsindex 3b2cc1634d8..454237feed3 100644--- a/e2e/test/scenarios/dashboard/dashcard-visualization-options.cy.spec.js+++ b/e2e/test/scenarios/dashboard/dashcard-visualization-options.cy.spec.js@@ -8,38 +8,12 @@ describe("scenarios > dashboard cards > visualization options", () => {cy.signInAsAdmin();});- it("should allow empty card title (metabase#12013, metabase#36788)", () => {- const originalCardTitle = "Orders";- H.visitDashboard(ORDERS_DASHBOARD_ID);-- cy.findByTestId("legend-caption")- .should("contain", originalCardTitle)- .and("be.visible");-- H.editDashboard();- H.showDashboardCardActions();- cy.icon("palette").click();-- H.modal().within(() => {- cy.findByDisplayValue(originalCardTitle).click().clear().blur();- cy.button("Done").click();- });-- cy.findByTestId("legend-caption").should("not.contain", originalCardTitle);- H.saveDashboard();- H.getDashboardCard().realHover();- H.getDashboardCardMenu().click();- H.popover()- .should("contain", "Edit question")- .and("contain", "Download results");- });-it("should show the ellipsis even with an empty card title on visualizations with noHeader (metabase#46897)", () => {const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;- const QUESTION_TABLE = {- name: "The tablest of all tables",- display: "table",+ const QUESTION_LINE = {+ name: "The lineest of all lines",+ display: "line",query: {aggregation: [["count"]],breakout: [@@ -50,44 +24,81 @@ describe("scenarios > dashboard cards > visualization options", () => {],],"source-table": ORDERS_ID,- limit: 5,},};- H.createQuestionAndDashboard({ questionDetails: QUESTION_TABLE }).then(- ({ body: card }) => {- H.visitDashboard(card.dashboard_id);-- cy.findByTestId("legend-caption")- .should("contain", QUESTION_TABLE.name)- .and("be.visible");+ H.createQuestionAndDashboard({+ questionDetails: QUESTION_LINE,+ cardDetails: { visualization_settings: { "card.title": "" } },+ }).then(({ body: { dashboard_id } }) => {+ H.visitDashboard(dashboard_id);+ });- H.editDashboard();- H.showDashboardCardActions();- cy.icon("palette").click();+ H.getDashboardCard().within(() => {+ H.echartsContainer().should("be.visible");+ });+ H.getDashboardCard().should("not.contain", QUESTION_LINE.name);+ H.getDashboardCard().realHover();+ H.getDashboardCardMenu().click();+ H.popover()+ .should("contain", "Edit question")+ .and("contain", "Download results");+ });- H.modal().within(() => {- cy.findByDisplayValue(QUESTION_TABLE.name).click().clear().blur();- cy.button("Done").click();+ it("should hide visualization options while the card loads, toggle column settings, reorder columns and allow an empty card title (metabase#21830, metabase#30966, metabase#16229, metabase#12013, metabase#36788)", () => {+ cy.intercept("GET", "/api/dashboard/*").as("getDashboard");+ cy.intercept(+ {+ method: "POST",+ url: "/api/dashboard/*/dashcard/*/card/*/query",+ middleware: true,+ },+ (req) => {+ req.on("response", (res) => {+ // throttle the response to simulate a mobile 3G connection+ res.setThrottle(100);});-- cy.findByTestId("legend-caption").should(- "not.contain",- QUESTION_TABLE.name,- );- H.saveDashboard();- H.getDashboardCard().realHover();- H.getDashboardCardMenu().click();- H.popover()- .should("contain", "Edit question")- .and("contain", "Download results");},- );- });+ ).as("getCardQuery");++ cy.visit(`/dashboard/${ORDERS_DASHBOARD_ID}`);+ cy.wait("@getDashboard");- it("column reordering should work (metabase#16229)", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- cy.findByLabelText("Edit dashboard").click();+ cy.log("metabase#21830");+ // it's crucial that we try to click on this icon BEFORE we wait for the `getCardQuery` response!+ H.editDashboard();+ H.showDashboardCardActions();++ H.getDashboardCard().within(() => {+ cy.icon("close").should("be.visible");+ cy.icon("click").should("not.exist");+ cy.icon("palette").should("not.exist");+ });++ cy.wait("@getCardQuery");++ H.getDashboardCard().within(() => {+ cy.icon("close").should("be.visible");+ cy.icon("click").should("be.visible");+ cy.icon("palette").should("be.visible");+ });++ cy.log("metabase#30966");+ H.getDashboardCard().realHover();+ cy.findByLabelText("Show visualization options").click();+ cy.findByTestId("Subtotal-settings-button").click();+ H.popover()+ .findByLabelText("Show a mini bar chart")+ .should("not.be.checked")+ .click({ force: true });+ H.popover().findByLabelText("Show a mini bar chart").should("be.checked");+ H.modal()+ .findAllByTestId("mini-bar-container")+ .should("have.length.above", 0);+ H.modal().button("Cancel").click();+ H.modal().should("not.exist");++ cy.log("metabase#16229");H.getDashboardCard().realHover();cy.findByLabelText("Show visualization options").click();cy.findByTestId("chartsettings-sidebar").within(() => {@@ -96,26 +107,40 @@ describe("scenarios > dashboard cards > visualization options", () => {vertical: 100,useMouseEvents: true,});- const idButton = () =>- cy.get('[data-testid="draggable-item-ID"]').closest("[role=button]");- const userIdButton = () =>- cy- .get('[data-testid="draggable-item-User ID"]')- .closest("[role=button]");- // The ID column should be below the User ID column.- expect(idButton().prev()[0]).to.equal(userIdButton()[0]);+ });+ // The ID column should be below the User ID column.+ H.getDraggableElements().should(($items) => {+ const columnNames = $items+ .toArray()+ .map((item) => item.dataset.testid.replace("draggable-item-", ""));+ expect(columnNames[0]).to.equal("User ID");+ expect(columnNames.indexOf("ID")).to.be.above(0);});// The table preview should get updated immediately, reflecting the changes in columns ordering.H.modal().findAllByRole("columnheader").first().contains("User ID");- });+ H.modal().button("Cancel").click();+ H.modal().should("not.exist");++ cy.log("metabase#12013, metabase#36788");+ const originalCardTitle = "Orders";+ cy.findByTestId("legend-caption")+ .should("contain", originalCardTitle)+ .and("be.visible");++ H.showDashboardCardActions();+ cy.icon("palette").click();++ H.modal().within(() => {+ cy.findByDisplayValue(originalCardTitle).click().clear().blur();+ cy.button("Done").click();+ });- it("should reflect column settings accurately when changing (metabase#30966)", () => {- H.visitDashboard(ORDERS_DASHBOARD_ID);- cy.findByLabelText("Edit dashboard").click();+ cy.findByTestId("legend-caption").should("not.contain", originalCardTitle);+ H.saveDashboard();H.getDashboardCard().realHover();- cy.findByLabelText("Show visualization options").click();- cy.findByTestId("Subtotal-settings-button").click();- H.popover().findByLabelText("Show a mini bar chart").click({ force: true });- cy.findAllByTestId("mini-bar-container").should("have.length.above", 0);+ H.getDashboardCardMenu().click();+ H.popover()+ .should("contain", "Edit question")+ .and("contain", "Download results");});});