feat: 完成模板预览隔离与矩阵验收

This commit is contained in:
que01 committed 2026-10-16 20:36:57 +08:00
1 parent d38dbe02aa
commit 5bf54096be
13 files changed
+287 -19

No files matched your search

@@ -1,4 +1,6 @@
import assert from "node:assert/strict";
import fs from "node:fs";
import { mkdirSync } from "node:fs";
import path from "node:path";
import { execFileSync } from "node:child_process";
import { test, expect } from "@playwright/test";
@@ -61,6 +63,12 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
});
let attempts = 0;
const writes: string[] = [];
const evidenceDirectory = process.env.TEMPLATE_PREVIEW_VISUAL_EVIDENCE;
const captureVisualEvidence = async (name: string) => {
if (!evidenceDirectory) return;
mkdirSync(evidenceDirectory, { recursive: true });
await page.screenshot({ path: path.join(evidenceDirectory, `${name}.png`) });
};
await page.route("**/api/**", async (route) => {
const url = new URL(route.request().url());
if (route.request().method() !== "GET") writes.push(url.pathname);
@@ -78,7 +86,13 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
if (url.pathname.endsWith("/admin/brands")) return route.fulfill({ json: [] });
return route.fulfill({ json: { name: "测试工作区" } });
});
await page.goto(`${process.env.ADMIN_URL || "http://localhost:3016"}/admin/templates`);
const adminPage = await page.goto(
`${process.env.ADMIN_URL || "http://localhost:3016"}/admin/templates`,
);
const contentSecurityPolicy = adminPage?.headers()["content-security-policy"];
assert.match(contentSecurityPolicy ?? "", /default-src 'self'/);
assert.match(contentSecurityPolicy ?? "", /img-src [^;]*data:/);
assert.match(contentSecurityPolicy ?? "", /frame-ancestors 'self'/);
await page.getByRole("button", { name: /预览/ }).click();
const modal = page.getByRole("dialog");
await expect(modal.getByText("预览测试失败,请重试")).toBeVisible();
@@ -90,12 +104,26 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
await modal.getByText("资源诊断", { exact: true }).click();
await expect(modal.getByText("内容缺失", { exact: true }).first()).toBeVisible();
await expect(modal.getByText("包内资源已验证", { exact: true }).first()).toBeVisible();
await captureVisualEvidence("home");
const choosePage = async (label: string) => {
await modal.getByLabel("预览页面").click();
await page.locator(".ant-select-item-option-content").getByText(label, { exact: true }).click();
};
// 画布内真实 CTA 导航:首页案例进入详情,详情咨询进入表单。
await modal.locator(".atelier-case").first().click();
await expect(modal.locator(".atelier-detail-action")).toBeVisible();
await captureVisualEvidence("detail");
await modal.locator(".atelier-detail-action button").first().click();
await expect(modal.locator(".inquiry-form")).toBeVisible();
await captureVisualEvidence("inquiry");
await modal.getByLabel("预览页面").click();
await page.locator(".ant-select-item-option-content").getByText("首页", { exact: true }).click();
await modal.getByText("资源诊断", { exact: true }).click();
await expect(modal.getByText("内容缺失", { exact: true }).first()).toBeVisible();
await expect(modal.getByText("包内资源已验证", { exact: true }).first()).toBeVisible();
await choosePage("我的");
await expect(modal.locator(".component-template-preview")).toContainText("我的咨询记录");
await captureVisualEvidence("profile");
await choosePage("业务详情");
await expect(modal.locator(".component-template-preview")).toContainText(
manifest.previewFixture.personal.content.offerings[0].name,