Pages list and Tiptap editor (ported from babyboo) with image upload on save, the FORM event picker, field errors at their fields, delete confirmation, unsaved-edits guard and a draft preview. The public page /p/<company>/<slug> renders on the server with metadata, sanitize-html, the company's logo and accent, and the sign-up form with UTM tags. Companies get branding; the event lead detail shows the web page and campaign. Labels in English and Chinese. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
33 lines
1.5 KiB
TypeScript
33 lines
1.5 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { contrastText, emptyPage, isSafeLink, pageBody, slugify, withTitle } from "./cmsPages";
|
|
|
|
describe("cmsPages helpers", () => {
|
|
it("slug follows the title until edited", () => {
|
|
const d = withTitle(emptyPage(), "Hotel Technology Day 2027!");
|
|
expect(d.slug).toBe("hotel-technology-day-2027");
|
|
expect(withTitle({ ...d, slug: "mine", slugTouched: true }, "Other").slug).toBe("mine");
|
|
expect(slugify(" ")).toBe("");
|
|
});
|
|
|
|
it("save body trims and drops blank optional fields", () => {
|
|
const body = pageBody({
|
|
...emptyPage(), title: " T ", slug: "t", metaDescription: " ",
|
|
blocks: [{ type: "HERO", heading: " Hi ", text: "", imageId: null }, { type: "FAQ", items: [{ question: " Q ", answer: " A " }] }],
|
|
});
|
|
expect(body.title).toBe("T");
|
|
expect(body.metaDescription).toBeNull();
|
|
expect(body.blocks).toEqual([{ type: "HERO", heading: "Hi" }, { type: "FAQ", items: [{ question: "Q", answer: "A" }] }]);
|
|
});
|
|
|
|
it("picks the more readable text colour", () => {
|
|
expect(contrastText("#FFEE00")).toBe("#000000");
|
|
expect(contrastText("#1A237E")).toBe("#FFFFFF");
|
|
expect(contrastText("bad")).toBe("#FFFFFF");
|
|
});
|
|
|
|
it("allows only safe button links", () => {
|
|
for (const ok of ["/p/INS/a", "https://x.com", "mailto:a@b.c", "tel:+60123"]) expect(isSafeLink(ok), ok).toBe(true);
|
|
for (const bad of ["//evil.com", "javascript:alert(1)", "http://x.com", "https://a b", "/\\evil", undefined]) expect(isSafeLink(bad), String(bad)).toBe(false);
|
|
});
|
|
});
|