Skip to content

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

Cover pivot subtotal date localization with a Jest test (#82947)

Nemanja Glumac57a08becb38c
diff --git a/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js b/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js
index a0295b6f487..88c2856f465 100644
--- a/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js
+++ b/e2e/test/scenarios/visualizations-tabular/visualizations-tabular-reproductions.cy.spec.js
@@ -3,7 +3,6 @@ import { chunk } from "underscore";
import { SAMPLE_DB_ID } from "e2e/support/cypress_data";
import { SAMPLE_DATABASE } from "e2e/support/cypress_sample_database";
-import { ADMIN_USER_ID } from "e2e/support/cypress_sample_instance_data";
const { ORDERS, ORDERS_ID, PEOPLE, PEOPLE_ID, PRODUCTS, PRODUCTS_ID } =
SAMPLE_DATABASE;
@@ -267,49 +266,6 @@ describe("#22206 adding and removing columns doesn't duplicate columns", () => {
});
});
-describe("issue 23076", () => {
- const questionDetails = {
- name: "Orders, Distinct values of ID, Grouped by Product → Title and Created At (month) and User → ID",
-
- query: {
- "source-table": ORDERS_ID,
- aggregation: [["distinct", ["field", ORDERS.ID, null]]],
- breakout: [
- ["field", PRODUCTS.TITLE, { "source-field": ORDERS.PRODUCT_ID }],
- ["field", ORDERS.CREATED_AT, { "temporal-unit": "month" }],
- ["field", PEOPLE.ID, { "source-field": ORDERS.USER_ID }],
- ],
- },
- display: "pivot",
- visualization_settings: {
- "pivot_table.column_split": {
- rows: ["TITLE", "CREATED_AT", "ID"],
- columns: [],
- values: ["distinct"],
- },
- },
- };
-
- beforeEach(() => {
- H.restore();
- cy.signInAsAdmin();
-
- cy.request("PUT", `/api/user/${ADMIN_USER_ID}`, {
- locale: "en-ZZ",
- });
-
- H.createQuestion(questionDetails, { visitQuestion: true });
- });
-
- it("should correctly translate dates (metabase#23076)", () => {
- cy.findAllByText(/^\[zz\] Totals for/)
- .should("be.visible")
- .eq(1)
- .invoke("text")
- .should("eq", "[zz] Totals for May 2026");
- });
-});
-
describe("issue 28304", () => {
const questionDetails = {
name: "28304",
diff --git a/frontend/src/metabase/visualizations/lib/data_grid.unit.spec.ts b/frontend/src/metabase/visualizations/lib/data_grid.unit.spec.ts
index 757f5c97a8e..6610f74c737 100644
--- a/frontend/src/metabase/visualizations/lib/data_grid.unit.spec.ts
+++ b/frontend/src/metabase/visualizations/lib/data_grid.unit.spec.ts
@@ -1,5 +1,9 @@
import _ from "underscore";
+import {
+ type LocaleDataWithLanguage,
+ setLocalization,
+} from "metabase/utils/i18n";
import { checkNotNull } from "metabase/utils/types";
import {
COLLAPSED_ROWS_SETTING,
@@ -873,5 +877,66 @@ describe("data_grid", () => {
),
).toEqual(lastColumn);
});
+
+ describe("localized subtotals", () => {
+ const GERMAN: LocaleDataWithLanguage = {
+ headers: {
+ language: "de",
+ "plural-forms": "nplurals=2; plural=(n != 1);",
+ },
+ translations: {
+ "": { "Totals for ${ 0 }": { msgstr: ["Summen für ${ 0 }"] } },
+ },
+ };
+
+ const ENGLISH: LocaleDataWithLanguage = {
+ headers: {
+ language: "en",
+ "plural-forms": "nplurals=2; plural=(n != 1);",
+ },
+ translations: { "": {} },
+ };
+
+ const CREATED_AT = createMockColumn({
+ name: "CREATED_AT",
+ display_name: "Created At",
+ base_type: TYPE.DateTime,
+ effective_type: TYPE.DateTime,
+ unit: "month",
+ source: "breakout",
+ });
+
+ const data = makePivotData(
+ [
+ ["2026-05-01T00:00:00Z", "a", 1],
+ ["2026-05-01T00:00:00Z", "b", 2],
+ ],
+ [CREATED_AT, D1, M],
+ );
+
+ afterEach(() => {
+ setLocalization(ENGLISH);
+ });
+
+ it("formats a date breakout once, in the active locale (metabase#23076)", () => {
+ setLocalization(GERMAN);
+
+ const { leftHeaderItems } = multiLevelPivotForIndexes(
+ data,
+ [],
+ [0, 1],
+ [2],
+ );
+
+ // Formatting the subtotal value a second time would re-parse the
+ // localized "Mai 2026" and mangle the month.
+ expect(getValues(leftHeaderItems)).toEqual([
+ "Mai 2026",
+ "a",
+ "b",
+ "Summen für Mai 2026",
+ ]);
+ });
+ });
});
});