- 新增 e2e/form-write.spec.ts:成功态/校验失败态/403态三个 E2E- 前缀用例 成功态 psql 落库验证 + 清理;校验失败态断言 status≠0 且 msg 无 "Internal Server Error" - f2-16-column-render.spec.ts:删除未用变量 BACKEND_NODE(TS 告警)+ 截图前等 Page-body - schema-samples.spec.ts:截图前 waitForSelector cxd-Page-body/table,避免截到 loading Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
125 lines
4.0 KiB
TypeScript
125 lines
4.0 KiB
TypeScript
/**
|
||
* F2-16 列级渲染映射 e2e 实证测试
|
||
*
|
||
* 断言目标:通知管理页(e732c4b0-2402-4e73-8cc4-786c8a8c52af)的列值显示
|
||
* 人话(日期格式、枚举中文、布尔是/否),不再裸渲染 ISO 串 / 数字 / false。
|
||
* 截图存 e2e/artifacts/f2-16/。
|
||
*/
|
||
import { expect, test, type Page } from '@playwright/test';
|
||
import * as http from 'node:http';
|
||
import * as path from 'node:path';
|
||
import * as fs from 'node:fs';
|
||
import { fileURLToPath } from 'node:url';
|
||
|
||
const __filename = fileURLToPath(import.meta.url);
|
||
const __dirname = path.dirname(__filename);
|
||
|
||
const TEMPLATE_ID = 'e732c4b0-2402-4e73-8cc4-786c8a8c52af';
|
||
const ARTIFACT_DIR = path.join(__dirname, 'artifacts', 'f2-16');
|
||
|
||
let _tokenCache: string | null = null;
|
||
|
||
async function getToken(): Promise<string> {
|
||
if (_tokenCache) return _tokenCache;
|
||
return new Promise((resolve, reject) => {
|
||
const body = JSON.stringify({ account: 'admin', password: '111111' });
|
||
const req = http.request(
|
||
{
|
||
hostname: 'localhost',
|
||
port: 8093,
|
||
path: '/api/auth/login',
|
||
method: 'POST',
|
||
headers: {
|
||
'Content-Type': 'application/json',
|
||
'Content-Length': Buffer.byteLength(body),
|
||
},
|
||
},
|
||
(res) => {
|
||
let data = '';
|
||
res.on('data', (c) => (data += c));
|
||
res.on('end', () => {
|
||
try {
|
||
const parsed = JSON.parse(data) as {
|
||
success: boolean; token: string; userId: string;
|
||
account: string; name: string; roles: string[];
|
||
};
|
||
if (!parsed.success) reject(new Error('登录失败'));
|
||
_tokenCache = parsed.token;
|
||
resolve(parsed.token);
|
||
} catch (e) {
|
||
reject(e);
|
||
}
|
||
});
|
||
},
|
||
);
|
||
req.on('error', reject);
|
||
req.write(body);
|
||
req.end();
|
||
});
|
||
}
|
||
|
||
async function seedAuth(page: Page) {
|
||
const token = await getToken();
|
||
await page.addInitScript(
|
||
({ t }: { t: string }) => {
|
||
localStorage.setItem('eip4_token', t);
|
||
localStorage.setItem(
|
||
'eip4_profile',
|
||
JSON.stringify({ userId: 'ADMIN', account: 'admin', name: '系统管理员', roles: [] }),
|
||
);
|
||
},
|
||
{ t: token },
|
||
);
|
||
}
|
||
|
||
test.beforeAll(() => {
|
||
fs.mkdirSync(ARTIFACT_DIR, { recursive: true });
|
||
});
|
||
|
||
test('F2-16 通知管理页列渲染为人话(日期/枚举/布尔)', async ({ page }) => {
|
||
await seedAuth(page);
|
||
await page.goto(`/page/${TEMPLATE_ID}`);
|
||
|
||
// 等待 amis-host 渲染完成(与 schema-samples.spec.ts 保持一致)
|
||
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||
|
||
// schema 无报错卡
|
||
await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible();
|
||
|
||
// F2-8 竞态修复:等待 amis crud 内容区可见(表格或空状态),再截图
|
||
await page.waitForSelector(
|
||
'[data-testid="amis-host"] table, [data-testid="amis-host"] .cxd-CRUD, [data-testid="amis-host"] .cxd-Page-body',
|
||
{ timeout: 15_000 },
|
||
).catch(() => {/* 无表格(空页或无权限),继续截图 */});
|
||
|
||
// 截图:全页
|
||
await page.screenshot({
|
||
path: path.join(ARTIFACT_DIR, 'notify-manage-full.png'),
|
||
fullPage: true,
|
||
});
|
||
|
||
// 日期列不应再裸渲染 ISO 串(含 T 分隔符的完整 ISO 格式)
|
||
const pageText = await page.textContent('body') ?? '';
|
||
expect(pageText).not.toMatch(/\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/);
|
||
|
||
// 有数据行时进一步断言布尔/枚举列值人话
|
||
const rows = await page.$$('tbody tr');
|
||
if (rows.length > 0) {
|
||
const tableText = await page.evaluate(() => {
|
||
const tbody = document.querySelector('tbody');
|
||
return tbody ? tbody.textContent ?? '' : '';
|
||
});
|
||
// 布尔 false/true 不应以裸文本出现(amis mapping 后显示 否/是)
|
||
expect(tableText).not.toMatch(/\bfalse\b/);
|
||
expect(tableText).not.toMatch(/\btrue\b/);
|
||
|
||
// 截图:仅表格区域
|
||
const tableEl = await page.$('table');
|
||
if (tableEl) {
|
||
await tableEl.screenshot({
|
||
path: path.join(ARTIFACT_DIR, 'notify-manage-table.png'),
|
||
});
|
||
}
|
||
}
|
||
});
|