This commit is contained in:
Your Name committed 2026-10-01 15:42:52 +07:00
1 parent 2d39edbd57
commit 78b722e120
24 files changed
+2130 -65

No files matched your search

@@ -2,8 +2,68 @@ import { describe, expect, test } from "bun:test";
import {
mergeSectionTranslations,
transformLocalizedPaths,
validateSectionPayload,
} from "./pages";
describe("Page section payload validation", () => {
test("accepts a DIVIDER payload", () => {
const result = validateSectionPayload("DIVIDER", {
width: "narrow",
style: "dotted",
thickness: 2,
spacing: "xl",
});
expect(result.success).toBe(true);
});
test.each(["#123", "#AbC8", "#12aBcD", "#12aBcD80"])(
"accepts DIVIDER color %s",
(color) => {
const result = validateSectionPayload("DIVIDER", {
width: "container",
style: "solid",
thickness: 1,
spacing: "md",
color,
});
expect(result.success).toBe(true);
},
);
test.each(["red", "#12", "#12345", "#123456789", "#fff; background: url(javascript:alert(1))"])(
"rejects unsafe DIVIDER color %s",
(color) => {
const result = validateSectionPayload("DIVIDER", {
width: "container",
style: "solid",
thickness: 1,
spacing: "md",
color,
});
expect(result.success).toBe(false);
expect(result.issues?.[0]?.path).toEqual(["color"]);
expect(result.issues?.[0]?.message).toBe(
"Color must be a hex value in #RGB, #RGBA, #RRGGBB, or #RRGGBBAA format",
);
},
);
test("rejects an unsupported DIVIDER width", () => {
const result = validateSectionPayload("DIVIDER", {
width: "wide",
style: "solid",
thickness: 1,
spacing: "sm",
});
expect(result.success).toBe(false);
expect(result.issues?.[0]?.path).toEqual(["width"]);
});
});
describe("Page section localization", () => {
const paths = ["title", "items[].title", "items[].note"];
const payload = {