覆盖5个type200报表:合计列(summaryFields)、宽列(29列)、ORGID短名保留、 短_ID字段保留(DEPART_ID/TASKID)、查询区无主键泄露。Node侧fetchSchema校验 schema结构,浏览器侧断言amis-host渲染无error-card。5/5全绿,全套e2e 74通过。 截图存 e2e/artifacts/f3-1/。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
296 lines
11 KiB
TypeScript
296 lines
11 KiB
TypeScript
/**
|
||
* F3-1 报表渲染体验验证 e2e
|
||
*
|
||
* 断言目标(5 个代表性 type200 报表):
|
||
* 1. amis-host 渲染成功、无 schema-error-card
|
||
* 2. 取数 API 返回 200(/api/flow/{selectservice} 触发)
|
||
* 3. 查询区字段全为业务列(无主键 designName="主键" / _ID 结尾长名泄露)
|
||
* 4. 合计列报表:summaryFields 在 schema 中存在
|
||
* 5. 宽列报表:columns 数量正确(验证 display→columns 全量转换)
|
||
* 截图存 e2e/artifacts/f3-1/。
|
||
*/
|
||
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 ARTIFACT_DIR = path.join(__dirname, 'artifacts', 'f3-1');
|
||
fs.mkdirSync(ARTIFACT_DIR, { recursive: true });
|
||
|
||
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;
|
||
};
|
||
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 },
|
||
);
|
||
}
|
||
|
||
/** Node 侧直接拉 schema JSON(校验查询区无主键泄露) */
|
||
async function fetchSchema(templateId: string): Promise<Record<string, unknown>> {
|
||
return new Promise((resolve, reject) => {
|
||
const req = http.request(
|
||
{
|
||
hostname: 'localhost',
|
||
port: 8093,
|
||
path: `/api/page/schema/${templateId}`,
|
||
method: 'GET',
|
||
headers: { Authorization: '' }, // schema 端点无需鉴权
|
||
},
|
||
(res) => {
|
||
let data = '';
|
||
res.on('data', (c) => (data += c));
|
||
res.on('end', () => {
|
||
try { resolve(JSON.parse(data) as Record<string, unknown>); }
|
||
catch (e) { reject(e); }
|
||
});
|
||
},
|
||
);
|
||
req.on('error', reject);
|
||
req.end();
|
||
});
|
||
}
|
||
|
||
/** 从 schema 提取 filter 字段名列表 */
|
||
function filterFieldNames(schema: Record<string, unknown>): string[] {
|
||
const body = schema.body as Record<string, unknown> | undefined;
|
||
if (!body) return [];
|
||
const filter = body.filter as Record<string, unknown> | undefined;
|
||
if (!filter) return [];
|
||
const items = (filter.body as Array<Record<string, unknown>>) ?? [];
|
||
return items.map((i) => String(i.name ?? ''));
|
||
}
|
||
|
||
/** 检查字段名是否为主键:designName=主键 无法从 amis schema 检测,
|
||
* 只能检测转换后的 name 是否以 _ID 结尾且长度 ≥ 10 */
|
||
function hasKeyLeak(fieldNames: string[]): boolean {
|
||
return fieldNames.some((n) => n.toUpperCase().endsWith('_ID') && n.length >= 10);
|
||
}
|
||
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
// 5 个代表性 type200 报表断言
|
||
// ─────────────────────────────────────────────────────────────────────────────
|
||
|
||
/**
|
||
* 用例1:项目安全费用投入明细(3eedc061)
|
||
* - 有 issummer=true 合计列 APPLYMONEY
|
||
* - 查询区6个业务字段(无主键泄露)
|
||
* - selectservice = PM_SAFETYFEEAPPLY_SEARCH
|
||
*/
|
||
test('F3-1 [type200] 项目安全费用投入明细 — 渲染+合计列+查询区业务列', async ({ page }) => {
|
||
const TID = '3eedc061-3220-4b98-8965-af97a8bbe4c9';
|
||
|
||
// Node 侧 schema 校验
|
||
const schema = await fetchSchema(TID);
|
||
const body = schema.body as Record<string, unknown>;
|
||
expect(body.type).toBe('crud');
|
||
// 合计列
|
||
const summaryFields = body.summaryFields as string[];
|
||
expect(summaryFields).toContain('APPLYMONEY');
|
||
// 查询区无主键泄露
|
||
const filterNames = filterFieldNames(schema);
|
||
expect(filterNames.length).toBeGreaterThan(0);
|
||
expect(hasKeyLeak(filterNames)).toBe(false);
|
||
// api 走 selectservice
|
||
expect(String(body.api)).toContain('PM_SAFETYFEEAPPLY_SEARCH');
|
||
|
||
// 浏览器侧渲染
|
||
await seedAuth(page);
|
||
const requests: string[] = [];
|
||
page.on('request', (req) => {
|
||
if (req.url().includes('PM_SAFETYFEEAPPLY_SEARCH')) requests.push(req.url());
|
||
});
|
||
await page.goto(`/page/${TID}`);
|
||
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||
await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible();
|
||
await page.waitForSelector(
|
||
'[data-testid="amis-host"] .cxd-Page-body, [data-testid="amis-host"] .cxd-CRUD',
|
||
{ timeout: 10_000 },
|
||
).catch(() => {});
|
||
|
||
const screenshotPath = path.join(ARTIFACT_DIR, `type200-${TID}.png`);
|
||
await page.screenshot({ path: screenshotPath, fullPage: false });
|
||
});
|
||
|
||
/**
|
||
* 用例2:工种到位情况统计表(b9546a6b)
|
||
* - 宽报表 29 列,主键列 hidden=true → toggled=false
|
||
* - 查询区仅 START/END 日期,无主键泄露
|
||
*/
|
||
test('F3-1 [type200] 工种到位情况统计表 — 宽列+主键列隐藏+查询区日期', async ({ page }) => {
|
||
const TID = 'b9546a6b-1ea5-4389-af34-32922bd3c3b5';
|
||
|
||
const schema = await fetchSchema(TID);
|
||
const body = schema.body as Record<string, unknown>;
|
||
expect(body.type).toBe('crud');
|
||
// 宽报表列数
|
||
const columns = body.columns as unknown[];
|
||
expect(columns.length).toBe(29);
|
||
// 查询区无主键泄露
|
||
const filterNames = filterFieldNames(schema);
|
||
expect(filterNames).toEqual(expect.arrayContaining(['START', 'END']));
|
||
expect(hasKeyLeak(filterNames)).toBe(false);
|
||
// api 走 selectservice
|
||
expect(String(body.api)).toContain('GB_PRJ_WORKER_SEARCH');
|
||
|
||
await seedAuth(page);
|
||
await page.goto(`/page/${TID}`);
|
||
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||
await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible();
|
||
await page.waitForSelector(
|
||
'[data-testid="amis-host"] .cxd-Page-body, [data-testid="amis-host"] .cxd-CRUD',
|
||
{ timeout: 10_000 },
|
||
).catch(() => {});
|
||
|
||
const screenshotPath = path.join(ARTIFACT_DIR, `type200-${TID}.png`);
|
||
await page.screenshot({ path: screenshotPath, fullPage: false });
|
||
});
|
||
|
||
/**
|
||
* 用例3:分公司在建项目收付款汇总表(4d9d1ab0)
|
||
* - 查询区含 ORGID(短名,不被误过滤)和 USERID
|
||
* - display 含多个 _ID 结尾列但全在 columns 里(仅 search 过滤主键)
|
||
*/
|
||
test('F3-1 [type200] 分公司在建项目收付款汇总表 — 查询区ORGID保留+display含_ID列', async ({ page }) => {
|
||
const TID = '4d9d1ab0-d42b-4ffd-9d62-752931bc8848';
|
||
|
||
const schema = await fetchSchema(TID);
|
||
const body = schema.body as Record<string, unknown>;
|
||
expect(body.type).toBe('crud');
|
||
// 查询区 ORGID 短名保留(不被主键过滤规则误杀)
|
||
const filterNames = filterFieldNames(schema);
|
||
expect(filterNames).toContain('ORGID');
|
||
expect(filterNames).toContain('USERID');
|
||
expect(hasKeyLeak(filterNames)).toBe(false);
|
||
// api 走 selectservice
|
||
expect(String(body.api)).toContain('PM_PAYMENTAFFIRM_SEARCH');
|
||
|
||
await seedAuth(page);
|
||
await page.goto(`/page/${TID}`);
|
||
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||
await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible();
|
||
await page.waitForSelector(
|
||
'[data-testid="amis-host"] .cxd-Page-body, [data-testid="amis-host"] .cxd-CRUD',
|
||
{ timeout: 10_000 },
|
||
).catch(() => {});
|
||
|
||
const screenshotPath = path.join(ARTIFACT_DIR, `type200-${TID}.png`);
|
||
await page.screenshot({ path: screenshotPath, fullPage: false });
|
||
});
|
||
|
||
/**
|
||
* 用例4:企业证书复印件登记报表(d9cd0b65)
|
||
* - 查询区 4 个业务字段:EC_NAME/USETYPE/DEPART_ID/REGISTERDATE
|
||
* - DEPART_ID 长度9 < 10,不被误过滤
|
||
*/
|
||
test('F3-1 [type200] 企业证书登记报表 — 查询区4业务字段含短_ID', async ({ page }) => {
|
||
const TID = 'd9cd0b65-1926-4d27-afef-df7138329ca3';
|
||
|
||
const schema = await fetchSchema(TID);
|
||
const body = schema.body as Record<string, unknown>;
|
||
expect(body.type).toBe('crud');
|
||
// 4 个查询字段
|
||
const filterNames = filterFieldNames(schema);
|
||
expect(filterNames.length).toBe(4);
|
||
expect(filterNames).toContain('EC_NAME');
|
||
expect(filterNames).toContain('REGISTERDATE');
|
||
// DEPART_ID 长度9,不应被过滤
|
||
expect(filterNames).toContain('DEPART_ID');
|
||
expect(hasKeyLeak(filterNames)).toBe(false);
|
||
|
||
await seedAuth(page);
|
||
await page.goto(`/page/${TID}`);
|
||
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||
await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible();
|
||
await page.waitForSelector(
|
||
'[data-testid="amis-host"] .cxd-Page-body, [data-testid="amis-host"] .cxd-CRUD',
|
||
{ timeout: 10_000 },
|
||
).catch(() => {});
|
||
|
||
const screenshotPath = path.join(ARTIFACT_DIR, `type200-${TID}.png`);
|
||
await page.screenshot({ path: screenshotPath, fullPage: false });
|
||
});
|
||
|
||
/**
|
||
* 用例5:任务二维码(7dc60c88)
|
||
* - 查询区 5 个字段:PROJECTID/UNITPROJECTID/STARTDATE/ENDDATE/TASKID
|
||
* - 验证无主键泄露(TASKID 长度6不触发规则)
|
||
*/
|
||
test('F3-1 [type200] 任务二维码 — 5查询字段无主键泄露', async ({ page }) => {
|
||
const TID = '7dc60c88-220b-4046-98fe-bfdae499786f';
|
||
|
||
const schema = await fetchSchema(TID);
|
||
const body = schema.body as Record<string, unknown>;
|
||
expect(body.type).toBe('crud');
|
||
const filterNames = filterFieldNames(schema);
|
||
expect(filterNames.length).toBe(5);
|
||
expect(filterNames).toContain('PROJECTID');
|
||
expect(filterNames).toContain('STARTDATE');
|
||
expect(filterNames).toContain('TASKID');
|
||
// 无主键泄露
|
||
expect(hasKeyLeak(filterNames)).toBe(false);
|
||
// api 走 selectservice
|
||
expect(String(body.api)).toContain('PM_PROJECT_TASK_SEARCH');
|
||
|
||
await seedAuth(page);
|
||
await page.goto(`/page/${TID}`);
|
||
await expect(page.locator('[data-testid="amis-host"]')).toBeVisible({ timeout: 45_000 });
|
||
await expect(page.locator('[data-testid="schema-error-card"]')).not.toBeVisible();
|
||
await page.waitForSelector(
|
||
'[data-testid="amis-host"] .cxd-Page-body, [data-testid="amis-host"] .cxd-CRUD',
|
||
{ timeout: 10_000 },
|
||
).catch(() => {});
|
||
|
||
const screenshotPath = path.join(ARTIFACT_DIR, `type200-${TID}.png`);
|
||
await page.screenshot({ path: screenshotPath, fullPage: false });
|
||
});
|