feat: 建立组件化模板预览基线并规划可视化编辑
This commit is contained in:
1 parent
c5af790554
commit
0b14b5a814
46 files changed
+1880
-427
No files matched your search
@@ -1,6 +1,6 @@
|
||||
import { test, expect } from "@playwright/test";
|
||||
|
||||
const adminOrigin = "http://localhost:3011";
|
||||
const adminOrigin = process.env.ADMIN_URL || "http://localhost:3005";
|
||||
const brand = {
|
||||
id: "brand-fixture",
|
||||
slug: "preview-fixture",
|
||||
@@ -8,7 +8,7 @@ const brand = {
|
||||
templateKey: "food",
|
||||
tagline: "校园家常餐",
|
||||
description: "认真做好每一餐",
|
||||
avatarUrl: "",
|
||||
avatarUrl: "/assets/owner/portrait.jpg",
|
||||
coverUrl: "",
|
||||
hours: "每日 17:00",
|
||||
address: "东门附近",
|
||||
@@ -35,7 +35,16 @@ const runtimeWorkspace = {
|
||||
},
|
||||
templateData: {},
|
||||
navigation: { tabs: [] },
|
||||
offerings: [],
|
||||
offerings: [
|
||||
{
|
||||
id: "menu-fixture",
|
||||
name: "家庭聚餐定制",
|
||||
summary: "为同学聚餐、家庭聚会提供常见的私房菜定制。",
|
||||
priceText: "88.88",
|
||||
coverUrl: brand.avatarUrl,
|
||||
presentation: { categoryLabel: "业务提供项", keywords: [], details: [] },
|
||||
},
|
||||
],
|
||||
inquiryForms: [],
|
||||
trustItems: [],
|
||||
trustPresentation: {},
|
||||
@@ -44,7 +53,10 @@ const runtimeWorkspace = {
|
||||
};
|
||||
const templateContent = {
|
||||
displayName: "餐饮模板",
|
||||
navigation: [{ key: "home", page: "home", label: "首页" }],
|
||||
navigation: [
|
||||
{ key: "home", page: "home", label: "首页" },
|
||||
{ key: "offerings", page: "offerings", label: "套餐餐品" },
|
||||
],
|
||||
assetSlots: [],
|
||||
trustContentTypes: [],
|
||||
admin: {
|
||||
@@ -88,6 +100,7 @@ const templateContent = {
|
||||
};
|
||||
|
||||
test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ page }) => {
|
||||
await page.setViewportSize({ width: 1920, height: 1000 });
|
||||
await page.route("http://localhost:3001/public/workspace**", (route) =>
|
||||
route.fulfill({ json: runtimeWorkspace }),
|
||||
);
|
||||
@@ -116,6 +129,8 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
return route.fulfill({
|
||||
json: { brand, installations: [], fields: [], offerings: [], forms: [], templateContent },
|
||||
});
|
||||
if (url.pathname === "/admin/workspace/preview")
|
||||
return route.fulfill({ json: runtimeWorkspace });
|
||||
if (url.pathname === "/public/templates/food")
|
||||
return route.fulfill({
|
||||
json: { name: "餐饮模板", description: "fixture", serviceCategories: [] },
|
||||
@@ -129,16 +144,75 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
|
||||
await page.getByLabel("密码").fill("fixture-password");
|
||||
await page.locator('button[type="submit"]').click();
|
||||
await expect(page.getByText("小程序页面配置")).toBeVisible();
|
||||
const frame = page.frameLocator('iframe[title="小程序页面预览"]');
|
||||
await expect(frame.locator(".food-home .name")).toContainText("测试主理人");
|
||||
await frame.locator('[data-editor-target="food.home.location"]').click();
|
||||
const preview = page.locator(".component-template-preview");
|
||||
await expect(preview.locator(".food-home .name")).toContainText("测试主理人");
|
||||
const dimensions = await preview.evaluate((element) => {
|
||||
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||
const name = element.querySelector(".name")!;
|
||||
const avatar = element.querySelector(".identity img")!;
|
||||
return {
|
||||
width: canvas.getBoundingClientRect().width,
|
||||
font: parseFloat(getComputedStyle(name).fontSize),
|
||||
avatar: avatar.getBoundingClientRect().width,
|
||||
transform: getComputedStyle(canvas.firstElementChild!).transform,
|
||||
};
|
||||
});
|
||||
expect(dimensions.font / dimensions.width).toBeCloseTo(32 / 750, 3);
|
||||
expect(dimensions.avatar / dimensions.width).toBeCloseTo(128 / 750, 3);
|
||||
expect(dimensions.transform).toBe("none");
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".identity img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
await preview.screenshot({ path: "../../.codex-tasks/preview-proportion/home.png" });
|
||||
const actionButtons = preview.locator(".food-home .actions button");
|
||||
await expect(actionButtons).toHaveCount(2);
|
||||
const previewBox = await preview.locator(".component-template-preview__canvas").boundingBox();
|
||||
const firstActionBox = await actionButtons.nth(0).boundingBox();
|
||||
const secondActionBox = await actionButtons.nth(1).boundingBox();
|
||||
expect(previewBox && firstActionBox && secondActionBox).toBeTruthy();
|
||||
expect(firstActionBox!.x).toBeGreaterThanOrEqual(previewBox!.x);
|
||||
expect(secondActionBox!.x + secondActionBox!.width).toBeLessThanOrEqual(
|
||||
previewBox!.x + previewBox!.width,
|
||||
);
|
||||
await expect(actionButtons.nth(0)).toContainText("咨询 / 预订");
|
||||
await expect(actionButtons.nth(1)).toContainText("查看餐品");
|
||||
await preview.locator('[data-editor-target="food.home.location"]').click();
|
||||
await expect(page.getByText("出摊信息标题")).toBeVisible();
|
||||
await expect(page.getByText("招牌餐品标题")).toHaveCount(0);
|
||||
await page.getByLabel("出摊信息标题").fill("后台草稿地点");
|
||||
await expect(preview.locator(".notice-title")).toContainText("后台草稿地点");
|
||||
await page.getByRole("button", { name: "保存页面内容" }).click();
|
||||
await expect(page.getByText("页面内容已保存为草稿,发布后小程序才会更新")).toBeVisible();
|
||||
await expect(frame.locator(".notice-title")).toContainText("后台草稿地点");
|
||||
await expect(frame.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
||||
await expect(preview.locator('[data-editor-target="food.home.location"]')).toHaveClass(
|
||||
/editor-target-selected/,
|
||||
);
|
||||
await page.getByText("套餐餐品", { exact: true }).click();
|
||||
await expect(preview.locator(".offering-card")).toHaveCount(1);
|
||||
await expect
|
||||
.poll(() =>
|
||||
preview.locator(".dish-media img").evaluate((image: HTMLImageElement) => image.naturalWidth),
|
||||
)
|
||||
.toBeGreaterThan(0);
|
||||
for (const width of [390, 320]) {
|
||||
await preview.locator(".component-template-preview__canvas").evaluate((element, size) => {
|
||||
(element as HTMLElement).style.width = size + "px";
|
||||
}, width);
|
||||
const layout = await preview.evaluate((element) => {
|
||||
const canvas = element.querySelector(".component-template-preview__canvas")!;
|
||||
const card = element.querySelector(".offering-card")!;
|
||||
const media = element.querySelector(".dish-media")!;
|
||||
return {
|
||||
canvas: canvas.getBoundingClientRect().width,
|
||||
overflow: card.scrollWidth - card.clientWidth,
|
||||
media: media.getBoundingClientRect().width,
|
||||
};
|
||||
});
|
||||
expect(layout.overflow).toBeLessThanOrEqual(1);
|
||||
expect(layout.media / layout.canvas).toBeCloseTo(224 / 750, 3);
|
||||
await preview.screenshot({
|
||||
path: "../../.codex-tasks/preview-proportion/menu-" + width + ".png",
|
||||
});
|
||||
}
|
||||
});
|
||||
Reference in new issue
Block a user