- dacli/ 整目录被 .gitignore 忽略,本次 force-add 其业务源码(766 文件) - 排除 node_modules/.env(含 PGPASSWORD 等敏感信息)/.DS_Store/__pycache__/*.pyc - 新增 dacli/.gitignore 长期管理内部噪声,新增文件仍需 git add -f - 根 .gitignore 补充 .cache/ 与诊断脚本忽略,并加 dacli 段说明
82 lines
2.4 KiB
TypeScript
82 lines
2.4 KiB
TypeScript
/**
|
|
* vitest test: form/_validate.ts (Phase D2 E2E 自动化)
|
|
*
|
|
* 测试 validateBasicInfo/validateFormData/validateColumnData/validateFormCreate
|
|
* 触发条件: 纯函数测试, 无副作用
|
|
*/
|
|
import { describe, it, expect } from 'vitest'
|
|
import { validateFormCreate } from '../../../src/commands/form/_validate.ts'
|
|
|
|
describe('form/_validate.ts step machine', () => {
|
|
it('成功路径: 合法 fullName + enCode + tables + formData', () => {
|
|
const r = validateFormCreate({
|
|
fullName: '测试表单',
|
|
enCode: 'test_form_v1',
|
|
type: 1,
|
|
webType: 1,
|
|
tables: [{ table: 'test_table', tableName: '测试表' }],
|
|
formData: {
|
|
fields: [
|
|
{
|
|
__config__: { formId: 'f_name', label: '名称', layout: 'colFormItem' },
|
|
__vModel__: 'f_name',
|
|
},
|
|
],
|
|
},
|
|
columnData: { columnList: [] },
|
|
})
|
|
expect(r.ok).toBe(true)
|
|
})
|
|
|
|
it('enCode 含下划线开头 → VS030', () => {
|
|
const r = validateFormCreate({
|
|
fullName: 'X',
|
|
enCode: '_bad', // _xxx 允许, 但 _bad 不行 (正则不允许 _xxx 之外的 _ 开头)
|
|
type: 1,
|
|
webType: 1,
|
|
tables: [],
|
|
formData: { fields: [] },
|
|
columnData: { columnList: [] },
|
|
})
|
|
expect(r.steps.some((s) => s.errors.some((e) => e.code === 'VS030'))).toBe(true)
|
|
})
|
|
|
|
it('formData 空 → VS401', () => {
|
|
const r = validateFormCreate({
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
type: 1,
|
|
webType: 1,
|
|
tables: [],
|
|
formData: null,
|
|
columnData: { columnList: [] },
|
|
})
|
|
expect(r.steps.some((s) => s.errors.some((e) => e.code === 'VS401'))).toBe(true)
|
|
})
|
|
|
|
it('webType≠1 但 columnList 空 → VS402', () => {
|
|
const r = validateFormCreate({
|
|
fullName: 'X',
|
|
enCode: 'xtest',
|
|
type: 1,
|
|
webType: 2, // 表单+列表
|
|
tables: [],
|
|
formData: { fields: [{ __config__: { formId: 'x', label: 'x', layout: 'colFormItem' }, __vModel__: 'x' }] },
|
|
columnData: { columnList: [] }, // 空 → 错
|
|
})
|
|
expect(r.steps.some((s) => s.errors.some((e) => e.code === 'VS402'))).toBe(true)
|
|
})
|
|
|
|
it('fullName 空 → 拦截 (无 code, 必填校验)', () => {
|
|
const r = validateFormCreate({
|
|
fullName: '',
|
|
enCode: 'xtest',
|
|
type: 1,
|
|
webType: 1,
|
|
tables: [],
|
|
formData: { fields: [] },
|
|
columnData: { columnList: [] },
|
|
})
|
|
expect(r.ok).toBe(false)
|
|
})
|
|
}) |