/** * tests/unit/field-builder-bs54.test.ts — BS-54 闭环 unit 测试 (v0.10+) * * 根因: jxcj v1.0 浏览器层 select 下拉框空白 (无 options) + * relationForm 弹窗不显示 (无 modelId). FieldBuilder.build() * 没补 dataType/options/modelId 默认值, 需用户手工写. * * 修复: FieldBuilder.build() 对 select/relationForm 字段自动补默认字段 * (dataType='static' + inline options; modelId='' 占位) * * 测试: * 1. select 字段 build() 后 __config__.dataType 必须存在 (默认 'static') * 2. select 字段 build() 后 options 数组必须有 ≥1 项 (默认 2 项占位) * 3. select 字段 build() 后 props.label/value 映射必须存在 (默认 fullName/id) * 4. relationForm 字段 build() 后 __config__.modelId key 必须存在 (空字符串占位) * 5. 用户传 --modelId 时, 该值透传 (不被默认覆盖) */ import { describe, it, expect } from 'vitest' import { FieldBuilder } from '../../src/schema/FieldBuilder.ts' describe('BS-54 FieldBuilder.build() select/relationForm 默认字段', () => { const fb = new FieldBuilder() it('select 字段: __config__.dataType 默认 = "static"', () => { const f = fb.build('select', { label: '状态下拉框' }) expect(f.__config__.dataType).toBe('static') }) it('select 字段: 不传 options 时, 自动补 ≥1 项 inline options', () => { const f = fb.build('select', { label: '类型' }) const opts = f.options as Array<{ id: string; fullName: string }> | undefined expect(opts).toBeDefined() expect(Array.isArray(opts)).toBe(true) expect(opts!.length).toBeGreaterThan(0) }) it('select 字段: 自动补 props.label="fullName", props.value="id"', () => { const f = fb.build('select', { label: '类型' }) const props = f.props as { label: string; value: string } | undefined expect(props).toBeDefined() expect(props!.label).toBe('fullName') expect(props!.value).toBe('id') }) it('select 字段: 用户传的 options 优先, 不被默认覆盖', () => { const custom = [{ fullName: 'A', id: 'a' }, { fullName: 'B', id: 'b' }, { fullName: 'C', id: 'c' }] const f = fb.build('select', { label: '类型', options: custom }) expect(f.options).toEqual(custom) }) it('relationForm 字段: __config__.modelId key 必须存在 (默认空字符串)', () => { const f = fb.build('relationForm', { label: '关联大赛' }) expect('modelId' in f.__config__).toBe(true) expect(f.__config__.modelId).toBe('') }) it('relationForm 字段: 用户传 modelId 时, 透传', () => { const f = fb.build('relationForm', { label: '关联大赛', __config__: { modelId: 'jxcj_competition_info' }, }) expect(f.__config__.modelId).toBe('jxcj_competition_info') }) })