45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
import { test } from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { missingField, visibleFields, slot, offering } from "../src/runtime/content.ts";
|
|
test("条件字段与空数组校验使用实际显示字段", () => {
|
|
const fields = [
|
|
{ key: "type", type: "select", label: "类型", required: true },
|
|
{
|
|
key: "choices",
|
|
type: "checkbox",
|
|
label: "选项",
|
|
required: true,
|
|
visibleWhen: [{ field: "type", operator: "equals", value: "group" }],
|
|
},
|
|
];
|
|
assert.equal(visibleFields(fields, { type: "daily" }).length, 1);
|
|
assert.equal(missingField(fields, { type: "group", choices: [] }).key, "choices");
|
|
assert.equal(missingField(fields, { type: "group", choices: ["a"] }), undefined);
|
|
});
|
|
test("结构化来源优先,详情使用公开投影", () => {
|
|
const item = slot(
|
|
{
|
|
trustItems: [
|
|
{ type: "credential", config: {}, content: "old" },
|
|
{ type: "credential", config: { standards: [] }, content: "edited" },
|
|
],
|
|
},
|
|
"credential",
|
|
);
|
|
assert.equal(item.content, "edited");
|
|
const data = offering({
|
|
id: "a",
|
|
summary: "摘要",
|
|
coverUrl: "cover",
|
|
priceText: "报价",
|
|
presentation: {
|
|
categoryLabel: "套餐",
|
|
heroImage: "hero",
|
|
keywords: [],
|
|
details: { background: "实际餐品说明" },
|
|
},
|
|
});
|
|
assert.equal(data.image, "hero");
|
|
assert.equal(data.details.background, "实际餐品说明");
|
|
});
|