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(); 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: "标志、字体、色彩与版式" }, ]); });