Files
dacli/tests/e2e/baseline/workSystem/regression.spec.ts
T

93 lines
3.5 KiB
TypeScript

/**
* tests/e2e/baseline/workSystem/regression.spec.ts
*
* workSystem baseline 回归 (API 层 0 错):
* - switchapp 切到 workSystem
* - 拿 form list (真总数 85, v0.6 修 dacli list bug 前误报 52 是 /list 子端点强制 enableFlow=1 的子集)
* - 对每张 form 跑 info 验证 schema 完整
* - 汇总 PASS / FAIL
*
* 跑法: npx playwright test tests/e2e/baseline/workSystem/regression.spec.ts
*/
import { test, expect } from '@playwright/test'
import { execSync } from 'node:child_process'
const APP_CODE = 'workSystem'
interface FormRow { id: string; enCode: string; fullName: string; type: number; webType?: string }
function dacli(args: string): string {
return execSync(`npx tsx src/cli.ts ${args}`, {
encoding: 'utf-8',
cwd: process.cwd(),
})
}
test.describe.configure({ mode: 'serial' })
test(`switchapp ${APP_CODE} 成功`, () => {
dacli(`switchapp --appCode=${APP_CODE}`)
const st = dacli(`status`)
expect(st).toContain(APP_CODE)
})
test(`${APP_CODE} form list 返回 80+ 张 (v0.6 真总数)`, () => {
const out = dacli(`form list --limit=200 --json`)
const json = JSON.parse(out) as { list: FormRow[] }
// v0.6 修 dacli list bug 后真总数 85 (vs v0.5 误报 52 — 旧版走 /list 强制 enableFlow=1)
expect(json.list.length, `workSystem form 真总数应 ≥80, 实际 ${json.list.length}`).toBeGreaterThanOrEqual(80)
})
test('每张 form info 都能拿到完整 schema', () => {
const out = dacli(`form list --limit=200 --json`)
const json = JSON.parse(out) as { list: FormRow[] }
const forms = json.list || []
const results: { enCode: string; ok: boolean; err?: string }[] = []
for (const f of forms) {
try {
const infoOut = dacli(`form info ${f.id}`)
const info = JSON.parse(infoOut) as { fullName: string; formData: string | null; tables?: string }
if (!info.fullName) throw new Error('fullName 缺失')
// formData 可能是 null (视图 form) / 对象 (新格式) / 数组 (旧格式) / 空对象 — 都接受
if (info.formData) {
const formData = JSON.parse(info.formData) as { fields?: unknown[] } | unknown[]
if (Array.isArray(formData)) {
// 旧格式: formData 直接是 fields 数组 — 接受
} else if (formData && typeof formData === 'object') {
const fields = (formData as { fields?: unknown[] }).fields
// 接受: 数组 OR 缺失 (空 form)
if (fields !== undefined && !Array.isArray(fields)) {
throw new Error('formData.fields 非数组')
}
} else {
throw new Error('formData 既非对象也非数组')
}
}
// tables 校验
if (info.tables) {
const tables = JSON.parse(info.tables) as unknown[]
if (!Array.isArray(tables)) throw new Error('tables 非数组')
}
results.push({ enCode: f.enCode, ok: true })
} catch (e) {
results.push({ enCode: f.enCode, ok: false, err: (e as Error).message })
}
}
const okCount = results.filter((r) => r.ok).length
const failCount = results.length - okCount
console.log(` ✓ PASS: ${okCount}/${results.length}`)
if (failCount > 0) {
console.log(' ✗ FAIL:')
for (const r of results.filter((x) => !x.ok)) console.log(` - ${r.enCode}: ${r.err}`)
}
expect(failCount, `${failCount} 张表单 info 失败`).toBe(0)
})
test('workflow 列表非空', () => {
const out = dacli(`workflow list --json`)
const json = JSON.parse(out) as { list: unknown[] }
expect(json.list.length).toBeGreaterThanOrEqual(10)
})