统一模板包 visual 契约并补齐完成证据;修复 release 版本一致性、管理员 token 撤销、CORS 与默认品牌配置;收敛依赖安全风险并完成全量回归验证。
221 lines
8.5 KiB
TypeScript
221 lines
8.5 KiB
TypeScript
import fs from "node:fs";
|
|
import { test, expect } from "@playwright/test";
|
|
|
|
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
|
const templateContent = JSON.parse(
|
|
fs.readFileSync("../../packages/template-acheng-campus-food/template.json", "utf8"),
|
|
);
|
|
const brand = {
|
|
id: "brand-fixture",
|
|
slug: "preview-fixture",
|
|
name: "预览品牌",
|
|
templateKey: "food",
|
|
tagline: "校园家常餐",
|
|
description: "认真做好每一餐",
|
|
avatarUrl: "",
|
|
coverUrl: "",
|
|
hours: "每日 17:00",
|
|
address: "东门附近",
|
|
deliveryNote: "提前预约",
|
|
contactPhone: "13800138000",
|
|
contactWechat: "food-example",
|
|
config: {
|
|
founder: "测试主理人",
|
|
title: "私房菜主理人",
|
|
heroImage: "",
|
|
visualPresentation: {},
|
|
},
|
|
};
|
|
const adminOffering = {
|
|
id: "menu-fixture",
|
|
kind: "service",
|
|
name: "家庭聚餐定制",
|
|
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
|
description: "餐品详情",
|
|
priceText: "88.88",
|
|
coverUrl: "",
|
|
isEnabled: true,
|
|
sortOrder: 0,
|
|
config: {
|
|
categoryKey: "private-chef",
|
|
categoryLabel: "私厨",
|
|
area: "东门",
|
|
series: "预约制",
|
|
spaceType: "8 人聚餐",
|
|
details: { background: "原餐品介绍", designConcept: "", crafts: [], materialsList: [] },
|
|
keywords: [],
|
|
},
|
|
};
|
|
const runtimeWorkspace = {
|
|
schemaVersion: "1.0.0",
|
|
publication: { status: "published", version: 1 },
|
|
brand: {
|
|
...brand,
|
|
...brand.config,
|
|
founder: brand.config.founder,
|
|
title: brand.config.title,
|
|
visualPresentation: {},
|
|
},
|
|
visualTemplate: {
|
|
key: "acheng-campus-food",
|
|
version: "1.0.3",
|
|
name: "阿成校园餐",
|
|
},
|
|
templateData: {},
|
|
navigation: { tabs: [] },
|
|
offerings: [
|
|
{
|
|
id: adminOffering.id,
|
|
name: adminOffering.name,
|
|
summary: adminOffering.summary,
|
|
priceText: adminOffering.priceText,
|
|
coverUrl: adminOffering.coverUrl,
|
|
presentation: {
|
|
categoryLabel: "私厨",
|
|
area: adminOffering.config.area,
|
|
series: adminOffering.config.series,
|
|
spaceType: adminOffering.config.spaceType,
|
|
keywords: [],
|
|
details: { ...adminOffering.config.details },
|
|
},
|
|
},
|
|
],
|
|
inquiryForms: [],
|
|
trustItems: [],
|
|
trustPresentation: {},
|
|
capabilities: [],
|
|
theme: { colors: {} },
|
|
};
|
|
|
|
test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ page }) => {
|
|
test.setTimeout(60000);
|
|
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/login")
|
|
return route.fulfill({
|
|
json: {
|
|
token: "fixture-token",
|
|
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();
|
|
const savedOffering = { ...adminOffering, ...savedBody };
|
|
Object.assign(adminOffering, structuredClone(savedOffering));
|
|
runtimeWorkspace.offerings[0] = {
|
|
...runtimeWorkspace.offerings[0],
|
|
name: adminOffering.name,
|
|
summary: adminOffering.summary,
|
|
priceText: adminOffering.priceText,
|
|
coverUrl: adminOffering.coverUrl,
|
|
presentation: structuredClone(adminOffering.config),
|
|
};
|
|
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 === "/public/templates/food")
|
|
return route.fulfill({
|
|
json: { name: "餐饮模板", description: "fixture", serviceCategories: [] },
|
|
});
|
|
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(".food-detail")).toContainText("家庭聚餐定制");
|
|
await expect(preview).toHaveAttribute(
|
|
"data-active-target",
|
|
"acheng-campus-food.detail.dishDetail",
|
|
);
|
|
await expect(preview).toHaveAttribute("data-active-record-id", adminOffering.id);
|
|
await expect(editor.locator(".service-offering-editor__view")).toContainText("详情内容");
|
|
await expect(page.getByText("正在核对详情展示")).toBeVisible();
|
|
|
|
await page.getByLabel("餐品介绍").fill("弹窗编辑后的餐品介绍");
|
|
await expect(preview.locator(".food-detail .body")).toContainText("弹窗编辑后的餐品介绍");
|
|
|
|
await page.getByText("列表卡片", { exact: true }).click();
|
|
await expect(preview.locator(".offering-card")).toContainText("家庭聚餐定制");
|
|
await expect(preview).toHaveAttribute("data-active-target", "acheng-campus-food.offerings.item");
|
|
await expect(page.getByText("正在核对列表展示")).toBeVisible();
|
|
|
|
await page.getByLabel("名称", { exact: true }).fill("列表实时预览餐品");
|
|
await expect(preview.locator(".offering-card")).toContainText("列表实时预览餐品");
|
|
|
|
await page.getByText("详情内容", { exact: true }).click();
|
|
await expect(preview.locator(".food-detail")).toContainText("列表实时预览餐品");
|
|
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
|
|
|
|
await page
|
|
.locator(".ant-modal-footer")
|
|
.getByRole("button", { name: "确 定", exact: true })
|
|
.click();
|
|
await expect(page.getByText("业务提供项已保存")).toBeVisible();
|
|
await page.locator(".ant-modal-wrap").waitFor({ state: "hidden" });
|
|
|
|
await page.getByRole("button", { name: "编辑详情" }).first().click();
|
|
await expect(page.locator(".component-template-preview")).toBeVisible();
|
|
|
|
await page.getByRole("button", { name: "在小程序页面编辑" }).click();
|
|
await expect(page.getByText("页面预览", { exact: true })).toBeVisible({ timeout: 15000 });
|
|
await page.getByText("首页业务卡片", { exact: true }).click();
|
|
await expect(
|
|
page.getByText("正在编辑业务提供项:列表实时预览餐品", { exact: true }),
|
|
).toBeVisible();
|
|
await page.getByLabel("名称", { exact: true }).fill("小程序页保存后的餐品");
|
|
await page.getByLabel("简介", { exact: true }).fill("跨入口保存后的业务简介");
|
|
await page.getByRole("button", { name: "保存此项内容" }).click();
|
|
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
|
|
expect(savedBody.name).toBe("小程序页保存后的餐品");
|
|
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
|
|
await page.goBack();
|
|
await expect(page.getByRole("heading", { name: "业务提供项", exact: true })).toBeVisible();
|
|
await page.getByRole("button", { name: "编辑详情" }).click();
|
|
await expect(page.getByLabel("名称", { exact: true })).toHaveValue("小程序页保存后的餐品");
|
|
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
|
|
await page
|
|
.locator(".ant-modal-footer")
|
|
.getByRole("button", { name: "确 定", exact: true })
|
|
.click();
|
|
await expect(page.getByText("业务提供项已保存")).toBeVisible();
|
|
expect(savedBody.name).toBe("小程序页保存后的餐品");
|
|
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
|
|
expect(savedBody.config.details.background).toBe("弹窗编辑后的餐品介绍");
|
|
});
|