fix: 修复模板画布点选与保存切页回归

This commit is contained in:
que01 committed 2026-10-18 13:40:01 +08:00
1 parent e6d843b4a7
commit cd2992c00a
15 files changed
+98 -40

No files matched your search

+38 -18
View File
@@ -33,6 +33,7 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
for (let index = 0; index < (await elements.count()); index++) {
const element = elements.nth(index);
if (!(await element.isVisible())) continue;
await element.scrollIntoViewIfNeeded();
const leafIndex = await element.evaluate((node, key) => {
return Array.from(node.querySelectorAll("*")).findIndex((child) => {
const rect = child.getBoundingClientRect();
@@ -40,7 +41,11 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
child.childElementCount === 0 &&
rect.width > 0 &&
rect.height > 0 &&
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key
child.closest("[data-editor-target]")?.getAttribute("data-editor-target") === key &&
document
.elementFromPoint(rect.left + rect.width / 2, rect.top + rect.height / 2)
?.closest("[data-editor-target]")
?.getAttribute("data-editor-target") === key
);
});
}, target);
@@ -61,6 +66,19 @@ async function verifyCanvasTargets(page: Page, manifest: any, pageKey: string) {
};
});
expect(point.target, "实际命中区域:" + target).toBe(target);
const originalNode = await content.elementHandle();
expect(originalNode).not.toBeNull();
await page.mouse.move(point.x, point.y);
await expect
.poll(() =>
preview
.locator(".component-template-preview__outline")
.evaluateAll((outlines) =>
outlines.every((outline) => getComputedStyle(outline).pointerEvents === "none"),
),
)
.toBe(true);
expect(await originalNode!.evaluate((node) => node.isConnected)).toBe(true);
await page.mouse.click(point.x, point.y);
await expect(
preview.locator(".component-template-preview__outline.is-selected"),
@@ -161,6 +179,7 @@ const runtimeWorkspace = {
trustItems: [{ ...adminTrust }],
trustPresentation: {},
capabilities: [],
plugins: [{ key: "inquiry", status: "enabled", config: {} }],
theme: { colors: {} },
};
const templateContent = JSON.parse(
@@ -390,9 +409,10 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
);
await page.keyboard.press("Escape");
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveCount(0);
await page.getByText("套餐餐品", { exact: true }).click();
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
await expect(page.getByRole("dialog", { name: "有尚未保存的修改" })).toHaveCount(0);
await expect(preview.locator(".offering-card")).toHaveCount(1);
await preview.locator('[data-editor-target="acheng-campus-food.offerings.item"]').click();
await preview.locator(".offering-card .dish-name").click();
await expect(preview.locator(".component-template-preview__outline.is-selected")).toHaveAttribute(
"data-selected-record-id",
adminOffering.id,
@@ -411,7 +431,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect.poll(() => adminOffering.name).toBe("编辑后的家庭餐");
await page.reload();
await page.getByText("套餐餐品", { exact: true }).click();
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
await expect(preview.locator(".offering-card")).toContainText("编辑后的家庭餐");
await page.getByText("出摊服务", { exact: true }).click();
await preview.locator('[data-editor-target="trust:schedule"]').click();
@@ -487,7 +507,7 @@ test("Admin 按通用预览目标筛选字段并同步品牌草稿", async ({ pa
await page.getByText("记录页", { exact: true }).click();
await expect(preview.locator(".records-page")).toBeVisible();
await expect(preview.locator(".records-page")).toContainText("请在微信小程序内登录查看");
await page.getByText("套餐餐品", { exact: true }).click();
await page.locator("label.ant-segmented-item").filter({ hasText: "套餐餐品" }).click();
await page.getByRole("button", { name: "点选编辑" }).click();
await expect
.poll(() =>
@@ -769,9 +789,9 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
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(page.getByLabel("数字或成果", { exact: true }).nth(0)).toHaveValue("10 年");
await expect(page.getByLabel("说明", { exact: true }).nth(1)).toHaveValue("项目落地");
await page.getByLabel("数字或成果", { exact: true }).nth(0).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 年");
@@ -787,7 +807,7 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
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 expect(page.getByLabel("数字或成果", { exact: true }).nth(0)).toHaveValue("25 年");
await preview.locator('[data-editor-target="editorial.home.hero"]').click();
await expect(page.getByLabel("首页主标题")).toBeVisible();
await page.getByLabel("设计理念", { exact: true }).fill("模板专属理念回归");
@@ -804,20 +824,20 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
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(page.getByLabel("方法说明", { exact: true }).nth(0)).toBeVisible();
await page.getByLabel("方法名称", { exact: true }).nth(0).fill("方法名称回归");
await expect(preview.locator(".pillar-title").first()).toContainText("方法名称回归");
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
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(page.getByLabel("步骤编号", { exact: true }).nth(0)).toBeVisible();
await expect(page.getByLabel("步骤名称", { exact: true }).nth(0)).toBeVisible();
await page.getByLabel("步骤说明", { exact: true }).nth(0).fill("步骤说明回归");
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
await page.getByRole("button", { name: "保存此项内容" }).click();
await expect(page.getByText("内容已保存为草稿,发布后访客才会看到更新")).toBeVisible();
await expect(page.getByText("已保存内容草稿,发布后访客才会看到更新")).toBeVisible();
await page.reload();
await expect(preview.locator(".flow-desc").first()).toContainText("步骤说明回归");
await preview.locator(".work-card").click();
@@ -826,12 +846,12 @@ test("林境模板支持首页和主理人区域点选", async ({ page }) => {
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 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 preview.locator(".editorial-profile .founder").click();
await expect(page.getByRole("button", { name: "信任数据", exact: true })).toHaveCount(0);
await expect(page.getByLabel("主理人姓名")).toBeVisible();
await page.getByLabel("主理人姓名").fill("修改后的主理人");
@@ -179,7 +179,10 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
await expect(preview.locator(".food-detail")).toContainText("列表实时预览餐品");
await expect(page.getByLabel("餐品介绍")).toHaveValue("弹窗编辑后的餐品介绍");
await page.locator(".ant-modal-footer").getByRole("button", { name: "OK" }).click();
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" });
@@ -199,11 +202,14 @@ test("业务编辑弹窗预览列表与详情详情同一份内容", async ({ pa
expect(savedBody.name).toBe("小程序页保存后的餐品");
expect(savedBody.summary).toBe("跨入口保存后的业务简介");
await page.goBack();
await expect(page.getByText("小程序内容:业务展示与详情")).toBeVisible();
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: "OK" }).click();
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("跨入口保存后的业务简介");