Skip to content

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

25.1 KB
Raw Blame
const { H } = cy;

import { ORDERS_DASHBOARD_ID } from "e2e/support/cypress_sample_instance_data";
import {
  ACCOUNTS_COUNT_BY_COUNTRY,
  COUNTRY_CODES,
  ORDERS_COUNT_BY_CREATED_AT,
  ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY,
  ORDERS_COUNT_BY_PRODUCT_CATEGORY,
  PIVOT_TABLE_CARD,
  PRODUCTS_AVERAGE_BY_CREATED_AT,
  PRODUCTS_COUNT_BY_CATEGORY,
  PRODUCTS_COUNT_BY_CREATED_AT,
  SCALAR_CARD,
  STEP_COLUMN_CARD,
  VIEWS_COLUMN_CARD,
  createDashboardWithVisualizerDashcards,
} from "e2e/support/test-visualizer-data";

describe("scenarios > visualizer > cartesian", () => {
  beforeEach(() => {
    H.restore();

    cy.intercept("POST", "/api/card/*/query").as("cardQuery");

    cy.signInAsNormalUser();

    H.createQuestion(ORDERS_COUNT_BY_CREATED_AT, {
      idAlias: "ordersCountByCreatedAtQuestionId",
      wrapId: true,
    });
    H.createQuestion(ORDERS_COUNT_BY_PRODUCT_CATEGORY, {
      idAlias: "ordersCountByProductCategoryQuestionId",
      wrapId: true,
    });
    H.createQuestion(ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY, {
      idAlias: "ordersCountByCreatedAtAndProductCategoryQuestionId",
      wrapId: true,
    });
    H.createQuestion(PRODUCTS_COUNT_BY_CREATED_AT, {
      idAlias: "productsCountByCreatedAtQuestionId",
      wrapId: true,
    });
    H.createQuestion(PRODUCTS_AVERAGE_BY_CREATED_AT, {
      idAlias: "productsAvgByCreatedAtQuestionId",
      wrapId: true,
    });
    H.createQuestion(PRODUCTS_COUNT_BY_CATEGORY, {
      idAlias: "productsCountByCategoryQuestionId",
      wrapId: true,
    });
  });

  it("should allow to change cartesian and pie viz settings (metabase#61197)", () => {
    H.createNativeQuestion(SCALAR_CARD.LANDING_PAGE_VIEWS, {
      idAlias: "landingPageViewsScalarQuestionId",
      wrapId: true,
    });
    H.createNativeQuestion(SCALAR_CARD.CHECKOUT_PAGE_VIEWS, {
      idAlias: "checkoutPageViewsScalarQuestionId",
      wrapId: true,
    });
    H.createNativeQuestion(SCALAR_CARD.PAYMENT_DONE_PAGE_VIEWS, {
      idAlias: "paymentDonePageViewsScalarQuestionId",
      wrapId: true,
    });
    H.createNativeQuestion(STEP_COLUMN_CARD, {
      idAlias: "stepColumnQuestionId",
      wrapId: true,
    });
    H.createNativeQuestion(VIEWS_COLUMN_CARD, {
      idAlias: "viewsColumnQuestionId",
      wrapId: true,
    });

    createDashboardWithVisualizerDashcards();
    H.editDashboard();

    H.showDashcardVisualizerModalSettings(0);

    H.modal().within(() => {
      H.goalLine().should("not.exist");
      cy.findByTestId("chartsettings-sidebar").findByText("Goal line").click();
      H.goalLine().should("exist");

      cy.findByTestId("chartsettings-sidebar").findByText("Trend line").click();
      H.trendLine().should("have.length", 2);

      // Ensure the chart legend contains original series name
      H.chartLegend().within(() => {
        cy.findByText(PRODUCTS_COUNT_BY_CREATED_AT.name).should("exist");
      });

      // Edit series settings
      cy.findAllByTestId("series-settings").within(() => {
        // Update series name
        cy.findAllByTestId("series-name-input")
          .eq(1)
          .type("{selectall}{del}Series B")
          .blur();

        // Update series display type
        cy.icon("chevrondown").eq(1).click();
        cy.icon("bar").click();

        // Update series color
        cy.findAllByTestId("color-selector-button").eq(1).click();
      });
    });

    H.popover().findByLabelText("#F9D45C").click();

    const assertUpdatedVizSettingsApplied = () => {
      H.goalLine().should("exist");
      H.trendLine().should("have.length", 2);
      // Ensure the chart legend contains renamed series
      H.chartLegend().within(() => {
        cy.findByText("Series B").should("exist");
        cy.findByText(PRODUCTS_COUNT_BY_CREATED_AT.name).should("not.exist");
      });
      H.chartPathWithFillColor("#F9D45C");
    };

    H.modal().within(() => {
      assertUpdatedVizSettingsApplied();
    });

    H.saveDashcardVisualizerModalSettings();

    H.getDashboardCard(0).within(() => {
      assertUpdatedVizSettingsApplied();
    });

    // Pie chart
    H.getDashboardCard(2).within(() => {
      H.echartsContainer().findByText("Total").should("exist");
    });
    H.showDashcardVisualizerModalSettings(2);
    H.modal().within(() => {
      cy.findByText("Display").click();

      H.echartsContainer().within(() => {
        cy.findByText("200").should("exist");
        cy.findByText("Total").should("exist");
      });
      cy.findByTestId("chartsettings-sidebar").findByText("Show total").click();
      H.echartsContainer().within(() => {
        cy.findByText("200").should("not.exist");
        cy.findByText("Total").should("not.exist");
      });
    });
    H.saveDashcardVisualizerModalSettings();

    // Hovering a pie slice hides the total, so move the pointer away first
    H.getDashboardCard(0).realHover();
    H.getDashboardCard(2).within(() => {
      H.pieSlices().should("have.length", 4);
      H.echartsContainer().within(() => {
        cy.findByText("200").should("not.exist");
        cy.findByText("Total").should("not.exist");
      });
    });
  });

  it("should work correctly when built from a non-cartesian chart", () => {
    H.createQuestion(PIVOT_TABLE_CARD);

    H.visitDashboard(ORDERS_DASHBOARD_ID);
    H.editDashboard();
    H.openQuestionsSidebar();
    H.clickVisualizeAnotherWay(PIVOT_TABLE_CARD.name);

    H.modal().within(() => {
      H.switchToAddMoreData();
      H.selectDataset(ORDERS_COUNT_BY_CREATED_AT.name);
      H.switchToColumnsList();
      H.selectColumnFromColumnsList(ORDERS_COUNT_BY_CREATED_AT.name, "Count");

      // VIZ-668 pivot-grouping is an internal column used by the pivot table and shouldn't be
      // shown in the columns list
      H.dataSourceColumn(PIVOT_TABLE_CARD.name, "Count").should("exist");
      H.dataSource(PIVOT_TABLE_CARD.name)
        .findByText("pivot-grouping")
        .should("not.exist");

      H.verticalWell().within(() => {
        cy.findByText("Count").should("exist");

        cy.findByText(`Count (${ORDERS_COUNT_BY_CREATED_AT.name})`).should(
          "exist",
        );
        cy.findAllByTestId("well-item").should("have.length", 2);
      });
      H.horizontalWell().within(() => {
        cy.findByText("Created At: Year").should("exist");
        cy.findAllByTestId("well-item").should("have.length", 1);
      });

      H.chartLegendItems().should("have.length", 2);
    });
  });

  it("should work with more than two datasets (VIZ-693)", () => {
    H.createDashboard().then(({ body: { id: dashboardId } }) => {
      H.visitDashboard(dashboardId);
    });

    H.editDashboard();

    H.openQuestionsSidebar();
    H.clickVisualizeAnotherWay(ORDERS_COUNT_BY_CREATED_AT.name);

    H.modal().within(() => {
      H.switchToAddMoreData();
      H.selectDataset(PRODUCTS_COUNT_BY_CREATED_AT.name);
      H.assertWellItems({
        vertical: ["Count", "Count (Products by Created At (Month))"],
      });
      H.selectDataset(PRODUCTS_AVERAGE_BY_CREATED_AT.name);
      H.assertWellItems({
        vertical: [
          "Count",
          "Count (Products by Created At (Month))",
          "Average of Price",
        ],
      });
    });

    H.saveDashcardVisualizerModal({ mode: "create" });

    // the new dashcard is below the minimum size for showing a legend,
    // so enlarge it before asserting on the legend items
    H.resizeDashboardCard({ card: H.getDashboardCard(0), x: 2000, y: 600 });

    // Wait for card queries before saving the dashboard
    H.getDashboardCard(0).within(() => {
      cy.findByText(PRODUCTS_COUNT_BY_CREATED_AT.name).should("exist");
      cy.findByText("Created At: Month").should("exist");
    });

    H.saveDashboard();

    // Making sure the card renders after saving the dashboard
    H.getDashboardCard(0).within(() => {
      cy.findByText(PRODUCTS_COUNT_BY_CREATED_AT.name).should("exist");
      cy.findByText("Created At: Month").should("exist");
    });
  });

  it("should not drop dimensions when changing viz type to another cartesian chart (VIZ-648)", () => {
    H.visitDashboard(ORDERS_DASHBOARD_ID);
    H.editDashboard();
    H.openQuestionsSidebar();

    H.clickVisualizeAnotherWay(
      ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.name,
    );

    H.modal().within(() => {
      H.selectVisualization("area");

      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.name,
        "Count",
      );
      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.name,
        "Created At: Month",
      );
      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.name,
        "Product → Category",
      );
    });
  });

  it("should preserve default colors (VIZ-1211)", () => {
    H.visitDashboard(ORDERS_DASHBOARD_ID);
    H.editDashboard();
    H.openQuestionsSidebar();

    H.sidebar().within(() => {
      cy.findByRole("menuitem", {
        name: ORDERS_COUNT_BY_PRODUCT_CATEGORY.name,
      }).click();
    });

    H.showDashcardVisualizerModal(1, {
      isVisualizerCard: false,
    });

    H.modal().within(() => {
      H.chartPathWithFillColor("#509EE3").should("have.length", 4);
    });
  });

  it("should remap columns when changing a viz type", () => {
    H.visitDashboard(ORDERS_DASHBOARD_ID);
    H.editDashboard();

    H.openQuestionsSidebar();
    H.clickVisualizeAnotherWay(ORDERS_COUNT_BY_PRODUCT_CATEGORY.name);

    H.modal().within(() => {
      // Turn into a pie chart
      cy.findByTestId("viz-picker-main").icon("pie").click();
      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_PRODUCT_CATEGORY.name,
        "Count",
      );
      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_PRODUCT_CATEGORY.name,
        "Product → Category",
      );
      H.pieMetricWell().findByText("Count").should("exist");
      H.pieDimensionWell().findByText("Product → Category").should("exist");
      H.echartsContainer().findByText("18,760").should("exist"); // total value

      // Turn into a funnel
      cy.findByTestId("viz-picker-main").icon("funnel").click();
      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_PRODUCT_CATEGORY.name,
        "Count",
      );
      H.assertDataSourceColumnSelected(
        ORDERS_COUNT_BY_PRODUCT_CATEGORY.name,
        "Product → Category",
      );
      H.verticalWell().findByText("Count").should("exist");
      H.horizontalWell().within(() => {
        cy.findByText("Product → Category").should("exist");
        cy.findByText("Doohickey").should("exist");
        cy.findByText("Gadget").should("exist");
        cy.findByText("Gizmo").should("exist");
        cy.findByText("Widget").should("exist");
        cy.findAllByTestId("well-item").should("have.length", 5);
      });
    });
  });

  it("should preserve column mapping when switching between cartesian and pie", () => {
    H.createQuestion(ACCOUNTS_COUNT_BY_COUNTRY);
    H.createDashboard().then(({ body: { id: dashboardId } }) => {
      H.visitDashboard(dashboardId);
    });

    H.editDashboard();

    H.openQuestionsSidebar();
    H.clickVisualizeAnotherWay(ACCOUNTS_COUNT_BY_COUNTRY.name);

    H.modal().within(() => {
      H.assertWellItems({ horizontal: ["Country"], vertical: ["Count"] });

      cy.log("cartesian (starting point) -> funnel -> scatter");
      H.selectVisualization("funnel");
      H.assertWellItems({
        horizontal: ["Country", ...COUNTRY_CODES],
        vertical: ["Count"],
      });
      H.selectVisualization("scatter");
      H.assertWellItems({ horizontal: ["Country"], vertical: ["Count"] });

      cy.log("Resetting the visualization to cartesian");
      H.clickUndoButton();
      H.clickUndoButton();

      cy.log("cartesian (starting point) -> pie -> funnel -> scatter");
      H.selectVisualization("pie");
      H.assertWellItems({ pieDimensions: ["Country"], pieMetric: ["Count"] });
      H.selectVisualization("funnel");
      H.assertWellItems({
        horizontal: ["Country", ...COUNTRY_CODES],
        vertical: ["Count"],
      });
      H.selectVisualization("scatter");
      H.assertWellItems({ horizontal: ["Country"], vertical: ["Count"] });
    });
  });

  it("should handle implicit viz settings (VIZ-947)", () => {
    function assertDataSourceColumnSelected(
      columnName: string,
      isSelected = true,
    ) {
      H.assertDataSourceColumnSelected(
        PIVOT_TABLE_CARD.name,
        columnName,
        isSelected,
      );
    }

    H.createQuestion(PIVOT_TABLE_CARD);

    H.visitDashboard(ORDERS_DASHBOARD_ID);
    H.editDashboard();
    H.openQuestionsSidebar();
    H.clickVisualizeAnotherWay(PIVOT_TABLE_CARD.name);

    H.modal().within(() => {
      assertDataSourceColumnSelected("Count");
      assertDataSourceColumnSelected("Average of Quantity", false);
      assertDataSourceColumnSelected("Created At: Year");
      assertDataSourceColumnSelected("Product → Category", false);
      H.chartPathWithFillColor("#509EE3").should("have.length", 5);
      H.verticalWell().findAllByTestId("well-item").should("have.length", 1);
      H.horizontalWell().findAllByTestId("well-item").should("have.length", 1);

      // Add Category column
      H.dataSourceColumn(PIVOT_TABLE_CARD.name, "Product → Category").click();
      assertDataSourceColumnSelected("Count");
      assertDataSourceColumnSelected("Average of Quantity", false);
      assertDataSourceColumnSelected("Created At: Year");
      assertDataSourceColumnSelected("Product → Category");
      H.chartLegendItems().should("have.length", 5);
      H.verticalWell().findAllByTestId("well-item").should("have.length", 1);
      H.horizontalWell().findAllByTestId("well-item").should("have.length", 2);

      // Add Average of Quantity column
      H.dataSourceColumn(PIVOT_TABLE_CARD.name, "Average of Quantity").click();
      assertDataSourceColumnSelected("Count");
      assertDataSourceColumnSelected("Average of Quantity");
      assertDataSourceColumnSelected("Created At: Year");
      assertDataSourceColumnSelected("Product → Category");
      H.chartLegendItems().should("have.length", 5);
      H.verticalWell().findAllByTestId("well-item").should("have.length", 2);
      H.horizontalWell().findAllByTestId("well-item").should("have.length", 2);

      // Remove dimensions
      H.deselectColumnFromColumnsList(
        PIVOT_TABLE_CARD.name,
        "Created At: Year",
      );
      H.deselectColumnFromColumnsList(
        PIVOT_TABLE_CARD.name,
        "Product → Category",
      );
      assertDataSourceColumnSelected("Count");
      assertDataSourceColumnSelected("Average of Quantity");
      assertDataSourceColumnSelected("Created At: Year", false);
      assertDataSourceColumnSelected("Product → Category", false);
      H.echartsContainer().should("not.exist");
      H.verticalWell().findAllByTestId("well-item").should("have.length", 2);
      H.horizontalWell().findAllByTestId("well-item").should("have.length", 0);

      // Add a dimension back
      H.dataSourceColumn(PIVOT_TABLE_CARD.name, "Created At: Year").click();
      assertDataSourceColumnSelected("Count");
      assertDataSourceColumnSelected("Average of Quantity");
      assertDataSourceColumnSelected("Created At: Year");
      assertDataSourceColumnSelected("Product → Category", false);
      H.echartsContainer().should("exist");
      H.verticalWell().findAllByTestId("well-item").should("have.length", 2);
      H.horizontalWell().findAllByTestId("well-item").should("have.length", 1);
      H.chartLegendItems().should("have.length", 2);
    });
  });

  describe("timeseries breakout", () => {
    it("should automatically use new columns whenever possible", () => {
      const Q1_NAME = ORDERS_COUNT_BY_CREATED_AT.name;
      const Q2_NAME = PRODUCTS_COUNT_BY_CREATED_AT.name;

      H.visitDashboard(ORDERS_DASHBOARD_ID);
      H.editDashboard();
      H.openQuestionsSidebar();

      H.clickVisualizeAnotherWay(Q1_NAME);

      H.modal().within(() => {
        H.switchToAddMoreData();
        H.selectDataset(Q2_NAME);
        H.switchToColumnsList();

        H.verticalWell().within(() => {
          cy.findByText("Count").should("exist");
          cy.findByText(`Count (${Q2_NAME})`).should("exist");
        });
        H.horizontalWell().findByText("Created At: Month").should("exist");

        H.ensureDisplayIsSelected("line");

        H.echartsContainer().within(() => {
          // x-axis labels
          cy.findByText("January 2026").should("exist");
          cy.findByText("January 2029").should("exist");
          // y-axis labels
          cy.findByText("600").should("exist");
          cy.findByText("10").should("exist");
        });

        H.dataSource(Q1_NAME).should("exist");
        H.dataSource(Q2_NAME).should("exist");
        H.assertDataSourceColumnSelected(Q1_NAME, "Count");
        H.assertDataSourceColumnSelected(Q1_NAME, "Created At: Month");
        H.assertDataSourceColumnSelected(Q2_NAME, "Count");
        H.assertDataSourceColumnSelected(Q2_NAME, "Created At: Month");
        H.chartLegendItems().should("have.length", 2);

        // Remove 2nd count column from the data manager
        H.deselectColumnFromColumnsList(Q2_NAME, "Count");
        H.assertDataSourceColumnSelected(Q2_NAME, "Count", false);
        H.verticalWell().findByText(`Count (${Q2_NAME})`).should("not.exist");
        // legend is visible only when there are multiple series
        H.chartLegend().should("not.exist");

        // Add back 2nd count column from the data manager
        H.dataSourceColumn(Q2_NAME, "Count").click();
        H.assertDataSourceColumnSelected(Q2_NAME, "Count");
        H.verticalWell().findByText(`Count (${Q2_NAME})`).should("exist");
        H.chartLegendItems().should("have.length", 2);

        // Remove all count columns from the well
        H.verticalWell().within(() => {
          cy.findAllByTestId("well-item")
            .first()
            .findByLabelText("Remove")
            .click();
          cy.findByTestId("well-item").findByLabelText("Remove").click();
        });

        H.assertDataSourceColumnSelected(Q1_NAME, "Count", false);
        H.assertDataSourceColumnSelected(Q2_NAME, "Count", false);
        H.chartLegend().should("not.exist");

        // Remove all "created at" columns from the well
        H.horizontalWell()
          .findByTestId("well-item")
          .findByLabelText("Remove")
          .click();
        H.assertDataSourceColumnSelected(Q1_NAME, "Created At: Month", false);
        H.assertDataSourceColumnSelected(Q2_NAME, "Created At: Month", false);
        H.chartLegend().should("not.exist");

        // Add all columns back
        H.dataSourceColumn(Q1_NAME, "Count").click();
        H.dataSourceColumn(Q1_NAME, "Created At: Month").click();
        H.dataSourceColumn(Q2_NAME, "Count").click();
        H.dataSourceColumn(Q2_NAME, "Created At: Month").click();
        H.verticalWell().findAllByTestId("well-item").should("have.length", 2);
        H.horizontalWell()
          .findAllByTestId("well-item")
          .should("have.length", 1);
        H.chartLegendItems().should("have.length", 2);

        // Remove 2nd data source
        H.removeDataSource(Q2_NAME);
        H.dataImporter().within(() => {
          cy.findByText(Q2_NAME).should("not.exist");
          cy.findAllByText("Count").should("have.length", 1);
          cy.findAllByText("Created At: Month").should("have.length", 1);
        });
        H.verticalWell().findAllByTestId("well-item").should("have.length", 1);
        H.horizontalWell()
          .findAllByTestId("well-item")
          .should("have.length", 1);
        H.chartLegend().should("not.exist");
      });
    });
  });

  describe("category breakout", () => {
    it("should automatically use new columns whenever possible", () => {
      const Q1_NAME = ORDERS_COUNT_BY_PRODUCT_CATEGORY.name;
      const Q2_NAME = PRODUCTS_COUNT_BY_CATEGORY.name;

      H.visitDashboard(ORDERS_DASHBOARD_ID);
      H.editDashboard();
      H.openQuestionsSidebar();

      H.clickVisualizeAnotherWay(Q1_NAME);

      H.modal().within(() => {
        cy.button("Add more data").click();
        H.selectDataset(Q2_NAME);
        cy.button("Done").click();

        H.verticalWell().within(() => {
          cy.findByText("Count").should("exist");
          cy.findByText(`Count (${Q2_NAME})`).should("exist");
        });
        H.horizontalWell().findByText("Product → Category").should("exist");

        H.assertCurrentVisualization("bar");

        H.echartsContainer().within(() => {
          // x-axis labels
          cy.findByText("Doohickey").should("exist");
          cy.findByText("Widget").should("exist");
          // y-axis labels
          cy.findByText("6.0k").should("be.visible");
          cy.findByText("3.0k").should("be.visible");
        });

        H.dataSource(Q1_NAME).should("exist");
        H.dataSource(Q2_NAME).should("exist");
        H.assertDataSourceColumnSelected(Q1_NAME, "Count");
        H.assertDataSourceColumnSelected(Q1_NAME, "Product → Category");
        H.assertDataSourceColumnSelected(Q2_NAME, "Count");
        H.assertDataSourceColumnSelected(Q2_NAME, "Category");
        H.chartLegendItems().should("have.length", 2);

        // Remove 2nd count column from the data manager
        H.dataSourceColumn(Q2_NAME, "Count").findByLabelText("Remove").click();
        H.assertDataSourceColumnSelected(Q2_NAME, "Count", false);
        H.verticalWell().findByText(`Count (${Q2_NAME})`).should("not.exist");
        // legend is visible only when there are multiple series
        H.chartLegend().should("not.exist");

        // Add 2nd count column from the data manager
        H.dataSourceColumn(Q2_NAME, "Count").click();
        H.assertDataSourceColumnSelected(Q2_NAME, "Count");
        H.verticalWell().findByText(`Count (${Q2_NAME})`).should("exist");
        H.chartLegendItems().should("have.length", 2);

        // Remove all count columns from the well
        H.verticalWell().within(() => {
          cy.findAllByTestId("well-item")
            .first()
            .findByLabelText("Remove")
            .click();
          cy.findByTestId("well-item").findByLabelText("Remove").click();
        });
        H.assertDataSourceColumnSelected(Q1_NAME, "Count", false);
        H.assertDataSourceColumnSelected(Q2_NAME, "Count", false);
        H.chartLegend().should("not.exist");

        // Remove all "category" columns from the well
        H.horizontalWell().within(() => {
          cy.findAllByTestId("well-item")
            .first()
            .findByLabelText("Remove")
            .click();
        });
        H.assertDataSourceColumnSelected(Q1_NAME, "Product → Category", false);
        H.assertDataSourceColumnSelected(Q2_NAME, "Category", false);
        H.chartLegend().should("not.exist");

        // Add all columns back
        H.dataSourceColumn(Q1_NAME, "Count").click();
        H.dataSourceColumn(Q1_NAME, "Product → Category").click();
        H.dataSourceColumn(Q2_NAME, "Count").click();
        H.dataSourceColumn(Q2_NAME, "Category").click();
        H.verticalWell().findAllByTestId("well-item").should("have.length", 2);
        H.horizontalWell()
          .findAllByTestId("well-item")
          .should("have.length", 2);
        H.chartLegendItems().should("have.length", 2);

        // Remove 2nd data source
        H.removeDataSource(Q2_NAME);
        H.dataImporter().within(() => {
          cy.findByText(Q2_NAME).should("not.exist");
          cy.findAllByText("Count").should("have.length", 1);
          cy.findAllByText("Category").should("not.exist");
        });
        H.verticalWell().findAllByTestId("well-item").should("have.length", 1);
        H.horizontalWell()
          .findAllByTestId("well-item")
          .should("have.length", 1);
        H.chartLegend().should("not.exist");
      });
    });

    it("should show only enabled series in the visualizer based on the card's viz settings", () => {
      const visualization_settings = {
        ...ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.visualization_settings,
        "graph.series_order": [
          {
            name: "Gadget",
            enabled: false,
            color: "#F9D45C",
            key: "Gadget",
          },
          {
            key: "Doohickey",
            color: "#88BF4D",
            enabled: true,
            name: "Doohickey",
          },
          {
            key: "Gizmo",
            color: "#A989C5",
            enabled: true,
            name: "Gizmo",
          },
          {
            name: "Widget",
            enabled: false,
            color: "#F2A86F",
            key: "Widget",
          },
        ],
        "graph.series_order_dimension": "CATEGORY",
      };

      H.createDashboardWithQuestions({
        questions: [
          {
            ...ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY,
            visualization_settings,
          },
        ],
      }).then(({ dashboard }) => {
        H.visitDashboard(dashboard.id);
      });

      H.getDashboardCard(0)
        .findAllByTestId("legend-item")
        .should("have.length", 2);

      H.editDashboard();
      H.showDashcardVisualizerModal(0, {
        isVisualizerCard: false,
      });

      H.modal().within(() => {
        cy.findAllByTestId("legend-item").should("have.length", 2);
        cy.button("Settings").click();
        cy.findAllByTestId("series-name-input").should("have.length", 2);
      });
    });
  });
});