test: add unit tests for pure logic modules

Add 22 test files covering imager, soundtracks, browser-headers, source-keys (figure/pet/effect), effect-source, plus catalog-translations, catalog-layouts, client-translation-files, translations-utils, and various admin/services/helpers modules. Total test count increases by 120+.
This commit is contained in:
openhands committed 2026-08-07 18:53:59 +02:00
1 parent 11e8b06bf8
commit 82e8448f26
25 files changed
+1400 -304

No files matched your search

+45
View File
@@ -0,0 +1,45 @@
import { describe, expect, it } from "vitest";
import { flattenObject, unflattenObject } from "./translations-utils";
describe("flattenObject", () => {
it("flattens nested objects into dotted keys", () => {
const flat = flattenObject({ a: { b: { c: "x" } }, d: "y" });
expect(flat).toEqual({ "a.b.c": "x", d: "y" });
});
it("stringifies non-object values", () => {
expect(flattenObject({ n: 5, b: true, nil: null })).toEqual({
n: "5",
b: "true",
nil: "",
});
});
it("keeps arrays as-is via String()", () => {
expect(flattenObject({ list: ["a", "b"] })).toEqual({ list: "a,b" });
});
it("honours an explicit prefix", () => {
expect(flattenObject({ a: 1 }, "root")).toEqual({ "root.a": "1" });
});
});
describe("unflattenObject", () => {
it("rebuilds nested objects from dotted keys", () => {
expect(unflattenObject({ "a.b.c": "x", d: "y" })).toEqual({
a: { b: { c: "x" } },
d: "y",
});
});
it("creates intermediate objects as needed", () => {
expect(unflattenObject({ "x.y": "1", "x.z": "2" })).toEqual({
x: { y: "1", z: "2" },
});
});
it("round-trips with flattenObject", () => {
const original = { menu: { home: "Home", items: { a: "A" } }, footer: "F" };
expect(unflattenObject(flattenObject(original))).toEqual(original);
});
});