42 lines
1.4 KiB
JavaScript
42 lines
1.4 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { DESIGN_SPEC_VERSION, validateDesignSpec } from "../src/index.ts";
|
|
import { renderDesignSpec } from "../src/render.ts";
|
|
|
|
const validSpec = {
|
|
version: DESIGN_SPEC_VERSION,
|
|
templateKey: "acheng-campus-food",
|
|
displayName: "阿成校园餐",
|
|
tone: "干净、亲切、可信",
|
|
theme: {
|
|
primaryColor: "#f2683c",
|
|
backgroundColor: "#f7f7f4",
|
|
surfaceColor: "#ffffff",
|
|
textColor: "#1f2328",
|
|
mutedTextColor: "#6b7280",
|
|
borderRadius: 16,
|
|
},
|
|
sections: [
|
|
{ type: "hero", title: "每天现做的校园餐", content: ["周三到周日供应"], action: "查看菜单" },
|
|
{ type: "services", title: "供应方式", content: ["单餐预订", "周餐预订"] },
|
|
{ type: "contact", title: "联系阿成", content: ["微信预约"] },
|
|
],
|
|
};
|
|
|
|
test("accepts a valid DesignSpec", () => {
|
|
assert.deepEqual(validateDesignSpec(validSpec), []);
|
|
});
|
|
|
|
test("requires a contact section", () => {
|
|
const errors = validateDesignSpec({ ...validSpec, sections: validSpec.sections.slice(0, 2) });
|
|
assert.equal(errors.includes("sections must include a contact section"), true);
|
|
});
|
|
|
|
test("renders machine-readable HTML", () => {
|
|
const html = renderDesignSpec(validSpec);
|
|
assert.match(html, /data-template-section="hero"/);
|
|
assert.match(html, /data-field="displayName"/);
|
|
assert.match(html, /data-action="hero"/);
|
|
});
|