Skip to content
Snippets Groups Projects
  • Kamil Mielnik's avatar
    71fdba7e
    User friendly error message when combining series that cannot be visualized together (#33119) · 71fdba7e
    Kamil Mielnik authored
    * Use named import for ErrorView
    
    * Export ErrorView and ErrorViewProps from Visualization
    
    * Define AddSeriesModalErrorView
    
    * Make ErrorView component configurable in Visualization by introducing errorView prop
    
    * Use AddSeriesModalErrorView thanks to new errorView prop
    
    * Fix export type syntax
    
    * Remove the dot for consistency with other error messages
    
    * Rename AddSeriesModalErrorView to ErrorView and extract it to a separate file
    
    * Allow translating the custom error message
    
    * Don't show custom ErrorView when there is only one series (or none)
    
    * Add a test case for a single incomplete chart
    
    * Inline: dashcardData
    
    * Add a reproduction e2e test for #32231
    
    * Add explicit assertion for the error message
    
    * Add a test case for default error message when there is only 1 series
    
    * Remove redundant setup functions
    
    * Wait for series query endpoint
    
    * Rename ErrorView to VisualizationErrorView
    
    * Rename VisualizationErrorView to MultipleSeriesErrorView
    
    * Improve assertions
    
    * Use editDashboard helper
    
    * Use data-testid for AddSeriesModal
    
    * Refactor errorView prop into errorMessageOverride
    - Do not export ErrorViewProps and Error out of Visualization
    User friendly error message when combining series that cannot be visualized together (#33119)
    Kamil Mielnik authored
    * Use named import for ErrorView
    
    * Export ErrorView and ErrorViewProps from Visualization
    
    * Define AddSeriesModalErrorView
    
    * Make ErrorView component configurable in Visualization by introducing errorView prop
    
    * Use AddSeriesModalErrorView thanks to new errorView prop
    
    * Fix export type syntax
    
    * Remove the dot for consistency with other error messages
    
    * Rename AddSeriesModalErrorView to ErrorView and extract it to a separate file
    
    * Allow translating the custom error message
    
    * Don't show custom ErrorView when there is only one series (or none)
    
    * Add a test case for a single incomplete chart
    
    * Inline: dashcardData
    
    * Add a reproduction e2e test for #32231
    
    * Add explicit assertion for the error message
    
    * Add a test case for default error message when there is only 1 series
    
    * Remove redundant setup functions
    
    * Wait for series query endpoint
    
    * Rename ErrorView to VisualizationErrorView
    
    * Rename VisualizationErrorView to MultipleSeriesErrorView
    
    * Improve assertions
    
    * Use editDashboard helper
    
    * Use data-testid for AddSeriesModal
    
    * Refactor errorView prop into errorMessageOverride
    - Do not export ErrorViewProps and Error out of Visualization
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
32231-add-incompatible-series.cy.spec.js 3.68 KiB
import { editDashboard, restore, visitDashboard } from "e2e/support/helpers";

import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";

const { PRODUCTS, PRODUCTS_ID } = SAMPLE_DATABASE;

const baseQuestion = {
  name: "Base question",
  query: {
    "source-table": PRODUCTS_ID,
    aggregation: [["count"]],
    breakout: [["field", PRODUCTS.CATEGORY, null]],
  },
  visualization_settings: {
    "graph.dimensions": ["CATEGORY"],
    "graph.metrics": ["count"],
  },
  display: "bar",
};

const incompleteQuestion = {
  name: "Incomplete question",
  native: {
    query: "select 1;",
  },
  visualization_settings: {
    "graph.dimensions": [null],
    "graph.metrics": ["1"],
  },
  display: "bar",
};

const issue32231Error = "Cannot read properties of undefined (reading 'name')";
const multipleSeriesError = "Unable to combine these questions";
const defaultError = "Which fields do you want to use for the X and Y axes?";

describe("issue 32231", () => {
  beforeEach(() => {
    restore();
    cy.signInAsAdmin();

    cy.intercept("GET", "/api/card/*/series?limit=*").as("seriesQuery");
  });

  it("should show user-friendly error when combining series that cannot be visualized together (metabase#32231)", () => {
    cy.createNativeQuestion(incompleteQuestion);
    cy.createQuestionAndDashboard({ questionDetails: baseQuestion }).then(
      ({ body: { id, card_id, dashboard_id } }) => {
        cy.request("PUT", `/api/dashboard/${dashboard_id}/cards`, {
          cards: [
            {
              id,
              card_id,
              row: 0,
              col: 0,
              size_x: 16,
              size_y: 10,
            },
          ],
        });

        visitDashboard(dashboard_id);
      },
    );

    editDashboard();
    cy.findByTestId("add-series-button").click({ force: true });
    cy.wait("@seriesQuery");

    cy.findByTestId("add-series-modal").within(() => {
      cy.get(".LineAreaBarChart").should("exist");
      cy.findByText(issue32231Error).should("not.exist");
      cy.findByText(multipleSeriesError).should("not.exist");
      cy.findByText(defaultError).should("not.exist");

      cy.findByText(incompleteQuestion.name).click();

      cy.get(".LineAreaBarChart").should("not.exist");
      cy.findByText(issue32231Error).should("not.exist");
      cy.findByText(multipleSeriesError).should("exist");
      cy.findByText(defaultError).should("not.exist");

      cy.findByText(incompleteQuestion.name).click();

      cy.get(".LineAreaBarChart").should("exist");
      cy.findByText(issue32231Error).should("not.exist");
      cy.findByText(multipleSeriesError).should("not.exist");
      cy.findByText(defaultError).should("not.exist");
    });
  });

  it("should show default visualization error message when the only series is incomplete", () => {
    cy.createNativeQuestionAndDashboard({
      questionDetails: incompleteQuestion,
    }).then(({ body: { id, card_id, dashboard_id } }) => {
      cy.request("PUT", `/api/dashboard/${dashboard_id}/cards`, {
        cards: [
          {
            id,
            card_id,
            row: 0,
            col: 0,
            size_x: 16,
            size_y: 10,
          },
        ],
      });

      visitDashboard(dashboard_id);
    });

    cy.findByTestId("dashcard").findByText(defaultError).should("exist");

    cy.icon("pencil").click();
    cy.findByTestId("add-series-button").click({ force: true });
    cy.wait("@seriesQuery");

    cy.findByTestId("add-series-modal").within(() => {
      cy.get(".LineAreaBarChart").should("not.exist");
      cy.findByText(issue32231Error).should("not.exist");
      cy.findByText(multipleSeriesError).should("not.exist");
      cy.findByText(defaultError).should("exist");
    });
  });
});