fix: 修复独立工坊业务详情区块字段过滤
This commit is contained in:
1 parent
61f216ae0e
commit
8f252d088a
15 files changed
+553
-145
No files matched your search
@@ -0,0 +1,370 @@
|
||||
import fs from "node:fs";
|
||||
import { test, expect, type Page } from "@playwright/test";
|
||||
|
||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||
const consoleWarnings = new WeakMap<Page, string[]>();
|
||||
|
||||
test.beforeEach(({ page }) => {
|
||||
const warnings: string[] = [];
|
||||
consoleWarnings.set(page, warnings);
|
||||
page.on("console", (message) => {
|
||||
const text = message.text();
|
||||
const isWarning =
|
||||
message.type() === "warning" ||
|
||||
(message.type() === "error" &&
|
||||
(text.startsWith("Warning:") ||
|
||||
text.includes("non-boolean attribute") ||
|
||||
text.includes("empty string")));
|
||||
if (isWarning) warnings.push(text);
|
||||
});
|
||||
});
|
||||
|
||||
test.afterEach(({ page }) => {
|
||||
expect(consoleWarnings.get(page) ?? []).toEqual([]);
|
||||
});
|
||||
|
||||
const templateContent = JSON.parse(
|
||||
fs.readFileSync("../../packages/template-atelier-solopreneur/template.json", "utf8"),
|
||||
);
|
||||
const brand = {
|
||||
id: "atelier-brand-fixture",
|
||||
slug: "atelier-preview-fixture",
|
||||
name: "独立工坊",
|
||||
templateKey: "personal",
|
||||
tagline: "为独立创作者建立可信的个人品牌",
|
||||
description: "品牌策略、视觉叙事与长期陪伴。",
|
||||
avatarUrl: "",
|
||||
coverUrl: "",
|
||||
hours: "工作日 10:00-18:00",
|
||||
address: "杭州",
|
||||
deliveryNote: "",
|
||||
contactPhone: "13800138000",
|
||||
contactWechat: "atelier-example",
|
||||
config: {
|
||||
founder: "林予",
|
||||
title: "品牌顾问",
|
||||
atelier: {
|
||||
identity: { status: "可预约", experience: "8 年经验", tags: [] },
|
||||
badges: [{ title: "真实案例" }],
|
||||
features: [],
|
||||
audiences: [],
|
||||
deliverables: [],
|
||||
process: [],
|
||||
proofs: [],
|
||||
faqs: [],
|
||||
},
|
||||
visualPresentation: {
|
||||
home: {
|
||||
eyebrow: "PERSONAL BRAND",
|
||||
title: "让专业被看见",
|
||||
subtitle: "从定位到表达",
|
||||
primaryAction: "预约沟通",
|
||||
secondaryAction: "查看案例",
|
||||
casesTitle: "试点案例",
|
||||
casesSubtitle: "真实项目",
|
||||
caseAction: "全部案例",
|
||||
featuresTitle: "合作方式",
|
||||
featuresEnglish: "METHOD",
|
||||
audienceTitle: "适合谁",
|
||||
audienceEnglish: "AUDIENCE",
|
||||
ctaTitle: "一起梳理品牌",
|
||||
ctaSubtitle: "先聊清楚目标",
|
||||
ctaAction: "发起咨询",
|
||||
},
|
||||
detail: {
|
||||
priceLabel: "合作方式",
|
||||
spaceLabel: "适用场景",
|
||||
backgroundTitle: "项目背景",
|
||||
conceptTitle: "设计理念",
|
||||
craftsTitle: "交付要点",
|
||||
materialsTitle: "能力构成",
|
||||
inquiryAction: "咨询这个案例",
|
||||
inquiryHint: "提交后会在工作台跟进",
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
const adminOffering = {
|
||||
id: "atelier-project-fixture",
|
||||
kind: "service",
|
||||
name: "山野茶品牌焕新",
|
||||
summary: "为在地茶品牌建立清晰、可信的视觉与叙事体系。",
|
||||
description: "案例详情说明",
|
||||
priceText: "¥ 30,000 起",
|
||||
coverUrl: "",
|
||||
isEnabled: true,
|
||||
sortOrder: 0,
|
||||
config: {
|
||||
categoryKey: "portfolio",
|
||||
categoryLabel: "品牌视觉",
|
||||
area: "杭州",
|
||||
series: "品牌焕新",
|
||||
spaceType: "线上与线下",
|
||||
keywords: ["个人品牌", "视觉叙事"],
|
||||
details: {
|
||||
background: "品牌已有稳定客群,但表达缺少统一线索。",
|
||||
designConcept: "以山野节气为线索,建立克制的视觉秩序。",
|
||||
crafts: ["品牌定位梳理", "视觉系统交付", "落地陪跑"],
|
||||
materialsList: [
|
||||
{ name: "品牌策略", spec: "定位、叙事与内容框架" },
|
||||
{ name: "视觉系统", spec: "标志、字体、色彩与版式" },
|
||||
],
|
||||
},
|
||||
detailHero: "",
|
||||
},
|
||||
};
|
||||
const runtimeWorkspace = {
|
||||
schemaVersion: "1.0.0",
|
||||
publication: { status: "published", version: 1 },
|
||||
brand: {
|
||||
...brand,
|
||||
...brand.config,
|
||||
visualPresentation: brand.config.visualPresentation,
|
||||
atelier: brand.config.atelier,
|
||||
},
|
||||
visualTemplate: {
|
||||
key: "atelier-solopreneur",
|
||||
version: templateContent.version,
|
||||
name: templateContent.displayName,
|
||||
},
|
||||
templateData: {},
|
||||
navigation: { tabs: [] },
|
||||
offerings: [
|
||||
{
|
||||
id: adminOffering.id,
|
||||
name: adminOffering.name,
|
||||
summary: adminOffering.summary,
|
||||
priceText: adminOffering.priceText,
|
||||
coverUrl: adminOffering.coverUrl,
|
||||
enabled: true,
|
||||
kind: adminOffering.kind,
|
||||
priceAmount: null,
|
||||
schemaKey: "personal-offering",
|
||||
schemaVersion: "1.0.0",
|
||||
presentation: {
|
||||
categoryKey: adminOffering.config.categoryKey,
|
||||
categoryLabel: adminOffering.config.categoryLabel,
|
||||
heroImage: adminOffering.config.detailHero,
|
||||
keywords: adminOffering.config.keywords,
|
||||
media: [],
|
||||
details: structuredClone(adminOffering.config.details),
|
||||
area: adminOffering.config.area,
|
||||
series: adminOffering.config.series,
|
||||
spaceType: adminOffering.config.spaceType,
|
||||
},
|
||||
sections: [],
|
||||
},
|
||||
],
|
||||
inquiryForms: [],
|
||||
trustItems: [],
|
||||
trustPresentation: {},
|
||||
capabilities: [],
|
||||
theme: { colors: {} },
|
||||
};
|
||||
|
||||
test("独立工坊业务编辑按真实 manifest 区块过滤字段", async ({ page }) => {
|
||||
test.setTimeout(90000);
|
||||
let savedBody: any;
|
||||
await page.setViewportSize({ width: 1920, height: 1000 });
|
||||
await page.route("**/api/**", async (route) => {
|
||||
const url = new URL(route.request().url());
|
||||
const path = url.pathname.replace(/^\/api/, "");
|
||||
if (path === "/admin/session/current")
|
||||
return route.fulfill({ status: 401, json: { error: { message: "未登录" } } });
|
||||
if (path === "/admin/session/login")
|
||||
return route.fulfill({
|
||||
json: {
|
||||
displayName: "测试管理员",
|
||||
role: "owner",
|
||||
mustChangePassword: false,
|
||||
},
|
||||
});
|
||||
if (path === "/admin/brands")
|
||||
return route.fulfill({ json: [{ id: brand.id, role: "owner", brand }] });
|
||||
if (path === "/admin/workspace/offerings")
|
||||
return route.fulfill({
|
||||
json: [{ ...adminOffering, config: structuredClone(adminOffering.config) }],
|
||||
});
|
||||
if (path === "/admin/workspace/forms") return route.fulfill({ json: [] });
|
||||
if (
|
||||
path === `/admin/workspace/offerings/${adminOffering.id}` &&
|
||||
route.request().method() === "PATCH"
|
||||
) {
|
||||
savedBody = route.request().postDataJSON();
|
||||
Object.assign(adminOffering, structuredClone(savedBody));
|
||||
runtimeWorkspace.offerings[0] = {
|
||||
...runtimeWorkspace.offerings[0],
|
||||
name: adminOffering.name,
|
||||
summary: adminOffering.summary,
|
||||
priceText: adminOffering.priceText,
|
||||
coverUrl: adminOffering.coverUrl,
|
||||
presentation: {
|
||||
...runtimeWorkspace.offerings[0].presentation,
|
||||
...structuredClone(adminOffering.config),
|
||||
details: structuredClone(adminOffering.config.details),
|
||||
heroImage: adminOffering.config.detailHero,
|
||||
},
|
||||
};
|
||||
return route.fulfill({ json: structuredClone(adminOffering) });
|
||||
}
|
||||
if (path === "/admin/workspace")
|
||||
return route.fulfill({
|
||||
json: {
|
||||
brand,
|
||||
installations: [],
|
||||
fields: [],
|
||||
offerings: [{ ...adminOffering, config: structuredClone(adminOffering.config) }],
|
||||
forms: [],
|
||||
templateContent,
|
||||
},
|
||||
});
|
||||
if (path === "/admin/config/brand") return route.fulfill({ json: brand });
|
||||
if (path === "/admin/workspace/preview")
|
||||
return route.fulfill({ json: structuredClone(runtimeWorkspace) });
|
||||
if (path === "/public/workspace")
|
||||
return route.fulfill({ json: structuredClone(runtimeWorkspace) });
|
||||
return route.fulfill({ json: {} });
|
||||
});
|
||||
|
||||
await page.goto(`${adminOrigin}/admin/services`);
|
||||
await page.getByLabel("账号").fill("admin");
|
||||
await page.getByLabel("密码").fill("fixture-password");
|
||||
await page.locator('button[type="submit"]').click();
|
||||
await page.getByRole("button", { name: "编辑详情" }).click();
|
||||
|
||||
const editor = page.locator(".service-offering-editor");
|
||||
const preview = editor.locator(".component-template-preview");
|
||||
await expect(preview.locator(".atelier-page")).toBeVisible();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectHero",
|
||||
);
|
||||
await expect(preview).toHaveAttribute("data-active-record-id", adminOffering.id);
|
||||
|
||||
// 头图与标题:只出现名称、简介、封面和详情主图,不出现案例信息或正文区块字段。
|
||||
await preview.locator(".atelier-title").click();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectHero",
|
||||
);
|
||||
await expect(page.getByText("正在编辑「案例头图与标题」", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("名称", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("一句话说明", { exact: true })).toBeVisible();
|
||||
await expect(editor.locator('[data-presentation-binding="offering.coverUrl"]')).toBeVisible();
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.detailHero"]'),
|
||||
).toBeVisible();
|
||||
await expect(page.getByLabel("价格展示", { exact: true })).toHaveCount(0);
|
||||
await expect(page.getByLabel("项目背景", { exact: true })).toHaveCount(0);
|
||||
await expect(page.getByLabel("交付要点", { exact: true })).toHaveCount(0);
|
||||
|
||||
// 案例信息:只出现报价与事实字段,标题、封面、详情主图消失。
|
||||
await preview.locator(".atelier-detail-facts .atelier-detail-value").first().click();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectFacts",
|
||||
);
|
||||
await expect(page.getByText("正在编辑「案例信息」", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("价格展示", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("案例类别", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("项目地点", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("方案名称", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("适用场景", { exact: true })).toBeVisible();
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.keywords"]'),
|
||||
).toBeVisible();
|
||||
await expect(page.getByLabel("名称", { exact: true })).toHaveCount(0);
|
||||
await expect(page.getByLabel("一句话说明", { exact: true })).toHaveCount(0);
|
||||
await expect(page.getByLabel("详情主图", { exact: true })).toHaveCount(0);
|
||||
|
||||
// 背景、理念、交付要点、能力构成分别只保留一个区块字段。
|
||||
await preview.getByText("品牌已有稳定客群,但表达缺少统一线索。").click();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectBackground",
|
||||
);
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.background"]'),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.designConcept"]'),
|
||||
).toHaveCount(0);
|
||||
await expect(page.getByLabel("价格展示", { exact: true })).toHaveCount(0);
|
||||
|
||||
await preview.getByText("以山野节气为线索,建立克制的视觉秩序。").click();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectConcept",
|
||||
);
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.designConcept"]'),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.background"]'),
|
||||
).toHaveCount(0);
|
||||
|
||||
await preview.getByText("品牌定位梳理").click();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectCrafts",
|
||||
);
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.crafts"]'),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.materialsList"]'),
|
||||
).toHaveCount(0);
|
||||
|
||||
await preview.getByText("品牌策略 定位、叙事与内容框架", { exact: true }).click();
|
||||
await expect(preview).toHaveAttribute(
|
||||
"data-active-target",
|
||||
"atelier-solopreneur.detail.projectMaterials",
|
||||
);
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.materialsList"]'),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.details.crafts"]'),
|
||||
).toHaveCount(0);
|
||||
|
||||
await preview.getByText("品牌已有稳定客群,但表达缺少统一线索。").click();
|
||||
await page.getByLabel("项目背景", { exact: true }).fill("弹窗里更新后的项目背景");
|
||||
await expect(preview.getByText("弹窗里更新后的项目背景", { exact: true })).toBeVisible();
|
||||
|
||||
// “查看全部字段”恢复完整表单。
|
||||
await page.getByRole("button", { name: "查看全部字段" }).click();
|
||||
await expect(page.getByLabel("名称", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("价格展示", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("项目背景", { exact: true })).toBeVisible();
|
||||
|
||||
// 列表卡片来自真实首页案例区域;右侧只显示名称、简介和封面。
|
||||
await page.getByText("列表卡片", { exact: true }).click();
|
||||
await expect(preview).toHaveAttribute("data-active-target", "atelier.home.case");
|
||||
await expect(preview).toHaveAttribute("data-active-record-id", adminOffering.id);
|
||||
await expect(editor.locator(".service-offering-editor__view")).toContainText("列表卡片");
|
||||
await expect(preview.locator(".atelier-case")).toContainText(adminOffering.name);
|
||||
await preview.locator(".atelier-case .atelier-card-title").click();
|
||||
await expect(page.getByText("正在编辑「试点案例卡片」", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("名称", { exact: true })).toBeVisible();
|
||||
await expect(page.getByLabel("一句话说明", { exact: true })).toBeVisible();
|
||||
await expect(editor.locator('[data-presentation-binding="offering.coverUrl"]')).toBeVisible();
|
||||
await expect(page.getByLabel("价格展示", { exact: true })).toHaveCount(0);
|
||||
await expect(
|
||||
editor.locator('[data-presentation-binding="offering.config.detailHero"]'),
|
||||
).toHaveCount(0);
|
||||
await expect(page.getByLabel("项目背景", { exact: true })).toHaveCount(0);
|
||||
|
||||
await page
|
||||
.locator(".ant-modal-footer")
|
||||
.getByRole("button", { name: "确 定", exact: true })
|
||||
.click();
|
||||
await expect(page.getByText("业务提供项已保存")).toBeVisible();
|
||||
expect(savedBody.name).toBe(adminOffering.name);
|
||||
expect(savedBody.config.details.background).toBe("弹窗里更新后的项目背景");
|
||||
expect(savedBody.config.details.designConcept).toBe("以山野节气为线索,建立克制的视觉秩序。");
|
||||
expect(savedBody.config.details.crafts).toEqual(["品牌定位梳理", "视觉系统交付", "落地陪跑"]);
|
||||
expect(savedBody.config.details.materialsList).toEqual([
|
||||
{ name: "品牌策略", spec: "定位、叙事与内容框架" },
|
||||
{ name: "视觉系统", spec: "标志、字体、色彩与版式" },
|
||||
]);
|
||||
});
|
||||
@@ -10,10 +10,10 @@ const businesses = [
|
||||
|
||||
const pageSchemes = [
|
||||
{
|
||||
templatePackageVersionId: "atelier-v132",
|
||||
templatePackageVersionId: "atelier-v133",
|
||||
name: "独立创作者画册",
|
||||
description: "个人品牌页面方案",
|
||||
version: "1.3.2",
|
||||
version: "1.3.3",
|
||||
supportedBusinessTypes: ["personal"],
|
||||
isLatestForPackage: true,
|
||||
},
|
||||
@@ -228,7 +228,7 @@ test("创建品牌成功后进入新品牌工作区", async ({ page }) => {
|
||||
name: "新的独立品牌",
|
||||
slug: "new-atelier",
|
||||
businessType: "personal",
|
||||
templatePackageVersionId: "atelier-v132",
|
||||
templatePackageVersionId: "atelier-v133",
|
||||
});
|
||||
await page.waitForURL("**/admin/overview");
|
||||
await expect(page.getByRole("heading", { name: "品牌概览" })).toBeVisible();
|
||||
@@ -268,7 +268,7 @@ test("创建品牌按业务类型过滤页面方案,失败后保留输入", as
|
||||
name: "测试独立品牌",
|
||||
slug: "test-atelier",
|
||||
businessType: "personal",
|
||||
templatePackageVersionId: "atelier-v132",
|
||||
templatePackageVersionId: "atelier-v133",
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -253,9 +253,14 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
|
||||
await page.getByRole("button", { name: "编辑详情" }).first().click();
|
||||
await expect(page.locator(".component-template-preview")).toBeVisible();
|
||||
|
||||
// 弹窗默认定位在详情页;跨入口编辑列表卡片前先切到列表并点选卡片,
|
||||
// 确保“在小程序页面编辑”携带的是首页列表区域而不是详情区域。
|
||||
await page.getByText("列表卡片", { exact: true }).click();
|
||||
await preview.locator(".offering-card .dish-name").click();
|
||||
await expect(page.getByText("业务卡片对应字段", { exact: true })).toBeVisible();
|
||||
await page.getByRole("button", { name: "在小程序页面编辑" }).click();
|
||||
await expect(page.getByText("页面预览", { exact: true })).toBeVisible({ timeout: 15000 });
|
||||
await page.getByText("首页业务卡片", { exact: true }).click();
|
||||
// 跳转时已按 targetKey 自动选中列表卡片区域,无需再手动点选页面区域。
|
||||
await expect(
|
||||
page.getByText("正在编辑业务提供项:列表实时预览餐品", { exact: true }),
|
||||
).toBeVisible();
|
||||
@@ -274,7 +279,7 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
|
||||
.locator(".ant-modal-footer")
|
||||
.getByRole("button", { name: "确 定", exact: true })
|
||||
.click();
|
||||
await expect(page.getByText("业务提供项已保存")).toBeVisible();
|
||||
await expect(page.getByText("业务提供项已保存").last()).toBeVisible();
|
||||
expect(savedBody.name).toBe("小程序页保存后的餐品");
|
||||
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
|
||||
expect(savedBody.config.details.background).toBe("弹窗编辑后的餐品介绍");
|
||||
|
||||
Reference in new issue
Block a user