fix: 完善模板可视化编辑闭环与通用验收
This commit is contained in:
1 parent
fa6b492bce
commit
22a82dbfba
39 files changed
+7773
-443
No files matched your search
@@ -1,4 +1,73 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
import fs from "node:fs";
|
||||
import { test, expect, type Page } from "@playwright/test";
|
||||
|
||||
// 从真实 DOM 点选区域,避免侧栏测试掩盖画布目标无法激活。
|
||||
async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
|
||||
const preview = page.locator(".component-template-preview");
|
||||
const targets = manifest.admin.sections
|
||||
.filter(
|
||||
(section: any) =>
|
||||
section.page === pageKey && (pageKey !== "detail" || section.target === "brand"),
|
||||
)
|
||||
.flatMap((section: any) =>
|
||||
(section.previewTargets ?? [])
|
||||
.filter((target: any) => !target.composite)
|
||||
.map((target: any) => target.key),
|
||||
);
|
||||
if (pageKey !== "detail") {
|
||||
targets.push(
|
||||
...manifest.trustContentTypes.flatMap((item: any) =>
|
||||
(item.previewTargets ?? [])
|
||||
.filter((target: any) => target.page === pageKey)
|
||||
.map((target: any) => target.key),
|
||||
),
|
||||
);
|
||||
targets.push(
|
||||
...manifest.trustContentTypes
|
||||
.filter((item: any) => item.pages.includes(pageKey))
|
||||
.map((item: any) => "trust:" + item.type),
|
||||
);
|
||||
}
|
||||
for (const target of new Set<string>(targets)) {
|
||||
const elements = preview.locator(`[data-editor-target="${target}"]`);
|
||||
for (let index = 0; index < (await elements.count()); index++) {
|
||||
const element = elements.nth(index);
|
||||
if (!(await element.isVisible())) continue;
|
||||
const leafIndex = await element.evaluate((node, key) => {
|
||||
return Array.from(node.querySelectorAll("*")).findIndex((child) => {
|
||||
const rect = child.getBoundingClientRect();
|
||||
return (
|
||||
child.childElementCount === 0 &&
|
||||
rect.width > 0 &&
|
||||
rect.height > 0 &&
|
||||
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key
|
||||
);
|
||||
});
|
||||
}, target);
|
||||
// 点击区内真实叶子内容,避开圆角的透明区域及嵌套子选区。
|
||||
const content = leafIndex >= 0 ? element.locator("*").nth(leafIndex) : element;
|
||||
await content.scrollIntoViewIfNeeded();
|
||||
const point = await content.evaluate((node) => {
|
||||
const rect = node.getBoundingClientRect();
|
||||
const x = rect.left + rect.width / 2;
|
||||
const y = rect.top + rect.height / 2;
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
target: document
|
||||
.elementFromPoint(x, y)
|
||||
?.closest("[data-editor-target]")
|
||||
?.getAttribute("data-editor-target"),
|
||||
};
|
||||
});
|
||||
expect(point.target, "实际命中区域:" + target).toBe(target);
|
||||
await page.mouse.click(point.x, point.y);
|
||||
await expect(
|
||||
preview.locator(".component-template-preview__outline.is-selected"),
|
||||
).toHaveAttribute("data-selected-target", target);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||
const brand = {
|
||||
@@ -94,157 +163,44 @@ const runtimeWorkspace = {
|
||||
capabilities: [],
|
||||
theme: { colors: {} },
|
||||
};
|
||||
const templateContent = {
|
||||
displayName: "餐饮模板",
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "offerings", page: "offerings", label: "套餐餐品" },
|
||||
{ key: "service", page: "service", label: "出摊服务" },
|
||||
{ key: "detail", page: "detail", label: "详情页" },
|
||||
{ key: "inquiry", page: "inquiry", label: "定制/咨询" },
|
||||
{ key: "success", page: "success", label: "提交成功页" },
|
||||
{ key: "records", page: "records", label: "记录页" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [
|
||||
{
|
||||
type: "schedule",
|
||||
label: "每周出摊安排",
|
||||
adminFields: { title: "安排标题", summary: "安排摘要", content: "安排正文" },
|
||||
hideStandardFields: ["summary", "content"],
|
||||
pages: ["service"],
|
||||
configFields: [
|
||||
{
|
||||
key: "weekdayLabel",
|
||||
binding: "trust.config.weekdayLabel",
|
||||
label: "工作日标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekdayDetail",
|
||||
binding: "trust.config.weekdayDetail",
|
||||
label: "工作日地点",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekendLabel",
|
||||
binding: "trust.config.weekendLabel",
|
||||
label: "周末标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "weekendDetail",
|
||||
binding: "trust.config.weekendDetail",
|
||||
label: "周末地点",
|
||||
input: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
admin: {
|
||||
sections: [
|
||||
{
|
||||
key: "detailCopy",
|
||||
title: "餐品说明",
|
||||
description: "编辑详情页说明",
|
||||
page: "detail",
|
||||
target: "brand",
|
||||
previewTargets: [{ key: "acheng-campus-food.detail.detailCopy", label: "餐品说明" }],
|
||||
fields: [
|
||||
{
|
||||
key: "priceLabel",
|
||||
binding: "brand.config.visualPresentation.detail.priceLabel",
|
||||
label: "价格标题",
|
||||
input: "text",
|
||||
previewTarget: "acheng-campus-food.detail.detailCopy",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "offering-card",
|
||||
title: "餐品卡片",
|
||||
description: "编辑单条餐品",
|
||||
page: "offerings",
|
||||
target: "offering",
|
||||
previewTargets: [{ key: "acheng-campus-food.offerings.item", label: "餐品卡片" }],
|
||||
fields: [
|
||||
{
|
||||
key: "name",
|
||||
binding: "offering.name",
|
||||
label: "餐品名称",
|
||||
input: "text",
|
||||
previewTarget: "acheng-campus-food.offerings.item",
|
||||
},
|
||||
{
|
||||
key: "summary",
|
||||
binding: "offering.summary",
|
||||
label: "餐品简介",
|
||||
input: "textarea",
|
||||
previewTarget: "acheng-campus-food.offerings.item",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "home",
|
||||
title: "首页内容",
|
||||
description: "首页可编辑项",
|
||||
page: "home",
|
||||
target: "brand",
|
||||
previewTargets: [
|
||||
{
|
||||
key: "food.home.brand-card",
|
||||
label: "品牌信息区",
|
||||
composite: true,
|
||||
children: ["food.home.identity", "food.home.location", "food.home.actions"],
|
||||
},
|
||||
{ key: "food.home.identity", label: "主理人身份" },
|
||||
{ key: "food.home.location", label: "服务地点" },
|
||||
{ key: "food.home.offerings-heading", label: "餐品区域标题" },
|
||||
{ key: "food.home.actions", label: "首页操作按钮" },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
key: "identity",
|
||||
binding: "brand.config.founder",
|
||||
previewTarget: "food.home.identity",
|
||||
label: "主理人姓名",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "stallTitle",
|
||||
binding: "brand.config.visualPresentation.home.stallTitle",
|
||||
previewTarget: "food.home.location",
|
||||
label: "出摊信息标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "stallTime",
|
||||
binding: "brand.config.visualPresentation.home.stallTime",
|
||||
previewTarget: "food.home.location",
|
||||
label: "营业时间说明",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "worksTitle",
|
||||
binding: "brand.config.visualPresentation.home.worksTitle",
|
||||
previewTarget: "food.home.offerings-heading",
|
||||
label: "招牌餐品标题",
|
||||
input: "text",
|
||||
},
|
||||
{
|
||||
key: "primaryAction",
|
||||
binding: "brand.config.visualPresentation.home.primaryAction",
|
||||
previewTarget: "food.home.actions",
|
||||
label: "咨询按钮",
|
||||
input: "text",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
const templateContent = JSON.parse(
|
||||
fs.readFileSync("../../packages/template-acheng-campus-food/template.json", "utf8"),
|
||||
);
|
||||
|
||||
// 根据真实声明生成完整列表数据,让每种内容区域都实际渲染。
|
||||
const additionalFoodTrust = templateContent.trustContentTypes
|
||||
.filter((item: { type: string }) => item.type !== "schedule")
|
||||
.map(
|
||||
(declaration: {
|
||||
type: string;
|
||||
label: string;
|
||||
configFields?: Array<{ key: string; input: string; itemFields?: Array<{ key: string }> }>;
|
||||
}) => ({
|
||||
id: "food-" + declaration.type,
|
||||
type: declaration.type,
|
||||
title: declaration.label,
|
||||
summary: "测试摘要",
|
||||
content: "测试正文",
|
||||
isPublished: true,
|
||||
sortOrder: 0,
|
||||
config: Object.fromEntries(
|
||||
(declaration.configFields ?? []).map((field) => [
|
||||
field.key,
|
||||
field.input === "list"
|
||||
? [
|
||||
Object.fromEntries(
|
||||
(field.itemFields ?? []).map((child) => [child.key, child.key + "测试值"]),
|
||||
),
|
||||
]
|
||||
: field.key + "测试值",
|
||||
]),
|
||||
),
|
||||
}),
|
||||
);
|
||||
runtimeWorkspace.trustItems.push(...additionalFoodTrust);
|
||||
|
||||
test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ page }) => {
|
||||
test.setTimeout(60000);
|
||||
let rejectOfferingSave = false;
|
||||
await page.setViewportSize({ width: 1920, height: 1000 });
|
||||
await page.route("http://localhost:3001/public/workspace**", (route) =>
|
||||
@@ -266,7 +222,9 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
if (url.pathname === "/admin/brands")
|
||||
return route.fulfill({ json: [{ id: brand.id, role: "owner", brand }] });
|
||||
if (url.pathname === "/admin/config/brand" && request.method() === "PATCH") {
|
||||
Object.assign(brand, request.postDataJSON());
|
||||
const patch = request.postDataJSON();
|
||||
if (patch.config) patch.config = { ...brand.config, ...patch.config };
|
||||
Object.assign(brand, patch);
|
||||
Object.assign(runtimeWorkspace.brand, brand);
|
||||
return route.fulfill({ json: brand });
|
||||
}
|
||||
@@ -309,7 +267,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
return route.fulfill({ json: adminOffering });
|
||||
}
|
||||
if (url.pathname === "/admin/config/trust-content")
|
||||
return route.fulfill({ json: [adminTrust] });
|
||||
return route.fulfill({ json: [adminTrust, ...additionalFoodTrust] });
|
||||
if (
|
||||
url.pathname === `/admin/config/trust-content/${adminTrust.id}` &&
|
||||
request.method() === "PATCH"
|
||||
@@ -439,17 +397,17 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
"data-selected-record-id",
|
||||
adminOffering.id,
|
||||
);
|
||||
await page.getByLabel("餐品名称").fill("编辑后的家庭餐");
|
||||
await page.getByLabel("名称", { exact: true }).fill("编辑后的家庭餐");
|
||||
await expect(page.getByText("有未保存修改", { exact: true })).toBeVisible();
|
||||
await page.getByText("出摊服务", { exact: true }).click();
|
||||
await expect(page.getByRole("dialog", { name: "有尚未保存的修改" })).toBeVisible();
|
||||
await page.getByRole("button", { name: "继续编辑" }).click();
|
||||
await expect(page.getByLabel("餐品名称")).toHaveValue("编辑后的家庭餐");
|
||||
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("编辑后的家庭餐");
|
||||
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
|
||||
rejectOfferingSave = true;
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("保存暂时失败,请重试", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("餐品名称")).toHaveValue("编辑后的家庭餐");
|
||||
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("编辑后的家庭餐");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
|
||||
await page.reload();
|
||||
@@ -492,9 +450,22 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await expect(preview.locator(".food-detail .bar button")).toBeVisible();
|
||||
await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/detail.png" });
|
||||
await expect(page.getByText("详情页由所选业务内容动态生成")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "点选编辑" })).toHaveCount(0);
|
||||
await expect(page.getByRole("button", { name: "点选编辑" })).toBeVisible();
|
||||
await expect(page.getByLabel("价格标题")).toHaveCount(0);
|
||||
await expect(page.getByLabel("餐品介绍")).toHaveCount(0);
|
||||
await page.getByRole("button", { name: "详情页咨询入口", exact: true }).click();
|
||||
await preview.locator(".food-detail .bar button").click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
|
||||
"data-selected-target",
|
||||
"acheng-campus-food.detail.action",
|
||||
);
|
||||
await page.getByLabel("咨询按钮文字", { exact: true }).fill("详情公共按钮回归");
|
||||
await expect(preview.locator(".food-detail .bar button")).toContainText("详情公共按钮回归");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await page.getByText("详情页", { exact: true }).click();
|
||||
await expect(preview.locator(".food-detail .bar button")).toContainText("详情公共按钮回归");
|
||||
await page.getByText("定制/咨询", { exact: true }).click();
|
||||
await expect(preview.locator(".inquiry-form .form-field")).toHaveCount(2);
|
||||
await expect(preview.locator(".inquiry-form")).toContainText("称呼");
|
||||
@@ -543,81 +514,178 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
path: "../../.codex-tasks/preview-proportion/menu-" + width + ".png",
|
||||
});
|
||||
}
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element) => {
|
||||
(element as HTMLElement).style.width = "";
|
||||
});
|
||||
const inspector = page.locator(".presentation-editor__inspector");
|
||||
for (const pageKey of [
|
||||
"home",
|
||||
"offerings",
|
||||
"profile",
|
||||
"service",
|
||||
"detail",
|
||||
"inquiry",
|
||||
"success",
|
||||
"records",
|
||||
]) {
|
||||
const label =
|
||||
templateContent.navigation.find((item: { page: string }) => item.page === pageKey)?.label ??
|
||||
(
|
||||
{ detail: "详情页", inquiry: "咨询页", success: "提交成功页", records: "记录页" } as Record<
|
||||
string,
|
||||
string
|
||||
>
|
||||
)[pageKey];
|
||||
await page.getByText(label, { exact: true }).click();
|
||||
await verifyCanvasTargets(page, templateContent, pageKey);
|
||||
for (const section of templateContent.admin.sections.filter(
|
||||
(item: { page: string }) => item.page === pageKey,
|
||||
)) {
|
||||
if (pageKey === "detail" && section.target !== "brand") continue;
|
||||
for (const target of section.previewTargets ?? []) {
|
||||
if (target.composite) continue;
|
||||
await page
|
||||
.locator(".presentation-editor__regions")
|
||||
.getByRole("button", { name: target.label, exact: true })
|
||||
.click();
|
||||
const fields = section.fields.filter(
|
||||
(field: { previewTarget: string }) => field.previewTarget === target.key,
|
||||
);
|
||||
for (const field of fields)
|
||||
await expect(
|
||||
inspector.locator(".ant-form-item-label").getByTitle(field.label, { exact: true }),
|
||||
).toBeVisible();
|
||||
}
|
||||
}
|
||||
if (pageKey !== "detail") {
|
||||
for (const declaration of templateContent.trustContentTypes.filter(
|
||||
(item: { pages: string[] }) => item.pages.includes(pageKey),
|
||||
)) {
|
||||
await page
|
||||
.locator(".presentation-editor__regions")
|
||||
.getByRole("button", { name: declaration.label, exact: true })
|
||||
.click();
|
||||
await expect(
|
||||
inspector.getByLabel(declaration.adminFields.title, { exact: true }),
|
||||
).toBeVisible();
|
||||
for (const field of declaration.configFields ?? []) {
|
||||
await expect(
|
||||
inspector.locator(".ant-form-item-label").getByTitle(field.label, { exact: true }),
|
||||
).toBeVisible();
|
||||
}
|
||||
}
|
||||
}
|
||||
for (const width of [320, 390]) {
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||
(element as HTMLElement).style.width = size + "px";
|
||||
}, width);
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview
|
||||
.locator(".component-template-preview__canvas")
|
||||
.evaluate((element) => element.scrollWidth - element.clientWidth),
|
||||
)
|
||||
.toBeLessThanOrEqual(1);
|
||||
await preview.screenshot({
|
||||
path:
|
||||
"../../.codex-tasks/template-audit-execution/raw/food-" + pageKey + "-" + width + ".png",
|
||||
});
|
||||
}
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element) => {
|
||||
(element as HTMLElement).style.width = "";
|
||||
});
|
||||
await preview.screenshot({
|
||||
path: "../../.codex-tasks/template-audit-execution/raw/food-" + pageKey + ".png",
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
test.setTimeout(60000);
|
||||
await page.setViewportSize({ width: 1600, height: 900 });
|
||||
const editorialBrand = {
|
||||
...structuredClone(brand),
|
||||
templateKey: "personal",
|
||||
avatarUrl: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||
config: {
|
||||
visualTemplateKey: "linjing-editorial",
|
||||
founder: "林境主理人",
|
||||
title: "建筑设计师",
|
||||
heroImage: "/assets/tab/home.png",
|
||||
heroImage: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||
homeHero: { title: "林境作品" },
|
||||
visualPresentation: {
|
||||
home: {
|
||||
proofEyebrow: "专业积累",
|
||||
proofTitle: "信任介绍",
|
||||
manifestoEyebrow: "工作方法",
|
||||
manifestoTitle: "专业方法",
|
||||
worksEyebrow: "代表项目",
|
||||
worksTitle: "作品与服务",
|
||||
worksAction: "查看作品",
|
||||
flowEyebrow: "合作方式",
|
||||
flowTitle: "合作流程",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const editorialPillars = [
|
||||
{ title: "比例与空间", desc: "根据建筑比例设计" },
|
||||
{ title: "材料与工艺", desc: "可验证的材料标准" },
|
||||
];
|
||||
const editorialFlow = [
|
||||
{ step: "01", name: "需求沟通", desc: "了解现场条件" },
|
||||
{ step: "02", name: "方案确认", desc: "明确交付范围" },
|
||||
{ step: "03", name: "制作安装", desc: "按方案实施" },
|
||||
{ step: "04", name: "验收跟进", desc: "长期维护" },
|
||||
];
|
||||
const editorialWorkspace = {
|
||||
...structuredClone(runtimeWorkspace),
|
||||
brand: {
|
||||
...structuredClone(runtimeWorkspace.brand),
|
||||
...editorialBrand,
|
||||
...editorialBrand.config,
|
||||
founder: "林境主理人",
|
||||
title: "建筑设计师",
|
||||
heroImage: "/assets/tab/home.png",
|
||||
heroImage: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||
homeHero: { title: "林境作品" },
|
||||
},
|
||||
offerings: [],
|
||||
trustItems: [],
|
||||
};
|
||||
const editorialContent = {
|
||||
displayName: "林境模板",
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "profile", page: "profile", label: "主理人与我" },
|
||||
offerings: structuredClone(runtimeWorkspace.offerings).map((item) => ({
|
||||
...item,
|
||||
coverUrl: "/assets/acheng-campus-food/owner/portrait.jpg",
|
||||
})),
|
||||
trustItems: [
|
||||
{
|
||||
id: "credential-fixture",
|
||||
type: "credential",
|
||||
title: "专业资历",
|
||||
summary: "建筑与门系统经验",
|
||||
content: "持续服务私宅项目",
|
||||
config: {
|
||||
pillars: editorialPillars,
|
||||
serviceFlow: editorialFlow,
|
||||
stats: [
|
||||
{ value: "10 年", label: "从业经验", sub: "持续服务私宅" },
|
||||
{ value: "200+", label: "项目落地", sub: "覆盖多个城市" },
|
||||
{ value: "30+", label: "合作品牌", sub: "长期协作" },
|
||||
{ value: "98%", label: "客户好评", sub: "来自真实反馈" },
|
||||
],
|
||||
},
|
||||
},
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
admin: {
|
||||
sections: [
|
||||
{
|
||||
key: "home",
|
||||
title: "首页主视觉",
|
||||
page: "home",
|
||||
target: "brand",
|
||||
previewTargets: [{ key: "editorial.home.hero", label: "首页主视觉" }],
|
||||
fields: [
|
||||
{
|
||||
key: "heroTitle",
|
||||
binding: "brand.config.homeHero.title",
|
||||
label: "首页标题",
|
||||
input: "text",
|
||||
previewTarget: "editorial.home.hero",
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
key: "identity",
|
||||
title: "主理人与联系方式",
|
||||
page: "profile",
|
||||
target: "brand",
|
||||
previewTargets: [
|
||||
{ key: "linjing-editorial.profile.identity", label: "主理人与联系方式" },
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
key: "founder",
|
||||
binding: "brand.config.founder",
|
||||
label: "主理人姓名",
|
||||
input: "text",
|
||||
previewTarget: "linjing-editorial.profile.identity",
|
||||
},
|
||||
],
|
||||
},
|
||||
trustPresentation: {
|
||||
pillars: editorialPillars,
|
||||
serviceFlow: editorialFlow,
|
||||
stats: [
|
||||
{ value: "10 年", label: "从业经验", sub: "持续服务私宅" },
|
||||
{ value: "200+", label: "项目落地", sub: "覆盖多个城市" },
|
||||
{ value: "30+", label: "合作品牌", sub: "长期协作" },
|
||||
{ value: "98%", label: "客户好评", sub: "来自真实反馈" },
|
||||
],
|
||||
},
|
||||
};
|
||||
const editorialContent = JSON.parse(
|
||||
fs.readFileSync("../../packages/template-linjing-editorial/template.json", "utf8"),
|
||||
);
|
||||
await page.route("**/api/**", (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const path = url.pathname.replace(/^\/api/, "");
|
||||
@@ -629,7 +697,34 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
return route.fulfill({
|
||||
json: [{ id: editorialBrand.id, role: "owner", brand: editorialBrand }],
|
||||
});
|
||||
if (path === "/admin/config/brand") return route.fulfill({ json: editorialBrand });
|
||||
if (path === "/admin/config/brand") {
|
||||
if (route.request().method() === "PATCH") {
|
||||
const patch = route.request().postDataJSON();
|
||||
if (patch.config) patch.config = { ...editorialBrand.config, ...patch.config };
|
||||
Object.assign(editorialBrand, patch);
|
||||
Object.assign(editorialWorkspace.brand, editorialBrand, editorialBrand.config);
|
||||
}
|
||||
return route.fulfill({ json: editorialBrand });
|
||||
}
|
||||
if (
|
||||
path === "/admin/config/trust-content/credential-fixture" &&
|
||||
route.request().method() === "PATCH"
|
||||
) {
|
||||
Object.assign(editorialWorkspace.trustItems[0], route.request().postDataJSON());
|
||||
Object.assign(editorialWorkspace.trustPresentation, editorialWorkspace.trustItems[0].config);
|
||||
return route.fulfill({ json: editorialWorkspace.trustItems[0] });
|
||||
}
|
||||
if (path === "/admin/workspace/offerings") return route.fulfill({ json: [adminOffering] });
|
||||
if (
|
||||
path === "/admin/workspace/offerings/" + adminOffering.id &&
|
||||
route.request().method() === "PATCH"
|
||||
) {
|
||||
Object.assign(adminOffering, route.request().postDataJSON());
|
||||
Object.assign(editorialWorkspace.offerings[0].presentation, adminOffering.config);
|
||||
return route.fulfill({ json: adminOffering });
|
||||
}
|
||||
if (path === "/admin/config/trust-content")
|
||||
return route.fulfill({ json: editorialWorkspace.trustItems });
|
||||
if (path === "/public/templates/personal")
|
||||
return route.fulfill({
|
||||
json: { name: "个人品牌", description: "林境模板", serviceCategories: [] },
|
||||
@@ -661,12 +756,154 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
|
||||
preview.locator(".hero-image").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
const stats = preview.locator('[data-editor-target="editorial.home.proof.stats"]');
|
||||
await expect(stats.locator(":scope > *")).toHaveCount(4);
|
||||
expect(
|
||||
await stats.evaluate(
|
||||
(element) => getComputedStyle(element).gridTemplateColumns.split(" ").length,
|
||||
),
|
||||
).toBe(2);
|
||||
await preview.screenshot({
|
||||
path: "../../.codex-tasks/template-audit-execution/raw/linjing-stats.png",
|
||||
});
|
||||
await stats.click();
|
||||
const inspector = page.locator(".presentation-editor__inspector");
|
||||
await expect(inspector.getByRole("heading", { name: "信任数据" })).toBeVisible();
|
||||
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("10 年");
|
||||
await expect(page.getByLabel("2. 说明")).toHaveValue("项目落地");
|
||||
await page.getByLabel("1. 数字或成果").fill("25 年");
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
|
||||
await inspector.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => editorialWorkspace.trustItems[0].config.stats[0].value).toBe("25 年");
|
||||
await preview.locator(".founder-name").click();
|
||||
await expect(inspector.getByRole("heading", { name: "主理人介绍", exact: true })).toBeVisible();
|
||||
for (const label of ["主理人姓名", "身份或职位", "主理人简介", "主理人标签"])
|
||||
await expect(inspector.getByLabel(label, { exact: true })).toBeVisible();
|
||||
await inspector.getByLabel("主理人简介").fill("跨页面共享的简介回归");
|
||||
await expect(preview.locator(".founder-copy .quote")).toContainText("跨页面共享的简介回归");
|
||||
await inspector.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect.poll(() => editorialBrand.description).toBe("跨页面共享的简介回归");
|
||||
await page.reload();
|
||||
await expect(preview.locator(".founder-copy .quote")).toContainText("跨页面共享的简介回归");
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("25 年");
|
||||
await page.getByRole("button", { name: "信任数据", exact: true }).click();
|
||||
await expect(page.getByLabel("1. 数字或成果")).toHaveValue("25 年");
|
||||
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
|
||||
await expect(page.getByLabel("首页标题")).toBeVisible();
|
||||
await expect(page.getByLabel("首页主标题")).toBeVisible();
|
||||
await page.getByLabel("设计理念", { exact: true }).fill("模板专属理念回归");
|
||||
await expect(preview.locator(".hero-slogan")).toContainText("模板专属理念回归");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".hero-slogan")).toContainText("模板专属理念回归");
|
||||
await page.getByRole("button", { name: "信任数据", exact: true }).click();
|
||||
await page.getByRole("button", { name: "下移第 1 项", exact: true }).click();
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("200+");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect.poll(() => editorialWorkspace.trustItems[0].config.stats[0].value).toBe("200+");
|
||||
await page.reload();
|
||||
await expect(stats.locator(".stat-value").first()).toContainText("200+");
|
||||
await preview.locator(".pillar-title").first().click();
|
||||
await expect(page.getByLabel("1. 方法说明")).toBeVisible();
|
||||
await page.getByLabel("1. 方法名称").fill("方法名称回归");
|
||||
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
|
||||
await preview.locator(".flow-name").first().click();
|
||||
await expect(page.getByLabel("1. 步骤编号")).toBeVisible();
|
||||
await expect(page.getByLabel("1. 步骤名称")).toBeVisible();
|
||||
await page.getByLabel("1. 步骤说明").fill("步骤说明回归");
|
||||
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
|
||||
await preview.locator(".work-card").click();
|
||||
for (const label of ["案例类别", "项目地点", "产品系列", "项目关键词"])
|
||||
await expect(inspector.getByText(label, { exact: true })).toBeVisible();
|
||||
await page.getByLabel("项目地点", { exact: true }).fill("项目地点回归");
|
||||
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
|
||||
await page.getByRole("button", { name: "保存此项内容" }).click();
|
||||
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
|
||||
await page.reload();
|
||||
await expect(preview.locator(".work-category")).toContainText("项目地点回归");
|
||||
await page.getByText("主理人与我", { exact: true }).click();
|
||||
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
|
||||
await preview.locator('[data-editor-target="linjing-editorial.profile.identity"]').click();
|
||||
await expect(page.getByRole("button", { name: "信任数据", exact: true })).toHaveCount(0);
|
||||
await expect(page.getByLabel("主理人姓名")).toBeVisible();
|
||||
await page.getByLabel("主理人姓名").fill("修改后的主理人");
|
||||
await expect(preview.locator(".editorial-profile .founder")).toContainText("修改后的主理人");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await page.getByRole("button", { name: "服务范围与适用对象", exact: true }).click();
|
||||
await expect(page.getByText("此区域尚未配置内容")).toBeVisible();
|
||||
await expect(page.getByRole("button", { name: "配置此区域内容" })).toBeVisible();
|
||||
for (const pageKey of [
|
||||
"home",
|
||||
"offerings",
|
||||
"profile",
|
||||
"detail",
|
||||
"inquiry",
|
||||
"success",
|
||||
"records",
|
||||
]) {
|
||||
const label =
|
||||
editorialContent.navigation.find((item: { page: string }) => item.page === pageKey)?.label ??
|
||||
(
|
||||
{ detail: "详情页", inquiry: "咨询页", success: "提交成功页", records: "记录页" } as Record<
|
||||
string,
|
||||
string
|
||||
>
|
||||
)[pageKey];
|
||||
await page.getByText(label, { exact: true }).click();
|
||||
await verifyCanvasTargets(page, editorialContent, pageKey);
|
||||
for (const section of editorialContent.admin.sections.filter(
|
||||
(item: { page: string }) => item.page === pageKey,
|
||||
)) {
|
||||
if (pageKey === "detail" && section.target !== "brand") continue;
|
||||
for (const target of section.previewTargets ?? []) {
|
||||
if (target.composite) continue;
|
||||
await page
|
||||
.locator(".presentation-editor__regions")
|
||||
.getByRole("button", { name: target.label, exact: true })
|
||||
.click();
|
||||
const fields = section.fields.filter(
|
||||
(field: { previewTarget: string }) => field.previewTarget === target.key,
|
||||
);
|
||||
for (const field of fields)
|
||||
await expect(
|
||||
inspector.locator(".ant-form-item-label").getByTitle(field.label, { exact: true }),
|
||||
).toBeVisible();
|
||||
}
|
||||
}
|
||||
for (const width of [320, 390]) {
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||
(element as HTMLElement).style.width = size + "px";
|
||||
}, width);
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview
|
||||
.locator(".component-template-preview__canvas")
|
||||
.evaluate((element) => element.scrollWidth - element.clientWidth),
|
||||
)
|
||||
.toBeLessThanOrEqual(1);
|
||||
await preview.screenshot({
|
||||
path:
|
||||
"../../.codex-tasks/template-audit-execution/raw/linjing-" +
|
||||
pageKey +
|
||||
"-" +
|
||||
width +
|
||||
".png",
|
||||
});
|
||||
}
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element) => {
|
||||
(element as HTMLElement).style.width = "";
|
||||
});
|
||||
await preview.screenshot({
|
||||
path: "../../.codex-tasks/template-audit-execution/raw/linjing-" + pageKey + ".png",
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user