fix: 收敛模板编辑发布契约并还原餐饮页面视觉
This commit is contained in:
1 parent
20bcb43534
commit
f4061a24bd
102 files changed
+4510
-870
No files matched your search
@@ -10,6 +10,14 @@
|
||||
4. 如果需要替换运行时或能力包页面,必须在 `overrides` 中声明目录;未声明的同路径文件会被 compiler 拒绝。
|
||||
5. 执行 `pnpm generate:template-catalog --write` 和 `pnpm template:check`。
|
||||
|
||||
## 模板完成门槛
|
||||
|
||||
- 每个 `entrypoints` 页面里由品牌编辑者提供的标题、说明、信任资料、业务详情和视觉文案,都必须由 Runtime 数据驱动,不能只在 WXML 中写成固定业务事实。
|
||||
- 每个可编辑字段必须在 `admin.sections` 声明,并把 `page` 指向实际显示它的页面;测试会按页面检查 `presentation`、hero、profile、trust 和 offering 绑定,不能只在其他页面存在同名绑定。
|
||||
- 每个 `trustContentTypes` 都必须声明至少一个实际展示页面;模板测试会检查 renderer 是否消费该类型,也会检查 renderer 使用的类型是否已声明在对应页面。
|
||||
- `pnpm validate:templates` 会自动发现所有 `packages/template-*` 并运行上述绑定回归。模板不能在未通过该检查时标记完成。
|
||||
- 通过自动检查后,还要用 `pnpm template:dev <key> --brand <slug>` 生成产物,检查真实内容、空状态和窄屏视觉;自动绑定测试不能替代微信开发者工具中的视觉验收。
|
||||
|
||||
最小可编译模板可参考 `packages/template-compiler/test/fixtures/template-drill-consultant`。
|
||||
|
||||
使用 `pnpm template:dev <key> --brand <slug>` 生成微信开发者工具项目。生产构建还必须提供 `--appid` 和 HTTPS `--api`。模板在构建时选择,运行时不会下载或解释模板代码。
|
||||
@@ -45,7 +45,16 @@ export type TemplateAdminField = {
|
||||
binding: string;
|
||||
label: string;
|
||||
help?: string;
|
||||
input: "text" | "textarea" | "phone" | "image" | "number" | "list";
|
||||
input:
|
||||
| "text"
|
||||
| "textarea"
|
||||
| "phone"
|
||||
| "image"
|
||||
| "number"
|
||||
| "boolean"
|
||||
| "select"
|
||||
| "multi-select"
|
||||
| "list";
|
||||
itemFields?: Array<{
|
||||
key: string;
|
||||
label: string;
|
||||
@@ -56,6 +65,14 @@ export type TemplateAdminField = {
|
||||
required?: boolean;
|
||||
maxLength?: number;
|
||||
placeholder?: string;
|
||||
options?: Array<{ value: string; label: string }>;
|
||||
};
|
||||
|
||||
/** 模板自己的浅层品牌字段,值存于 BrandProfile.config.templateData。 */
|
||||
export type TemplateField = Omit<TemplateAdminField, "binding"> & {
|
||||
key: string;
|
||||
page?: TemplatePageKey;
|
||||
binding?: `brand.config.templateData.${string}`;
|
||||
};
|
||||
|
||||
/** 一个面向业务用户的编辑分组,而不是技术 schema 或 JSON 编辑器。 */
|
||||
@@ -63,6 +80,8 @@ export type TemplateAdminSection = {
|
||||
key: string;
|
||||
title: string;
|
||||
description: string;
|
||||
/** Exact Mini Program page that displays this section's content. */
|
||||
page: TemplatePageKey;
|
||||
target: "brand" | "offering" | "trust" | "inquiry";
|
||||
fields: TemplateAdminField[];
|
||||
};
|
||||
@@ -74,14 +93,26 @@ export type TemplateAdminManifest = {
|
||||
export type TemplateTrustContentType = {
|
||||
type: "schedule" | "coverage" | "process" | "credential" | "case" | "promise" | (string & {});
|
||||
label: string;
|
||||
/** Labels for the persisted TrustContent columns edited in Admin. */
|
||||
adminFields: {
|
||||
title: string;
|
||||
summary: string;
|
||||
content: string;
|
||||
summaryHelp?: string;
|
||||
summaryPlaceholder?: string;
|
||||
};
|
||||
pages?: TemplatePageKey[];
|
||||
help?: string;
|
||||
placeholder?: string;
|
||||
required?: boolean;
|
||||
configFields?: TemplateAdminField[];
|
||||
maxPublishedItems?: number;
|
||||
hideStandardFields?: Array<"summary" | "content">;
|
||||
};
|
||||
|
||||
export type TemplateSampleContent = {
|
||||
templateKey: string;
|
||||
inquiryFormName: string;
|
||||
offerings: Array<Record<string, unknown>>;
|
||||
trustContent: Array<Record<string, unknown>>;
|
||||
fields: Array<Record<string, unknown>>;
|
||||
@@ -110,6 +141,7 @@ export type TemplatePackageManifest = {
|
||||
/** 开发时的默认品牌;构建参数 `--brand` 优先。 */
|
||||
defaultBrandSlug?: string;
|
||||
dataSlots: TemplateDataSlot[];
|
||||
templateFields?: TemplateField[];
|
||||
assetSlots: TemplateAssetSlot[];
|
||||
admin: TemplateAdminManifest;
|
||||
trustContentTypes?: TemplateTrustContentType[];
|
||||
@@ -142,6 +174,14 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
errors.push("data slot source is invalid");
|
||||
}
|
||||
}
|
||||
for (const [index, field] of (manifest.templateFields ?? []).entries()) {
|
||||
if (!field?.key?.trim() || !field?.label?.trim())
|
||||
errors.push(`templateFields.${index} requires key and label`);
|
||||
if (field.binding && !field.binding.startsWith("brand.config.templateData."))
|
||||
errors.push(`templateFields.${index}.binding must target templateData`);
|
||||
if (field.input === "list" && !field.itemFields?.length)
|
||||
errors.push(`templateFields.${index}.list requires itemFields`);
|
||||
}
|
||||
if (manifest.trustContentTypes !== undefined) {
|
||||
if (!Array.isArray(manifest.trustContentTypes))
|
||||
errors.push("trustContentTypes must be an array");
|
||||
@@ -155,6 +195,19 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
errors.push(`trustContentTypes.${index}.type is required`);
|
||||
if (typeof item.label !== "string" || !item.label.trim())
|
||||
errors.push(`trustContentTypes.${index}.label is required`);
|
||||
for (const key of ["title", "summary", "content"] as const) {
|
||||
if (typeof item.adminFields?.[key] !== "string" || !item.adminFields[key].trim())
|
||||
errors.push(`trustContentTypes.${index}.adminFields.${key} is required`);
|
||||
}
|
||||
for (const page of item.pages ?? []) {
|
||||
if (!manifest.entrypoints?.[page])
|
||||
errors.push(`trustContentTypes.${index}.pages contains an undeclared entrypoint`);
|
||||
}
|
||||
if (
|
||||
item.maxPublishedItems !== undefined &&
|
||||
(!Number.isInteger(item.maxPublishedItems) || item.maxPublishedItems < 1)
|
||||
)
|
||||
errors.push(`trustContentTypes.${index}.maxPublishedItems must be a positive integer`);
|
||||
for (const field of item.configFields ?? []) {
|
||||
if (!field.key?.trim() || !field.binding?.startsWith("trust.config."))
|
||||
errors.push(`trustContentTypes.${index}.configFields binding is invalid`);
|
||||
@@ -164,6 +217,41 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
}
|
||||
}
|
||||
}
|
||||
if (manifest.sampleContent && typeof manifest.sampleContent === "object") {
|
||||
for (const [industry, sample] of Object.entries(manifest.sampleContent)) {
|
||||
if (!sample.inquiryFormName?.trim())
|
||||
errors.push(`sampleContent.${industry}.inquiryFormName is required`);
|
||||
for (const [index, item] of (sample.trustContent ?? []).entries()) {
|
||||
if (!manifest.trustContentTypes?.some((type) => type.type === item.type))
|
||||
errors.push(
|
||||
`sampleContent.${industry}.trustContent.${index} uses an undeclared trust content type`,
|
||||
);
|
||||
}
|
||||
for (const [index, field] of (sample.fields ?? []).entries()) {
|
||||
if (
|
||||
typeof field.key !== "string" ||
|
||||
!field.key.trim() ||
|
||||
typeof field.label !== "string" ||
|
||||
!field.label.trim()
|
||||
)
|
||||
errors.push(`sampleContent.${industry}.fields.${index} requires key and label`);
|
||||
if (
|
||||
![
|
||||
"text",
|
||||
"tel",
|
||||
"phone",
|
||||
"number",
|
||||
"select",
|
||||
"radio",
|
||||
"multi-select",
|
||||
"textarea",
|
||||
"date",
|
||||
].includes(String(field.type))
|
||||
)
|
||||
errors.push(`sampleContent.${industry}.fields.${index} has an unsupported Runtime type`);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Array.isArray(manifest.assetSlots)) errors.push("assetSlots must be an array");
|
||||
else {
|
||||
for (const slot of manifest.assetSlots) {
|
||||
@@ -177,6 +265,10 @@ export function validateTemplatePackageManifest(value: unknown): string[] {
|
||||
for (const section of manifest.admin.sections) {
|
||||
if (!section?.key?.trim() || !section.title?.trim() || !section.description?.trim())
|
||||
errors.push("every admin section requires key, title and description");
|
||||
if (!section?.page?.trim() || !manifest.entrypoints?.[section.page])
|
||||
errors.push(
|
||||
`admin section ${section?.key ?? "<unknown>"} must target a declared entrypoint`,
|
||||
);
|
||||
if (!Array.isArray(section.fields) || !section.fields.length)
|
||||
errors.push("every admin section must contain fields");
|
||||
for (const field of section.fields ?? []) {
|
||||
|
||||
@@ -6,6 +6,17 @@ import test from "node:test";
|
||||
|
||||
const packagesRoot = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
||||
const runtimeRoot = path.resolve(packagesRoot, "../apps/miniapp");
|
||||
const adminTrustEditor = fs.readFileSync(
|
||||
path.resolve(packagesRoot, "../apps/admin/src/features/trust-content/TrustContentPage.tsx"),
|
||||
"utf8",
|
||||
);
|
||||
|
||||
for (const field of ["title", "summary", "content"]) {
|
||||
assert.ok(
|
||||
adminTrustEditor.includes(`selectedTypeMeta?.adminFields.${field}`),
|
||||
`Admin trust editor must render the manifest label for ${field}`,
|
||||
);
|
||||
}
|
||||
|
||||
function sourceFile(templateRoot, relativePath, extension) {
|
||||
const local = path.join(templateRoot, "miniapp", `${relativePath}.${extension}`);
|
||||
@@ -19,6 +30,9 @@ function renderedFields(templateRoot, entrypoint) {
|
||||
const heroFields = new Set();
|
||||
const profileFields = new Set();
|
||||
const trustFields = new Set();
|
||||
const trustItemTypes = new Set();
|
||||
const brandFields = new Set();
|
||||
let rendersAllTrustItems = false;
|
||||
function visit(relativePath) {
|
||||
if (seen.has(relativePath)) return;
|
||||
seen.add(relativePath);
|
||||
@@ -29,6 +43,9 @@ function renderedFields(templateRoot, entrypoint) {
|
||||
for (const match of content.matchAll(/(?<![.\w])presentation\.([A-Za-z][A-Za-z0-9]*)/g)) {
|
||||
fields.add(match[1]);
|
||||
}
|
||||
for (const match of content.matchAll(/(?<![.\w])brand\.([A-Za-z][A-Za-z0-9]*)/g)) {
|
||||
brandFields.add(match[1]);
|
||||
}
|
||||
for (const match of content.matchAll(/(?<![.\w])hero\.([A-Za-z][A-Za-z0-9]*)/g)) {
|
||||
heroFields.add(match[1]);
|
||||
}
|
||||
@@ -38,6 +55,21 @@ function renderedFields(templateRoot, entrypoint) {
|
||||
for (const match of content.matchAll(/trustContent\.([A-Za-z][A-Za-z0-9]*)/g)) {
|
||||
trustFields.add(match[1]);
|
||||
}
|
||||
for (const match of content.matchAll(
|
||||
/selectSlot\(items,\s*["']([A-Za-z][A-Za-z0-9_-]*)["']\)/g,
|
||||
)) {
|
||||
trustItemTypes.add(match[1]);
|
||||
}
|
||||
if (/trustItems/.test(content)) {
|
||||
for (const match of content.matchAll(
|
||||
/item\.type\s*===\s*["']([A-Za-z][A-Za-z0-9_-]*)["']/g,
|
||||
)) {
|
||||
trustItemTypes.add(match[1]);
|
||||
}
|
||||
if (/wx:for="{{trustItems}}"/.test(content) && !/item\.type\s*===/.test(content)) {
|
||||
rendersAllTrustItems = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
const componentConfig = sourceFile(templateRoot, relativePath, "json");
|
||||
if (!componentConfig) return;
|
||||
@@ -49,7 +81,16 @@ function renderedFields(templateRoot, entrypoint) {
|
||||
}
|
||||
}
|
||||
visit(entrypoint);
|
||||
return { fields, heroFields, profileFields, trustFields, seen };
|
||||
return {
|
||||
fields,
|
||||
heroFields,
|
||||
profileFields,
|
||||
trustFields,
|
||||
trustItemTypes,
|
||||
brandFields,
|
||||
rendersAllTrustItems,
|
||||
seen,
|
||||
};
|
||||
}
|
||||
|
||||
const sharedOfferingBindings = [
|
||||
@@ -64,6 +105,18 @@ const sharedOfferingBindings = [
|
||||
"offering.config.details.crafts",
|
||||
"offering.config.details.materialsList",
|
||||
];
|
||||
const offeringRuntimeBindings = {
|
||||
"offering.config.categoryLabel": "item.presentation.categoryLabel",
|
||||
"offering.config.detailHero": "item.detailHero",
|
||||
"offering.config.area": "item.area",
|
||||
"offering.config.series": "item.series",
|
||||
"offering.config.spaceType": "item.spaceType",
|
||||
"offering.config.keywords": "item.keywords",
|
||||
"offering.config.details.background": "item.details.background",
|
||||
"offering.config.details.designConcept": "item.details.designConcept",
|
||||
"offering.config.details.crafts": "item.details.crafts",
|
||||
"offering.config.details.materialsList": "item.details.materialsList",
|
||||
};
|
||||
|
||||
for (const directory of fs
|
||||
.readdirSync(packagesRoot)
|
||||
@@ -73,31 +126,99 @@ for (const directory of fs
|
||||
if (!fs.existsSync(manifestPath)) continue;
|
||||
test(`${directory} exposes rendered content through Admin bindings`, () => {
|
||||
const manifest = JSON.parse(fs.readFileSync(manifestPath, "utf8"));
|
||||
for (const declaration of manifest.trustContentTypes ?? []) {
|
||||
for (const field of ["title", "summary", "content"]) {
|
||||
assert.ok(
|
||||
declaration.adminFields?.[field]?.trim(),
|
||||
`${manifest.packageKey}: trust type ${declaration.type} has no Admin label for ${field}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const sample of Object.values(manifest.sampleContent ?? {})) {
|
||||
for (const item of sample.trustContent ?? []) {
|
||||
assert.ok(
|
||||
manifest.trustContentTypes?.some((type) => type.type === item.type),
|
||||
`${manifest.packageKey}: sample trust type ${item.type} has no declared editor or renderer`,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const section of manifest.admin.sections) {
|
||||
assert.ok(
|
||||
manifest.entrypoints[section.page],
|
||||
`${manifest.packageKey}: ${section.key} points to an unknown Mini Program page`,
|
||||
);
|
||||
}
|
||||
const bindings = new Set(
|
||||
manifest.admin.sections.flatMap((section) => section.fields.map((field) => field.binding)),
|
||||
);
|
||||
for (const [pageKey, entrypoint] of Object.entries(manifest.entrypoints)) {
|
||||
const { fields, heroFields, profileFields, trustFields, seen } = renderedFields(
|
||||
templateRoot,
|
||||
entrypoint,
|
||||
const {
|
||||
fields,
|
||||
heroFields,
|
||||
profileFields,
|
||||
trustFields,
|
||||
trustItemTypes,
|
||||
brandFields,
|
||||
rendersAllTrustItems,
|
||||
seen,
|
||||
} = renderedFields(templateRoot, entrypoint);
|
||||
const pageBindings = new Set(
|
||||
manifest.admin.sections
|
||||
.filter((section) => section.page === pageKey)
|
||||
.flatMap((section) => section.fields.map((field) => field.binding)),
|
||||
);
|
||||
for (const field of fields) {
|
||||
const binding = `brand.config.visualPresentation.${pageKey}.${field}`;
|
||||
assert.ok(
|
||||
bindings.has(`brand.config.visualPresentation.${pageKey}.${field}`),
|
||||
`${manifest.packageKey}: ${pageKey}.${field} is rendered but has no Admin field`,
|
||||
bindings.has(binding),
|
||||
`${manifest.packageKey}: ${pageKey}.${field} has no Admin field`,
|
||||
);
|
||||
assert.ok(
|
||||
pageBindings.has(binding),
|
||||
`${manifest.packageKey}: ${pageKey}.${field} Admin field is assigned to another page`,
|
||||
);
|
||||
}
|
||||
for (const field of heroFields) {
|
||||
const binding =
|
||||
field === "image" ? "brand.config.heroImage" : `brand.config.homeHero.${field}`;
|
||||
assert.ok(
|
||||
bindings.has(binding),
|
||||
pageBindings.has(binding),
|
||||
`${manifest.packageKey}: ${pageKey} hero.${field} has no Admin field`,
|
||||
);
|
||||
}
|
||||
for (const declaration of manifest.admin.sections.filter((item) => item.page === pageKey)) {
|
||||
for (const field of declaration.fields) {
|
||||
const binding = field.binding;
|
||||
if (binding === "brand.avatarUrl")
|
||||
assert.ok(
|
||||
brandFields.has("avatarUrl"),
|
||||
`${manifest.packageKey}: avatar has no renderer`,
|
||||
);
|
||||
if (binding === "brand.description")
|
||||
assert.ok(
|
||||
brandFields.has("slogan") || brandFields.has("description"),
|
||||
`${manifest.packageKey}: description has no renderer`,
|
||||
);
|
||||
if (binding === "brand.contactPhone")
|
||||
assert.ok(
|
||||
brandFields.has("phone") || brandFields.has("contactPhone"),
|
||||
`${manifest.packageKey}: phone has no renderer`,
|
||||
);
|
||||
if (binding === "brand.contactWechat")
|
||||
assert.ok(
|
||||
brandFields.has("wechat") || brandFields.has("contactWechat"),
|
||||
`${manifest.packageKey}: WeChat has no renderer`,
|
||||
);
|
||||
if (binding === "brand.address")
|
||||
assert.ok(
|
||||
brandFields.has("studioAddress") || brandFields.has("address"),
|
||||
`${manifest.packageKey}: address has no renderer`,
|
||||
);
|
||||
}
|
||||
}
|
||||
for (const field of profileFields) {
|
||||
assert.ok(
|
||||
bindings.has(`brand.config.profilePresentation.${field}`),
|
||||
pageBindings.has(`brand.config.profilePresentation.${field}`),
|
||||
`${manifest.packageKey}: profilePresentation.${field} has no Admin field`,
|
||||
);
|
||||
}
|
||||
@@ -110,17 +231,107 @@ for (const directory of fs
|
||||
continue;
|
||||
}
|
||||
assert.ok(
|
||||
manifest.trustContentTypes?.some((type) =>
|
||||
type.configFields?.some(
|
||||
(configField) => configField.binding === `trust.config.${field}`,
|
||||
),
|
||||
manifest.trustContentTypes?.some(
|
||||
(type) =>
|
||||
type.pages?.includes(pageKey) &&
|
||||
type.configFields?.some(
|
||||
(configField) => configField.binding === `trust.config.${field}`,
|
||||
),
|
||||
),
|
||||
`${manifest.packageKey}: trustContent.${field} has no Admin field`,
|
||||
);
|
||||
}
|
||||
for (const type of trustItemTypes) {
|
||||
const declaration = manifest.trustContentTypes?.find((item) => item.type === type);
|
||||
assert.ok(
|
||||
declaration,
|
||||
`${manifest.packageKey}: renderer uses undeclared trust type ${type}`,
|
||||
);
|
||||
assert.ok(
|
||||
declaration.pages?.includes(pageKey),
|
||||
`${manifest.packageKey}: renderer uses trust type ${type} on ${pageKey} but the page is not declared`,
|
||||
);
|
||||
}
|
||||
for (const declaration of manifest.trustContentTypes ?? []) {
|
||||
if (!declaration.pages?.includes(pageKey)) continue;
|
||||
assert.ok(
|
||||
rendersAllTrustItems || trustItemTypes.has(declaration.type),
|
||||
`${manifest.packageKey}: trust type ${declaration.type} claims ${pageKey}, but that renderer does not display it`,
|
||||
);
|
||||
}
|
||||
const pageSource = [...seen]
|
||||
.flatMap((relativePath) =>
|
||||
["js", "wxml"]
|
||||
.map((extension) => sourceFile(templateRoot, relativePath, extension))
|
||||
.filter(Boolean)
|
||||
.map((file) => fs.readFileSync(file, "utf8")),
|
||||
)
|
||||
.join("\n");
|
||||
for (const declaration of manifest.trustContentTypes ?? []) {
|
||||
if (!declaration.pages?.includes(pageKey)) continue;
|
||||
for (const field of declaration.configFields ?? []) {
|
||||
assert.ok(
|
||||
pageSource.includes(`.${field.key}`) ||
|
||||
declaration.pages.some((destination) => {
|
||||
const destinationFiles = renderedFields(
|
||||
templateRoot,
|
||||
manifest.entrypoints[destination],
|
||||
).seen;
|
||||
return [...destinationFiles].some((file) =>
|
||||
["js", "wxml"].some((extension) => {
|
||||
const source = sourceFile(templateRoot, file, extension);
|
||||
return source && fs.readFileSync(source, "utf8").includes(`.${field.key}`);
|
||||
}),
|
||||
);
|
||||
}),
|
||||
`${manifest.packageKey}: ${declaration.type}.${field.key} is editable but is not consumed on ${pageKey}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (pageKey === Object.keys(manifest.entrypoints)[0]) {
|
||||
for (const declaration of manifest.trustContentTypes ?? []) {
|
||||
assert.ok(
|
||||
declaration.pages?.length,
|
||||
`${manifest.packageKey}: trust type ${declaration.type} must declare its Mini Program destination`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (pageKey === "home") {
|
||||
for (const field of manifest.templateFields ?? []) {
|
||||
const source = `templateData.${field.key}`;
|
||||
const entryFiles = [...seen].flatMap((relativePath) =>
|
||||
["js", "wxml"]
|
||||
.map((extension) => sourceFile(templateRoot, relativePath, extension))
|
||||
.filter(Boolean),
|
||||
);
|
||||
assert.ok(
|
||||
entryFiles.some((file) =>
|
||||
new RegExp(`templateData(?:\\?\\.)?${field.key}`).test(fs.readFileSync(file, "utf8")),
|
||||
),
|
||||
`${manifest.packageKey}: template field ${field.key} is declared but never rendered`,
|
||||
);
|
||||
}
|
||||
}
|
||||
if (seen.has("components/modules/offering-detail/offering-detail")) {
|
||||
for (const binding of sharedOfferingBindings) {
|
||||
assert.ok(bindings.has(binding), `${manifest.packageKey}: missing ${binding}`);
|
||||
assert.ok(
|
||||
pageBindings.has(binding),
|
||||
`${manifest.packageKey}: missing ${binding} on detail page`,
|
||||
);
|
||||
}
|
||||
const detailSources = [...seen].flatMap((relativePath) =>
|
||||
["wxml", "js"]
|
||||
.map((extension) => sourceFile(templateRoot, relativePath, extension))
|
||||
.filter(Boolean)
|
||||
.map((file) => fs.readFileSync(file, "utf8")),
|
||||
);
|
||||
const detailSource = detailSources.join("\n");
|
||||
for (const [binding, runtimePath] of Object.entries(offeringRuntimeBindings)) {
|
||||
if (!pageBindings.has(binding)) continue;
|
||||
assert.ok(
|
||||
detailSource.includes(runtimePath),
|
||||
`${manifest.packageKey}: ${binding} is editable but ${runtimePath} is not rendered on ${pageKey}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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