本仓 2026-08-12 从 ssw main (192.168.1.18:13300/ssw/ssw-mvp) 的 dacli/ subpath 抽取,作为独立仓托管到 gitea:3000/ssw/dacli.git。 - 工作树为 ssw main dacli subpath 最新版 (110 commit, 08-12) - 历史未带 ssw main 整体历史(避免大仓污染) - 此为新仓基线 commit,未来以本仓历史为主
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)
|
|
})
|
|
}) |