feat: 分离模板演示数据并校验预览资源

This commit is contained in:
que01 committed 2026-10-16 17:55:52 +08:00
1 parent 6edde5a8d6
commit b60174885e
31 files changed
+1785 -69

No files matched your search

@@ -30,11 +30,25 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
`
import 'reflect-metadata';
import { AdminTemplatePreviewService } from './dist/modules/admin/admin-template-preview.service.js';
import { AdminTemplatePreviewAssetsService } from './dist/modules/admin/admin-template-preview-assets.service.js';
import { execFileSync } from 'node:child_process';
import { createHash } from 'node:crypto';
import { mkdtempSync, readdirSync, readFileSync, rmSync } from 'node:fs';
import os from 'node:os';
import path from 'node:path';
let input = '';
for await (const chunk of process.stdin) input += chunk;
const version = JSON.parse(input);
const service = new AdminTemplatePreviewService({ templatePackageVersion: { findUnique: async () => version } });
process.stdout.write(JSON.stringify(await service.preview(version.id, 'personal')));
const temporary = mkdtempSync(path.join(os.tmpdir(), 'template-preview-browser-'));
try {
execFileSync(process.execPath, ['../../scripts/template-pack.cjs', '--template', version.packageKey, '--out', temporary], { stdio: 'ignore' });
const archive = readdirSync(temporary).find((file) => file.endsWith('.tar.gz'));
version.artifactPath = path.join(temporary, archive);
version.archiveChecksum = createHash('sha256').update(readFileSync(version.artifactPath)).digest('hex');
version.contentChecksum = JSON.parse(readFileSync(path.join(temporary, archive.slice(0, -7), 'checksums.json'), 'utf8')).contentChecksum;
const service = new AdminTemplatePreviewService({ templatePackageVersion: { findUnique: async () => version }, templatePackageAuditLog: { create: async () => ({}) } }, new AdminTemplatePreviewAssetsService());
process.stdout.write(JSON.stringify(await service.preview(version.id, 'personal', 'browser-fixture-admin')));
} finally { rmSync(temporary, { recursive: true, force: true }); }
`,
],
{ cwd: path.resolve("../api"), input: JSON.stringify(version), encoding: "utf8" },
@@ -70,8 +84,12 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
await expect(modal.getByText("预览测试失败,请重试")).toBeVisible();
await modal.getByRole("button", { name: /重试/ }).click();
await expect(modal.locator(".atelier-founder-name")).toHaveText(
manifest.sampleContent.personal.brandConfig.founder,
manifest.previewFixture.personal.content.brandConfig.founder,
);
await expect(modal.getByText("演示数据:独立预览内容")).toBeVisible();
await modal.getByText("资源诊断", { exact: true }).click();
await expect(modal.getByText("内容缺失", { exact: true }).first()).toBeVisible();
await expect(modal.getByText("包内资源已验证", { exact: true }).first()).toBeVisible();
const choosePage = async (label: string) => {
await modal.getByLabel("预览页面").click();
await page.locator(".ant-select-item-option-content").getByText(label, { exact: true }).click();
@@ -80,8 +98,13 @@ test("模板管理可重试预览,并切换我的、详情和禁止提交的
await expect(modal.locator(".component-template-preview")).toContainText("我的咨询记录");
await choosePage("业务详情");
await expect(modal.locator(".component-template-preview")).toContainText(
manifest.sampleContent.personal.offerings[0].name,
manifest.previewFixture.personal.content.offerings[0].name,
);
const caseImage = modal.locator('.component-template-preview img[src^="data:image/"]').first();
await expect(caseImage).toBeVisible();
await expect
.poll(() => caseImage.evaluate((image: HTMLImageElement) => image.naturalWidth))
.toBeGreaterThan(0);
await choosePage("咨询表单");
await expect(modal.locator(".inquiry-form")).toBeVisible();
await expect(modal.locator(".inquiry-form button").last()).toBeDisabled();