feat: 增加可视化模板页面编辑器
This commit is contained in:
1 parent
9d2038cc93
commit
c5af790554
24 files changed
+773
-129
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import assert from "node:assert/strict";
|
||||
import {
|
||||
applyPresentationValues,
|
||||
filterSectionsForPreviewTarget,
|
||||
presentationFieldName,
|
||||
readPresentationValue,
|
||||
} from "../src/features/brand/presentation-bindings.ts";
|
||||
@@ -37,6 +38,21 @@ assert.equal(next.visualPresentation.inquiry.subtitle, "原说明");
|
||||
assert.equal(next.unrelatedSetting, true);
|
||||
assert.equal(config.founder, "阿成");
|
||||
|
||||
const previewSections = [
|
||||
{
|
||||
key: "home",
|
||||
fields: [
|
||||
{ key: "location", previewTarget: "home.location" },
|
||||
{ key: "hero", previewTarget: "home.hero" },
|
||||
],
|
||||
},
|
||||
{ key: "profile", fields: [{ key: "bio", previewTarget: "profile.bio" }] },
|
||||
];
|
||||
assert.deepEqual(filterSectionsForPreviewTarget(previewSections, "home.hero"), [
|
||||
{ key: "home", fields: [{ key: "hero", previewTarget: "home.hero" }] },
|
||||
]);
|
||||
assert.equal(filterSectionsForPreviewTarget(previewSections).length, 2);
|
||||
|
||||
const unsafe = applyPresentationValues(
|
||||
{ founder: "原主理人" },
|
||||
[
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
import { templatePreviewUrl } from "../src/lib/template-preview.ts";
|
||||
|
||||
test("template preview URL is resolved from generic deployment configuration", () => {
|
||||
const url = templatePreviewUrl(
|
||||
"new-template",
|
||||
"brand-a",
|
||||
"profile",
|
||||
JSON.stringify({ "new-template": "https://preview.example.test/app/" }),
|
||||
"https://admin.example.test",
|
||||
"/pages/profile/index",
|
||||
);
|
||||
assert.equal(
|
||||
url,
|
||||
"https://preview.example.test/app/?editor=1&parentOrigin=https%3A%2F%2Fadmin.example.test&brand=brand-a#/pages/profile/index",
|
||||
);
|
||||
});
|
||||
|
||||
test("missing, malformed or invalid template preview configuration fails closed", () => {
|
||||
assert.equal(templatePreviewUrl("missing", "brand-a", "home", undefined), undefined);
|
||||
assert.equal(templatePreviewUrl("missing", "brand-a", "home", "{"), undefined);
|
||||
assert.equal(
|
||||
templatePreviewUrl("broken", "brand-a", "home", JSON.stringify({ broken: "not a URL" })),
|
||||
undefined,
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user