Skip to content

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

35.6 KB
Raw Blame
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
import {
  NORMAL_USER_ID,
  ORDERS_DASHBOARD_ID,
} from "e2e/support/cypress_sample_instance_data";
import type {
  DashboardDetails,
  StructuredQuestionDetails,
} from "e2e/support/helpers";
import { uploadTranslationDictionaryViaAPI } from "e2e/support/helpers/e2e-content-translation-helpers";
import {
  ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY,
  PRODUCTS_COUNT_BY_CATEGORY_PIE,
} from "e2e/support/test-visualizer-data";
import type { DictionaryArray } from "metabase-types/api";
const { ORDERS, ORDERS_ID } = SAMPLE_DATABASE;

const { ACCOUNTS_ID, ACCOUNTS, PRODUCTS, PRODUCTS_ID, PEOPLE, PEOPLE_ID } =
  SAMPLE_DATABASE;
import {
  frenchBooleanTranslations,
  frenchNames,
  germanFieldNames,
  germanFieldValues,
} from "./helpers/constants";

const { H } = cy;

describe("scenarios > content translation > static embeds > dashboards", () => {
  describe("pivot table renamed column (metabase#63296)", () => {
    beforeEach(() => {
      H.restore();
      cy.signInAsAdmin();
      H.activateToken("pro-self-hosted");

      uploadTranslationDictionaryViaAPI([
        { locale: "fr", msgid: "Category", msgstr: "La catégorie" },
        { locale: "fr", msgid: "Title", msgstr: "Le titre" },
      ]);

      cy.intercept("GET", "/api/embed/dashboard/*").as("dashboard");

      cy.signInAsAdmin();

      H.createQuestion(ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY, {
        idAlias: "productsCountByCreatedAtQuestionId",
        wrapId: true,
      });

      H.createQuestion({
        name: "Pivot table",
        display: "pivot",
        query: {
          aggregation: [["count"]],
          breakout: [
            ["field", PRODUCTS.CATEGORY, null],
            ["field", PRODUCTS.TITLE, null],
          ],
          "source-table": PRODUCTS_ID,
        },
        visualization_settings: {
          "pivot_table.column_split": {
            rows: ["CATEGORY", "TITLE"],
            columns: [],
            values: ["count"],
          },
          column_settings: {
            '["name", "CATEGORY"]': {
              column_title: "Category",
            },
          },
        },
      });
    });

    it("should translate the renamed column title of a pivot table", () => {
      H.createDashboard({
        name: "the_dashboard",
      }).then(({ body: { id: dashboardId } }) => {
        H.visitDashboard(dashboardId);
        H.editDashboard();
        H.openQuestionsSidebar();

        H.sidebar().findByText("Pivot table").click();

        H.saveDashboard();

        H.openLegacyStaticEmbeddingModal({
          resource: "dashboard",
          resourceId: dashboardId,
        });
        H.publishChanges("dashboard", () => {});

        H.visitEmbeddedPage(
          {
            // Unjustified type cast. FIXME
            resource: { dashboard: dashboardId as number },
            params: {},
          },
          {
            additionalHashOptions: {
              locale: "fr",
            },
          },
        );

        cy.wait("@dashboard");

        H.getDashboardCard(0).within(() => {
          cy.findByText("La catégorie").should("exist");
        });
      });
    });
  });

  describe("card titles and descriptions", () => {
    beforeEach(() => {
      H.restore();
      cy.signInAsAdmin();
      H.activateToken("pro-self-hosted");

      uploadTranslationDictionaryViaAPI([
        { locale: "fr", msgid: "Gadget", msgstr: "Le gadget" },
        { locale: "fr", msgid: "Doohickey", msgstr: "Le doohickey" },
        { locale: "fr", msgid: "Gizmo", msgstr: "Le gizmo" },
        { locale: "fr", msgid: "Widget", msgstr: "Le widget" },
        {
          locale: "fr",
          msgid: "Products by Category (Pie)",
          msgstr: "Produits par catégorie (Camembert)",
        },
        {
          locale: "fr",
          msgid: "A breakdown of products by category",
          msgstr: "Une répartition des produits par catégorie",
        },
      ]);

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

      cy.signInAsAdmin();

      H.createQuestion(ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY, {
        idAlias: "productsCountByCreatedAtQuestionId",
        wrapId: true,
      });

      H.createQuestion(
        {
          ...PRODUCTS_COUNT_BY_CATEGORY_PIE,
          description: "A breakdown of products by category",
        },
        {
          idAlias: "productsCountByCategoryPieQuestionId",
          wrapId: true,
        },
      );
    });

    it("should translate guest embeds dashboard card titles and descriptions", () => {
      H.createDashboard({
        name: "the_dashboard",
      }).then(({ body: { id: dashboardId } }) => {
        H.visitDashboard(dashboardId);
        H.editDashboard();
        H.openQuestionsSidebar();

        H.sidebar().findByText(PRODUCTS_COUNT_BY_CATEGORY_PIE.name).click();
        H.saveDashboard();

        H.openLegacyStaticEmbeddingModal({
          resource: "dashboard",
          resourceId: dashboardId,
        });
        H.publishChanges("dashboard", () => {});

        H.visitEmbeddedPage(
          {
            // Unjustified type cast. FIXME
            resource: { dashboard: dashboardId as number },
            params: {},
          },
          {
            additionalHashOptions: {
              locale: "fr",
            },
          },
        );

        cy.wait("@dashboard");
        cy.wait("@cardQuery");

        // Check that the title is translated
        cy.findByText("Produits par catégorie (Camembert)").should("exist");

        H.getDashboardCard(0).realHover().icon("info").realHover();
        H.tooltip().within(() => {
          // Check that the description is translated
          cy.findByText("Une répartition des produits par catégorie").should(
            "exist",
          );
        });
      });
    });
  });

  describe("values translation", () => {
    beforeEach(() => {
      H.restore();
      cy.signInAsAdmin();
      H.activateToken("pro-self-hosted");

      uploadTranslationDictionaryViaAPI([
        { locale: "fr", msgid: "Gadget", msgstr: "Le gadget" },
        { locale: "fr", msgid: "Doohickey", msgstr: "Le doohickey" },
        { locale: "fr", msgid: "Gizmo", msgstr: "Le gizmo" },
        { locale: "fr", msgid: "Widget", msgstr: "Le widget" },
      ]);

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

      cy.signInAsAdmin();

      H.createQuestion(ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY, {
        idAlias: "productsCountByCreatedAtQuestionId",
        wrapId: true,
      });

      H.createQuestion(
        {
          ...PRODUCTS_COUNT_BY_CATEGORY_PIE,
          visualization_settings: {
            "pie.rows": [
              ["Widget", "#69C8C8"],
              ["Gadget", "#C7EAEA"],
              ["Gizmo", "#98D9D9"],
              ["Doohickey", "#F3F3F4"],
            ].map(([key, color]) => ({
              key,
              name: key,
              originalName: key,
              color,
              defaultColor: false,
              enabled: true,
              hidden: false,
              isOther: false,
            })),
          },
        },
        {
          idAlias: "productsCountByCategoryPieQuestionId",
          wrapId: true,
        },
      );
    });

    it("should assign the proper colors to a pie", () => {
      H.createDashboard({
        name: "the_dashboard",
      }).then(({ body: { id: dashboardId } }) => {
        H.visitDashboard(dashboardId);
        H.editDashboard();
        H.openQuestionsSidebar();

        H.sidebar().findByText(PRODUCTS_COUNT_BY_CATEGORY_PIE.name).click();
        H.saveDashboard();

        H.openLegacyStaticEmbeddingModal({
          resource: "dashboard",
          resourceId: dashboardId,
        });
        H.publishChanges("dashboard", () => {});

        H.visitEmbeddedPage(
          {
            // Unjustified type cast. FIXME
            resource: { dashboard: dashboardId as number },
            params: {},
          },
          {
            additionalHashOptions: {
              locale: "fr",
            },
          },
        );

        cy.wait("@dashboard");
        cy.wait("@cardQuery");

        H.getDashboardCard(0).within(() => {
          cy.findAllByText("Le gadget").should("exist");
          cy.findAllByText("Le doohickey").should("exist");
          cy.findAllByText("Le gizmo").should("exist");
          cy.findAllByText("Le widget").should("exist");

          // Verify colors
          cy.findByTestId("chart-legend").within(() => {
            cy.findAllByTestId("legend-item")
              .find("button")
              .then(($elements) => {
                const actualColors = Array.from($elements).map((element) =>
                  element.style.getPropertyValue("--legend-dot-color"),
                );
                expect(actualColors).to.deep.equal([
                  "#69C8C8",
                  "#C7EAEA",
                  "#98D9D9",
                  "#F3F3F4",
                ]);
              });
          });
        });
      });
    });

    it("should translate guest embeds dashboard values on visualizer cards (metabase#62373)", () => {
      H.visitDashboard(ORDERS_DASHBOARD_ID);

      H.editDashboard();
      H.removeDashboardCard(0);
      H.openQuestionsSidebar();

      // Add the regular question
      H.sidebar()
        .findByText(ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.name)
        .click();

      // Add the visualizer question
      H.clickVisualizeAnotherWay(
        ORDERS_COUNT_BY_CREATED_AT_AND_PRODUCT_CATEGORY.name,
      );
      H.selectVisualization("bar");
      H.saveDashcardVisualizerModal({ mode: "create" });
      H.saveDashboard();

      H.openLegacyStaticEmbeddingModal({
        resource: "dashboard",
        resourceId: ORDERS_DASHBOARD_ID,
      });
      H.publishChanges("dashboard", () => {});

      H.visitEmbeddedPage(
        {
          resource: { dashboard: ORDERS_DASHBOARD_ID },
          params: {},
        },
        {
          additionalHashOptions: {
            locale: "fr",
          },
        },
      );

      cy.wait("@dashboard");
      cy.wait("@cardQuery");
      cy.wait("@cardQuery");

      H.getDashboardCard(0).within(() => {
        cy.findAllByText("Le gadget").should("exist");
        cy.findAllByText("Le doohickey").should("exist");
        cy.findAllByText("Le gizmo").should("exist");
        cy.findAllByText("Le widget").should("exist");
      });

      H.getDashboardCard(1).within(() => {
        cy.findAllByText("Le gadget").should("exist");
        cy.findAllByText("Le doohickey").should("exist");
        cy.findAllByText("Le gizmo").should("exist");
        cy.findAllByText("Le widget").should("exist");
      });
    });
  });

  describe("measure names", () => {
    before(() => {
      cy.intercept("POST", "/api/ee/content-translation/upload-dictionary").as(
        "uploadDictionary",
      );

      H.restore();
      cy.signInAsAdmin();
      H.activateToken("pro-self-hosted");

      uploadTranslationDictionaryViaAPI([
        ...germanFieldNames,
        ...germanFieldValues,
        ...frenchNames,
        ...frenchBooleanTranslations,
      ]);
      H.snapshot("with-translations");
    });

    beforeEach(() => {
      cy.intercept("GET", "/api/embed/dashboard/*").as("dashboard");
      cy.intercept("GET", "/api/embed/dashboard/**/card/*").as("cardQuery");
      cy.intercept("GET", "/api/embed/dashboard/**/search/*").as("searchQuery");
      // Unjustified type cast. FIXME
      H.restore("with-translations" as any);
    });

    it("should translate pivot table measure names", () => {
      const pivotQuestionDetails: StructuredQuestionDetails = {
        name: "Pivot Table Test",
        query: {
          "source-table": ORDERS_ID,
          aggregation: [["count"]],
          breakout: [
            ["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],
            ["field", ORDERS.QUANTITY, null],
          ],
        },
        display: "pivot",
        visualization_settings: {
          "pivot_table.column_split": {
            // Unjustified type cast. FIXME
            rows: [ORDERS.CREATED_AT, ORDERS.QUANTITY] as any,
            columns: [],
            values: ["count"],
          },
          column_settings: {
            '["name","count"]': {
              column_title: "Price",
            },
          },
        },
      };

      H.createQuestionAndDashboard({
        questionDetails: pivotQuestionDetails,
        dashboardDetails: {
          name: "Pivot Dashboard Test",
          enable_embedding: true,
          embedding_params: {},
        },
      }).then(({ body: { dashboard_id } }) => {
        H.visitEmbeddedPage(
          {
            // Unjustified type cast. FIXME
            resource: { dashboard: dashboard_id as number },
            params: {},
          },
          {
            additionalHashOptions: {
              locale: "de",
            },
          },
        );

        cy.wait("@dashboard");

        H.getDashboardCard(0).within(() => {
          cy.findByText("Preis").should("exist");
        });
      });
    });
  });

  describe("filters and field values", () => {
    describe("ee", () => {
      before(() => {
        cy.intercept(
          "POST",
          "/api/ee/content-translation/upload-dictionary",
        ).as("uploadDictionary");

        H.restore();
        cy.signInAsAdmin();
        H.activateToken("pro-self-hosted");

        uploadTranslationDictionaryViaAPI([
          ...germanFieldNames,
          ...germanFieldValues,
          ...frenchNames,
          ...frenchBooleanTranslations,
        ]);
        H.snapshot("with-translations");
      });

      beforeEach(() => {
        cy.intercept("GET", "/api/embed/dashboard/*").as("dashboard");
        cy.intercept("GET", "/api/embed/dashboard/**/card/*").as("cardQuery");
        cy.intercept("GET", "/api/embed/dashboard/**/search/*").as(
          "searchQuery",
        );
        // Unjustified type cast. FIXME
        H.restore("with-translations" as any);
      });

      [{ isMultiSelect: true }, { isMultiSelect: false }].forEach(
        ({ isMultiSelect }) => {
          it(`can filter products table via localized, ${isMultiSelect ? "multiselect" : "single-select"} list widget and see localized values`, () => {
            const productCategoryFilter = {
              name: "Category",
              slug: "product_category",
              id: "11d79abe",
              type: "string/=",
              sectionId: "string",
              isMultiSelect,
            };
            cy.signInAsAdmin();
            H.createQuestionAndDashboard({
              questionDetails: {
                name: "Products question",
                query: {
                  "source-table": PRODUCTS_ID,
                  limit: 30,
                },
              },
              dashboardDetails: {
                parameters: [productCategoryFilter],
                enable_embedding: true,
                embedding_params: {
                  [productCategoryFilter.slug]: "enabled",
                },
              },
            }).then(({ body: { id, card_id, dashboard_id } }) => {
              cy.request("PUT", `/api/dashboard/${dashboard_id}`, {
                dashcards: [
                  {
                    id,
                    card_id,
                    row: 0,
                    col: 0,
                    size_x: 24,
                    size_y: 20,
                    parameter_mappings: [
                      {
                        parameter_id: productCategoryFilter.id,
                        card_id,
                        target: [
                          "dimension",
                          ["field", PRODUCTS.CATEGORY, null],
                        ],
                      },
                    ],
                  },
                ],
              });
              H.visitEmbeddedPage(
                {
                  // Unjustified type cast. FIXME
                  resource: { dashboard: dashboard_id as number },
                  params: {},
                },
                {
                  additionalHashOptions: {
                    locale: "de",
                  },
                },
              );
              cy.wait("@cardQuery");

              cy.log("Before filtering, multiple categories are shown");
              H.tableInteractiveBody().within(() => {
                cy.findAllByText(/Dingsbums/).should(
                  "have.length.greaterThan",
                  2,
                );
                cy.findAllByText(/Apparat/).should(
                  "have.length.greaterThan",
                  2,
                );
                cy.findAllByText(/Gerät/).should("have.length.greaterThan", 2);
                cy.findAllByText(/Steuerelement/).should(
                  "have.length.greaterThan",
                  2,
                );
              });

              cy.log("Non-categorical string values are translated");
              cy.findByText("Rustic Paper Wallet").should("not.exist");
              cy.findByText("Rustikale Papierbörse").should("be.visible");

              cy.log("After filtering, only selected categories are shown");
              H.filterWidget().findByText("Kategorie").click();
              H.popover().within(() => {
                cy.findByText(/Dingsbums/).click();
                if (isMultiSelect) {
                  cy.findByText(/Apparat/).click();
                }
                cy.findByText(/Füge einen Filter hinzu/).click();
              });
              H.tableInteractiveBody().within(() => {
                cy.findAllByText(/Dingsbums/).should(
                  "have.length.greaterThan",
                  2,
                );
                if (isMultiSelect) {
                  cy.findAllByText(/Apparat/).should(
                    "have.length.greaterThan",
                    2,
                  );
                } else {
                  cy.findByText(/Apparat/).should("not.exist");
                }
                cy.findByText(/Gerät/).should("not.exist");
                cy.findByText(/Steuerelement/).should("not.exist");
              });
            });
          });
        },
      );

      it("translates boolean content in filters and cards", () => {
        const booleanFilter = {
          name: "Boolean Filter",
          slug: "boolean_filter",
          id: "boolean-filter-id",
          type: "boolean/=",
          sectionId: "boolean",
          default: true,
        };

        cy.signInAsAdmin();
        H.createQuestionAndDashboard({
          questionDetails: {
            name: "Boolean Question",
            query: {
              "source-table": ACCOUNTS_ID,
              aggregation: [["count"]],
              breakout: [
                [
                  "field",
                  ACCOUNTS.TRIAL_CONVERTED,
                  {
                    "base-type": "type/Boolean",
                  },
                ],
                [
                  "field",
                  ACCOUNTS.ACTIVE_SUBSCRIPTION,
                  {
                    "base-type": "type/Boolean",
                  },
                ],
              ],
            },
          },
          dashboardDetails: {
            parameters: [booleanFilter],
            enable_embedding: true,
            embedding_params: {
              [booleanFilter.slug]: "enabled",
            },
          },
        }).then(({ body: { id, card_id, dashboard_id } }) => {
          cy.request("PUT", `/api/dashboard/${dashboard_id}`, {
            dashcards: [
              {
                id,
                card_id,
                row: 0,
                col: 0,
                size_x: 24,
                size_y: 20,
                parameter_mappings: [
                  {
                    card_id,
                    parameter_id: booleanFilter.id,
                    target: [
                      "dimension",
                      [
                        "field",
                        "ACTIVE_SUBSCRIPTION",
                        {
                          "base-type": "type/Boolean",
                        },
                      ],
                      {
                        "stage-number": 1,
                      },
                    ],
                  },
                ],
              },
            ],
          });
          H.visitEmbeddedPage(
            {
              // Unjustified type cast. FIXME
              resource: { dashboard: dashboard_id as number },
              params: {},
            },
            {
              additionalHashOptions: {
                locale: "fr",
              },
            },
          );
          cy.wait("@cardQuery");

          cy.findByTestId("table-body").within(() => {
            cy.findAllByText(/vrai/).should("have.length", 2);
            cy.findAllByText(/true/).should("have.length", 0);
          });
        });
      });

      it("translates MultiAutocomplete values and options", () => {
        const nameFilter = {
          name: "Multi",
          slug: "multi",
          id: "52b05b6d",
          type: "string/=",
          sectionId: "string",
        };

        cy.signInAsAdmin();
        H.createQuestionAndDashboard({
          questionDetails: {
            name: "People question",
            query: {
              "source-table": PEOPLE_ID,
              limit: 30,
              filter: [
                "contains",
                [
                  "field",
                  PEOPLE.NAME,
                  {
                    "base-type": "type/Text",
                  },
                ],
                "Fran",
                {
                  "case-sensitive": false,
                },
              ],
            },
          },
          dashboardDetails: {
            parameters: [nameFilter],
            enable_embedding: true,
            embedding_params: {
              [nameFilter.slug]: "enabled",
            },
          },
        }).then(({ body: { id, card_id, dashboard_id } }) => {
          cy.request("PUT", `/api/dashboard/${dashboard_id}`, {
            dashcards: [
              {
                id,
                card_id,
                row: 0,
                col: 0,
                size_x: 24,
                size_y: 20,
                parameter_mappings: [
                  {
                    parameter_id: nameFilter.id,
                    card_id,
                    target: ["dimension", ["field", PEOPLE.NAME, null]],
                  },
                ],
              },
            ],
          });
          H.visitEmbeddedPage(
            {
              // Unjustified type cast. FIXME
              resource: { dashboard: dashboard_id as number },
              params: {},
            },
            {
              additionalHashOptions: {
                locale: "fr",
              },
            },
          );
          cy.wait("@cardQuery");

          H.tableInteractiveBody().within(() => {
            // all rows should be visible initially
            cy.findAllByRole("row").should("have.length.greaterThan", 2);
            cy.findByText(/Glacia Froskeon/).should("exist");
            cy.findByText(/Hammera Francite/).should("exist");
            cy.findByText(/Francesca Gleason/).should("not.exist");
            cy.findByText(/Francesca Hammes/).should("not.exist");
          });

          H.filterWidget().findByText("Multi").click();
          // Search matches against untranslated text, hence "Fran" matching these names
          cy.findByPlaceholderText("Recherche dans la liste").type("Fran");
          cy.wait("@searchQuery");
          cy.findByTestId("parameter-value-dropdown").within(() => {
            cy.findByText(/Glacia Froskeon/).click();
            cy.button(/Ajouter un filtre/).click();
          });

          H.tableInteractiveBody().within(() => {
            // only the row matching the selection
            cy.findAllByRole("row").should("have.length", 1);
            cy.findByText(/Glacia Froskeon/).should("exist");
            cy.findByText(/Hammera Francite/).should("not.exist");
            cy.findByText(/Francesca Gleason/).should("not.exist");
            cy.findByText(/Francesca Hammes/).should("not.exist");
          });

          cy.findByTestId("parameter-widget").click();
          // Search matches against untranslated text, hence "Fran" matching these names
          cy.findByPlaceholderText("Recherche dans la liste").type("Fran");
          cy.findByText(/Hammera Francite/).click();
          cy.realPress("Escape");
          cy.findByTestId("parameter-value-dropdown")
            .button(/Mettre à jour le filtre/)
            .click();

          H.tableInteractiveBody().within(() => {
            // only the two rows matching the selection
            cy.findAllByRole("row").should("have.length", 2);
            cy.findByText(/Glacia Froskeon/).should("exist");
            cy.findByText(/Hammera Francite/).should("exist");
            cy.findByText(/Francesca Gleason/).should("not.exist");
            cy.findByText(/Francesca Hammes/).should("not.exist");
          });
        });
      });

      it("translates selected static-list filter label in guest embed", () => {
        const staticListFilter = {
          name: "Number",
          slug: "number",
          id: "static-list-id",
          type: "number/=",
          sectionId: "number",
          values_source_type: "static-list" as const,
          values_source_config: {
            values: [
              ["1", "Gadget"],
              ["2", "Widget"],
            ],
          },
        };

        cy.signInAsAdmin();
        H.createQuestionAndDashboard({
          questionDetails: {
            name: "Expression Question",
            query: {
              "source-table": PEOPLE_ID,
            },
          },
          dashboardDetails: {
            // Unjustified type cast. FIXME
            parameters: [staticListFilter as any], // current API isn't set to accept string[][] as values
            enable_embedding: true,
            embedding_params: {
              [staticListFilter.slug]: "enabled",
            },
          },
        }).then(({ body: { id, card_id, dashboard_id } }) => {
          // Map the parameter to an expression column so the filter widget
          // is visible, but hasFields() returns false (testing the tc()
          // fix in FormattedParameterValue)
          cy.request("PUT", `/api/dashboard/${dashboard_id}`, {
            dashcards: [
              {
                id,
                card_id,
                row: 0,
                col: 0,
                size_x: 24,
                size_y: 9,
                parameter_mappings: [
                  {
                    parameter_id: staticListFilter.id,
                    card_id,
                    target: [
                      "dimension",
                      ["expression", "Thing", { "base-type": "type/Integer" }],
                      { "stage-number": 0 },
                    ],
                  },
                ],
              },
            ],
          });

          H.visitEmbeddedPage(
            {
              // Unjustified type cast. FIXME
              resource: { dashboard: dashboard_id as number },
              params: {},
            },
            {
              setFilters: { [staticListFilter.slug]: "1" },
              additionalHashOptions: {
                locale: "de",
              },
            },
          );

          H.filterWidget().findByText("Gerät").should("be.visible");
        });
      });

      it("translates selected static-list filter label in guest embed for values without labels", () => {
        const staticListFilter = {
          name: "String",
          slug: "string",
          id: "static-list-id",
          type: "string/=",
          sectionId: "string",
          values_source_type: "static-list" as const,
          values_source_config: {
            values: [["Gadget"], ["Widget"]],
          },
        };

        cy.signInAsAdmin();
        H.createQuestionAndDashboard({
          questionDetails: {
            name: "Expression Question",
            query: {
              "source-table": PEOPLE_ID,
            },
          },
          dashboardDetails: {
            // Unjustified type cast. FIXME
            parameters: [staticListFilter as any], // current API isn't set to accept string[][] as values
            enable_embedding: true,
            embedding_params: {
              [staticListFilter.slug]: "enabled",
            },
          },
        }).then(({ body: { id, card_id, dashboard_id } }) => {
          // Map the parameter to an expression column so the filter widget
          // is visible, but hasFields() returns false (testing the tc()
          // fix in FormattedParameterValue)
          cy.request("PUT", `/api/dashboard/${dashboard_id}`, {
            dashcards: [
              {
                id,
                card_id,
                row: 0,
                col: 0,
                size_x: 24,
                size_y: 9,
                parameter_mappings: [
                  {
                    parameter_id: staticListFilter.id,
                    card_id,
                    target: [
                      "dimension",
                      ["expression", "Thing", { "base-type": "type/Integer" }],
                      { "stage-number": 0 },
                    ],
                  },
                ],
              },
            ],
          });

          H.visitEmbeddedPage(
            {
              // Unjustified type cast. FIXME
              resource: { dashboard: dashboard_id as number },
              params: {},
            },
            {
              setFilters: { [staticListFilter.slug]: "Gadget" },
              additionalHashOptions: {
                locale: "de",
              },
            },
          );

          H.filterWidget().findByText("Gerät").should("be.visible");
        });
      });
    });
  });

  describe("tab names and text cards", () => {
    const translations: DictionaryArray = [
      { locale: "de", msgid: "Tab 1", msgstr: "Reiter 1" },
      { locale: "de", msgid: "Tab 2", msgstr: "Reiter 2" },
      { locale: "de", msgid: "Sample Heading", msgstr: "Beispielüberschrift" },
      { locale: "de", msgid: "Sample Text", msgstr: "Beispieltext" },
    ];
    type VisitWithLocale = (options?: { locale?: string }) => void;
    // Unjustified type cast. FIXME
    let visitEmbeddedDashboard = null as unknown as VisitWithLocale,
      // Unjustified type cast. FIXME
      visitNormalDashboard = null as unknown as VisitWithLocale;

    before(() => {
      H.restore();
      cy.signInAsAdmin();
      H.activateToken("pro-self-hosted");
      uploadTranslationDictionaryViaAPI(translations);
      cy.request("PUT", `/api/dashboard/${ORDERS_DASHBOARD_ID}`, {
        enable_embedding: true,
        tabs: [
          H.getDashboardTabDetails({
            name: "Tab 1",
            id: 100,
          }),
          H.getDashboardTabDetails({
            name: "Tab 2",
            id: 101,
          }),
        ],
        dashcards: [
          H.getHeadingCardDetails({
            col: 0,
            text: "Sample Heading",
            dashboard_tab_id: 100,
          }),
          H.getTextCardDetails({
            col: 0,
            text: "Sample Text",
            dashboard_tab_id: 100,
          }),
        ],
      } satisfies DashboardDetails);
      H.snapshot("tab-names-and-text-cards");
    });

    beforeEach(() => {
      cy.intercept("POST", "api/ee/content-translation/upload-dictionary").as(
        "uploadDictionary",
      );
      // Unjustified type cast. FIXME
      H.restore("tab-names-and-text-cards" as any);
      cy.signInAsAdmin();
      visitEmbeddedDashboard = ({ locale = "de" } = {}) => {
        H.visitEmbeddedPage(
          {
            resource: { dashboard: ORDERS_DASHBOARD_ID },
            params: {},
          },
          {
            additionalHashOptions: {
              locale,
            },
          },
        );
      };
      visitNormalDashboard = ({ locale = "de" } = {}) => {
        cy.request("PUT", `/api/user/${NORMAL_USER_ID}`, { locale });
        cy.signInAsNormalUser();
        H.visitDashboard(ORDERS_DASHBOARD_ID);
      };
    });

    it("should translate dashboard tab names, heading cards and text cards", () => {
      visitEmbeddedDashboard();

      cy.log("tab names");
      cy.findByRole("tab", { name: "Reiter 1" }).should("be.visible");
      cy.findByRole("tab", { name: "Reiter 2" }).should("be.visible");

      cy.log("heading cards");
      H.getDashboardCard(0)
        .findByText(/Beispielüberschrift/)
        .should("be.visible");

      cy.log("text cards");
      H.getDashboardCard(1)
        .findByText(/Beispieltext/)
        .should("be.visible");
    });

    it("translations of tab names and text cards do not break normal dashboard", () => {
      visitNormalDashboard();
      cy.findByRole("tab", { name: "Tab 1" }).should("be.visible");
      cy.findByRole("tab", { name: "Tab 2" }).should("be.visible");
      cy.findAllByTestId("dashcard")
        .contains(/Sample Heading/)
        .should("be.visible");
      cy.findAllByTestId("dashcard")
        .contains(/Sample Text/)
        .should("be.visible");
    });
  });

  describe("funnel chart with translated dimension values (metabase#71488)", () => {
    beforeEach(() => {
      H.restore();
      cy.signInAsAdmin();
      H.activateToken("pro-self-hosted");

      uploadTranslationDictionaryViaAPI([
        { locale: "fr", msgid: "Gadget", msgstr: "Le gadget" },
        { locale: "fr", msgid: "Doohickey", msgstr: "Le doohickey" },
        { locale: "fr", msgid: "Gizmo", msgstr: "Le gizmo" },
        { locale: "fr", msgid: "Widget", msgstr: "Le widget" },
      ]);

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

      cy.signInAsAdmin();
    });

    it("should render funnel with translated dimension labels in a static embed", () => {
      H.createQuestion({
        name: "Products Funnel",
        display: "funnel",
        query: {
          "source-table": PRODUCTS_ID,
          aggregation: [["count"]],
          breakout: [["field", PRODUCTS.CATEGORY, null]],
        },
        visualization_settings: {
          "funnel.metric": "count",
          "funnel.dimension": "CATEGORY",
        },
      }).then(({ body: card }) => {
        H.createDashboard({
          name: "funnel_dashboard",
        }).then(({ body: { id: dashboardId } }) => {
          // Add the funnel card to the dashboard
          H.addOrUpdateDashboardCard({
            dashboard_id: dashboardId,
            card_id: card.id,
            card: { size_x: 16, size_y: 8 },
          });
          H.visitDashboard(dashboardId);
          H.openLegacyStaticEmbeddingModal({
            resource: "dashboard",
            resourceId: dashboardId,
          });
          H.publishChanges("dashboard", () => {});
          H.visitEmbeddedPage(
            {
              // Unjustified type cast. FIXME
              resource: { dashboard: dashboardId as number },
              params: {},
            },
            {
              additionalHashOptions: {
                locale: "fr",
              },
            },
          );
          // The funnel should render without crashing
          cy.findByTestId("funnel-chart", { timeout: 10_000 }).should("exist");
          // Dimension labels should be translated
          cy.findAllByTestId("funnel-chart-header").should("have.length", 4);
          cy.findByTestId("funnel-chart").within(() => {
            cy.findByText("Le gadget").should("exist");
            cy.findByText("Le doohickey").should("exist");
            cy.findByText("Le gizmo").should("exist");
            cy.findByText("Le widget").should("exist");
          });
        });
      });
    });
  });
});