refactor: 统一模板契约并修复预览版本
This commit is contained in:
1 parent
cd2992c00a
commit
50b87e48de
56 files changed
+7849
-5756
No files matched your search
@@ -20,7 +20,6 @@ const brand = {
|
||||
contactPhone: "13800138000",
|
||||
contactWechat: "food-example",
|
||||
config: {
|
||||
visualTemplateKey: "acheng-campus-food",
|
||||
founder: "测试主理人",
|
||||
title: "私房菜主理人",
|
||||
heroImage: "",
|
||||
@@ -56,7 +55,11 @@ const runtimeWorkspace = {
|
||||
founder: brand.config.founder,
|
||||
title: brand.config.title,
|
||||
visualPresentation: {},
|
||||
visualTemplateKey: brand.config.visualTemplateKey,
|
||||
},
|
||||
visualTemplate: {
|
||||
key: "acheng-campus-food",
|
||||
version: "1.0.2",
|
||||
name: "阿成校园餐",
|
||||
},
|
||||
templateData: {},
|
||||
navigation: { tabs: [] },
|
||||
|
||||
@@ -15,24 +15,27 @@ const modules = Object.fromEntries(
|
||||
]),
|
||||
);
|
||||
|
||||
test("多模板预览随当前品牌配置切换所有真实模板,重复切换不保留旧 renderer", () => {
|
||||
test("多模板预览随 Runtime 模板声明切换所有真实 renderer", () => {
|
||||
for (const manifest of [...manifests, ...manifests.reverse()]) {
|
||||
assert.equal(
|
||||
resolvePreviewRenderer(modules, { visualTemplateKey: manifest.packageKey })?.key,
|
||||
resolvePreviewRenderer(modules, {
|
||||
visualTemplate: { key: manifest.visualTemplateKey },
|
||||
})?.key,
|
||||
manifest.packageKey,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
test("缺少或未知模板时不回落到首个模板", () => {
|
||||
for (const config of [
|
||||
test("缺少或未知 Runtime 模板声明时不回落到首个模板", () => {
|
||||
for (const workspace of [
|
||||
undefined,
|
||||
null,
|
||||
[],
|
||||
{},
|
||||
{ visualTemplateKey: "missing" },
|
||||
{ visualTemplateKey: 1 },
|
||||
{ brand: { config: { visualTemplateKey: "acheng-campus-food" } } },
|
||||
{ visualTemplate: { key: "missing" } },
|
||||
{ visualTemplate: { key: 1 } },
|
||||
]) {
|
||||
assert.equal(resolvePreviewRenderer(modules, config), undefined);
|
||||
assert.equal(resolvePreviewRenderer(modules, workspace), undefined);
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user