fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
@@ -4,6 +4,7 @@ import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import test from "node:test";
|
||||
import { validateTemplatePackageManifest } from "../src/index.ts";
|
||||
import { runtimeContractForBinding } from "../../types/src/runtime-content-contract.ts";
|
||||
|
||||
const packageRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
|
||||
@@ -26,6 +27,61 @@ test("template contract rejects technical or incomplete admin declarations", ()
|
||||
]);
|
||||
});
|
||||
|
||||
test("template admin sections must point to a declared Mini Program page", () => {
|
||||
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.admin.sections[0].page = "missing-page";
|
||||
assert.deepEqual(validateTemplatePackageManifest(manifest), [
|
||||
"admin section identity must target a declared entrypoint",
|
||||
]);
|
||||
});
|
||||
|
||||
test("template trust content pages must point to declared Mini Program pages", () => {
|
||||
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.trustContentTypes[0].pages = ["missing-page"];
|
||||
assert.deepEqual(validateTemplatePackageManifest(manifest), [
|
||||
"trustContentTypes.0.pages contains an undeclared entrypoint",
|
||||
]);
|
||||
});
|
||||
|
||||
test("template trust editor fields map to persisted TrustContent columns", () => {
|
||||
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.trustContentTypes[0].adminFields.summary = "";
|
||||
assert.ok(
|
||||
validateTemplatePackageManifest(manifest).includes(
|
||||
"trustContentTypes.0.adminFields.summary is required",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("template samples cannot import trust types without an Admin declaration", () => {
|
||||
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.sampleContent.food.trustContent.push({
|
||||
type: "not-declared",
|
||||
title: "未知",
|
||||
content: "未知",
|
||||
});
|
||||
assert.ok(
|
||||
validateTemplatePackageManifest(manifest).includes(
|
||||
`sampleContent.food.trustContent.${manifest.sampleContent.food.trustContent.length - 1} uses an undeclared trust content type`,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("template sample inquiry fields use Runtime-supported input types", () => {
|
||||
const manifestPath = path.join(packageRoot, "template-acheng-campus-food/template.json");
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
manifest.sampleContent.food.fields[0].type = "image";
|
||||
assert.ok(
|
||||
validateTemplatePackageManifest(manifest).includes(
|
||||
"sampleContent.food.fields.0 has an unsupported Runtime type",
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
test("template manifests declare editable material content", () => {
|
||||
const linjing = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, "template-linjing-editorial/template.json"), "utf8"),
|
||||
@@ -47,7 +103,6 @@ test("template manifests declare editable material content", () => {
|
||||
])
|
||||
assert.ok(bindings(linjing).has(binding), binding);
|
||||
for (const binding of [
|
||||
"brand.config.visualPresentation.profile.coverageContent",
|
||||
"brand.config.visualPresentation.offerings.menuTip",
|
||||
"brand.config.visualPresentation.inquiry.promise",
|
||||
])
|
||||
@@ -59,3 +114,135 @@ test("template manifests declare editable material content", () => {
|
||||
["stats", "pillars", "serviceFlow"],
|
||||
);
|
||||
});
|
||||
|
||||
test("template fields use the shallow templateData namespace", () => {
|
||||
for (const key of ["acheng-campus-food", "linjing-editorial"]) {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, `template-${key}/template.json`), "utf8"),
|
||||
);
|
||||
for (const field of manifest.templateFields ?? []) {
|
||||
assert.equal(typeof field.key, "string");
|
||||
assert.ok(!field.key.includes("."), `${key}: template field keys stay shallow`);
|
||||
assert.ok(
|
||||
[
|
||||
"text",
|
||||
"textarea",
|
||||
"number",
|
||||
"boolean",
|
||||
"image",
|
||||
"select",
|
||||
"multi-select",
|
||||
"list",
|
||||
].includes(field.input),
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("every declared Admin binding has one Runtime contract", () => {
|
||||
for (const key of ["acheng-campus-food", "linjing-editorial"]) {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, `template-${key}/template.json`), "utf8"),
|
||||
);
|
||||
for (const field of manifest.admin.sections.flatMap((section) => section.fields)) {
|
||||
assert.ok(runtimeContractForBinding(field.binding), `${key}: ${field.binding}`);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
test("shared brand facts have one editor and template-specific offering detail binds to Runtime", () => {
|
||||
const sharedBrandBindings = new Set([
|
||||
"brand.name",
|
||||
"brand.tagline",
|
||||
"brand.description",
|
||||
"brand.avatarUrl",
|
||||
"brand.coverUrl",
|
||||
"brand.hours",
|
||||
"brand.address",
|
||||
"brand.contactPhone",
|
||||
"brand.contactWechat",
|
||||
"brand.deliveryNote",
|
||||
]);
|
||||
for (const key of ["acheng-campus-food", "linjing-editorial"]) {
|
||||
const root = path.join(packageRoot, `template-${key}`);
|
||||
const manifest = JSON.parse(fs.readFileSync(path.join(root, "template.json"), "utf8"));
|
||||
const bindings = manifest.admin.sections.flatMap((section) =>
|
||||
section.fields.map((field) => field.binding),
|
||||
);
|
||||
assert.ok(!bindings.some((binding) => sharedBrandBindings.has(binding)), key);
|
||||
}
|
||||
const foodRoot = path.join(packageRoot, "template-acheng-campus-food");
|
||||
const food = JSON.parse(fs.readFileSync(path.join(foodRoot, "template.json"), "utf8"));
|
||||
const background = food.admin.sections
|
||||
.flatMap((section) => section.fields)
|
||||
.find((field) => field.binding === "offering.config.details.background");
|
||||
assert.equal(background.label, "餐品介绍");
|
||||
const runtimeRenderer = fs.readFileSync(
|
||||
path.resolve(
|
||||
packageRoot,
|
||||
"../apps/miniapp/components/modules/offering-detail/offering-detail.wxml",
|
||||
),
|
||||
"utf8",
|
||||
);
|
||||
assert.match(runtimeRenderer, /item\.details\.background\s*\|\|\s*item\.desc/);
|
||||
const runtimeProjection = fs.readFileSync(
|
||||
path.resolve(packageRoot, "../apps/api/src/modules/public/public-workspace.controller.ts"),
|
||||
"utf8",
|
||||
);
|
||||
assert.match(runtimeProjection, /projectOfferingDetails\(config\)/);
|
||||
});
|
||||
|
||||
test("food service slots declare the structured fields consumed by their visual layout", () => {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, "template-acheng-campus-food/template.json"), "utf8"),
|
||||
);
|
||||
const schedule = manifest.trustContentTypes.find((item) => item.type === "schedule");
|
||||
assert.deepEqual(schedule.pages, ["service"]);
|
||||
assert.deepEqual(schedule.hideStandardFields, ["summary", "content"]);
|
||||
for (const key of ["weekdayLabel", "weekdayDetail", "weekendLabel", "weekendDetail"]) {
|
||||
assert.ok(schedule.configFields.some((field) => field.key === key && field.required));
|
||||
}
|
||||
const page = fs.readFileSync(
|
||||
path.join(packageRoot, "template-acheng-campus-food/miniapp/pages/stall-service/index.wxml"),
|
||||
"utf8",
|
||||
);
|
||||
assert.match(page, /wx:for="\{\{schedule\.rows\}\}"/);
|
||||
assert.doesNotMatch(page, /wx:for="\{\{trustItems\}\}"|item\.summary|item\.content/);
|
||||
});
|
||||
|
||||
test("food home passes projected trust items to the renderer", () => {
|
||||
const page = fs.readFileSync(
|
||||
path.join(packageRoot, "template-acheng-campus-food/miniapp/pages/index/index.wxml"),
|
||||
"utf8",
|
||||
);
|
||||
assert.match(page, /<acheng-home[\s\S]*trust-items="\{\{trustItems\}\}"/);
|
||||
assert.doesNotMatch(page, /trust-content=/);
|
||||
});
|
||||
|
||||
test("food profile renders only profile trust types once", () => {
|
||||
const manifest = JSON.parse(
|
||||
fs.readFileSync(path.join(packageRoot, "template-acheng-campus-food/template.json"), "utf8"),
|
||||
);
|
||||
const page = fs.readFileSync(
|
||||
path.join(packageRoot, "template-acheng-campus-food/miniapp/pages/bookings/index.wxml"),
|
||||
"utf8",
|
||||
);
|
||||
assert.equal(
|
||||
manifest.trustContentTypes.find((item) => item.type === "credential").pages.includes("profile"),
|
||||
true,
|
||||
);
|
||||
for (const type of ["coverage", "process"]) {
|
||||
assert.equal(
|
||||
manifest.trustContentTypes.find((item) => item.type === type).pages.includes("profile"),
|
||||
false,
|
||||
`${type} must be rendered on its dedicated page`,
|
||||
);
|
||||
}
|
||||
assert.equal((page.match(/credentials="{{credentials}}"/g) ?? []).length, 1);
|
||||
assert.doesNotMatch(page, /item\.type === '(coverage|process)'/);
|
||||
for (const type of ["case", "promise"]) {
|
||||
assert.ok(
|
||||
manifest.trustContentTypes.find((item) => item.type === type).pages.includes("profile"),
|
||||
);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user