Track HiveGrid Cloud planning reference
This commit is contained in:
1 parent
b3d5ea6764
commit
e341c5938a
5784 files changed
+1104929
-3
No files matched your search
+92
@@ -0,0 +1,92 @@
|
||||
import fs from "node:fs";
|
||||
import path from "node:path";
|
||||
import type { TFunction } from "i18next";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { getDateAsString } from "./cells/RowDateCell";
|
||||
import { getNumberAsStringValue } from "./cells/RowNumberCell";
|
||||
import { getBooleanAsStringValue } from "./cells/RowBooleanCell";
|
||||
import { createLocaleFormatters } from "~/locale/format";
|
||||
import { PropertyType } from "~/application/enums/entities/PropertyType";
|
||||
import RowHelper from "~/utils/helpers/RowHelper";
|
||||
|
||||
const cellsRoot = path.resolve(process.cwd(), "apps/web/app/components/entities/rows/cells");
|
||||
|
||||
function readCell(relativePath: string) {
|
||||
return fs.readFileSync(path.join(cellsRoot, relativePath), "utf8");
|
||||
}
|
||||
|
||||
describe("row cell formatting i18n", () => {
|
||||
it("keeps visible date, number, and folio formatting on locale formatters", () => {
|
||||
const numberSource = readCell("RowNumberCell.tsx");
|
||||
const sources = [readCell("RowDateCell.tsx"), numberSource, readCell("RowFolioCell.tsx")].join("\n");
|
||||
|
||||
expect(sources).toContain("~/locale/format");
|
||||
expect(sources).toContain("useLocaleFormatters");
|
||||
expect(sources).toContain("formatters.date");
|
||||
expect(sources).toContain("formatters.number");
|
||||
expect(sources).toContain("formatters.currency");
|
||||
expect(sources).toContain("formatters.percent");
|
||||
expect(sources).toContain("formatters.relativeDate");
|
||||
expect(numberSource).not.toContain("value.toString()");
|
||||
expect(sources).not.toContain("DateUtils");
|
||||
expect(sources).not.toContain("NumberUtils");
|
||||
expect(sources).not.toContain("Intl");
|
||||
expect(sources).not.toContain("toLocaleString");
|
||||
expect(sources).not.toContain("ui.autogenerated");
|
||||
});
|
||||
|
||||
it("formats default row numbers through locale formatters", () => {
|
||||
expect(getNumberAsStringValue({ value: 1234567.89, formatters: createLocaleFormatters("en") })).toBe("1,234,567.89");
|
||||
expect(getNumberAsStringValue({ value: 1234567.89, formatters: createLocaleFormatters("de") })).toBe("1.234.567,89");
|
||||
});
|
||||
|
||||
it("keeps explicit row date patterns stable", () => {
|
||||
const value = new Date("2026-05-26T10:20:30.000Z");
|
||||
|
||||
expect(getDateAsString({ value, format: "YYYY-MM-DD" })).toBe("2026-05-26");
|
||||
expect(getDateAsString({ value, format: "DD-MM-YYYY" })).toBe("26-05-2026");
|
||||
expect(getDateAsString({ value, format: "MM-DD-YYYY" })).toBe("05-26-2026");
|
||||
});
|
||||
|
||||
it("formats boolean labels through shared translation keys", () => {
|
||||
const keys: string[] = [];
|
||||
const t = ((key: string) => {
|
||||
keys.push(key);
|
||||
return `translated:${key}`;
|
||||
}) as TFunction;
|
||||
|
||||
expect(getBooleanAsStringValue({ value: true, format: "yesNo", t })).toBe("translated:shared.yes");
|
||||
expect(getBooleanAsStringValue({ value: false, format: "yesNo", t })).toBe("translated:shared.no");
|
||||
expect(getBooleanAsStringValue({ value: true, format: "trueFalse", t })).toBe("translated:shared.true");
|
||||
expect(getBooleanAsStringValue({ value: false, format: "trueFalse", t })).toBe("translated:shared.false");
|
||||
expect(getBooleanAsStringValue({ value: true, format: "enabledDisabled", t })).toBe("translated:shared.enabled");
|
||||
expect(getBooleanAsStringValue({ value: false, format: "enabledDisabled", t })).toBe("translated:shared.disabled");
|
||||
expect(getBooleanAsStringValue({ value: true, format: "onOff", t })).toBe("translated:shared.on");
|
||||
expect(getBooleanAsStringValue({ value: false, format: "onOff", t })).toBe("translated:shared.off");
|
||||
expect(getBooleanAsStringValue({ value: true, format: "activeInactive", t })).toBe("translated:shared.active");
|
||||
expect(getBooleanAsStringValue({ value: false, format: "activeInactive", t })).toBe("translated:shared.inactive");
|
||||
expect(keys).toEqual([
|
||||
"shared.yes",
|
||||
"shared.no",
|
||||
"shared.true",
|
||||
"shared.false",
|
||||
"shared.enabled",
|
||||
"shared.disabled",
|
||||
"shared.on",
|
||||
"shared.off",
|
||||
"shared.active",
|
||||
"shared.inactive",
|
||||
]);
|
||||
});
|
||||
|
||||
it("keeps RowHelper fallback values on translation keys", () => {
|
||||
const t = ((key: string) => `translated:${key}`) as TFunction;
|
||||
const source = fs.readFileSync(path.resolve(process.cwd(), "apps/web/app/utils/helpers/RowHelper.tsx"), "utf8");
|
||||
|
||||
expect(RowHelper.getFormattedValue(true, PropertyType.BOOLEAN, t)).toBe("translated:shared.yes");
|
||||
expect(RowHelper.getFormattedValue(false, PropertyType.BOOLEAN, t)).toBe("translated:shared.no");
|
||||
expect(RowHelper.getFormattedValue("value", "unsupported" as PropertyType, t)).toBe("translated:models.row.values.notSupported");
|
||||
expect(source).not.toContain('return "Not supported"');
|
||||
expect(source).not.toContain('return value ? "t" : "f"');
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user