import { describe, expect, it } from 'vitest' import { normalizeCodegenSearchList } from '../../src/commands/form/_codegen_schema.ts' describe('codegen search-list schema repair', () => { it('fills missing search ids from columnList props before CodePreview', () => { const columnData = { columnList: [ { id: 'f_team_name', prop: 'f_team_name', label: '团队名称' }, { id: 'f_topic_direction', prop: 'f_topic_direction', label: '赛题方向' }, ], searchList: [ { label: '', __config__: { jnpfKey: 'input' } }, { label: '', __config__: { jnpfKey: 'select' } }, ], } const result = normalizeCodegenSearchList(columnData) expect(result.changed).toBe(2) expect(result.columnData.searchList).toEqual([ expect.objectContaining({ id: 'f_team_name', prop: 'f_team_name' }), expect.objectContaining({ id: 'f_topic_direction', prop: 'f_topic_direction' }), ]) }) it('uses form fields when a column entry is unavailable', () => { const result = normalizeCodegenSearchList( { searchList: [{ __config__: { jnpfKey: 'input' } }] }, { fields: [{ __vModel__: 'f_team_name', __config__: { label: '团队名称' } }] }, ) expect(result.changed).toBe(1) expect(result.columnData.searchList[0].id).toBe('f_team_name') expect(result.columnData.searchList[0].prop).toBe('f_team_name') }) it('repairs nested searchList entries inside children and tableList', () => { const columnData = { columnList: [ { id: 'f_team_name', prop: 'f_team_name', label: '团队名称' }, { id: 'f_topic_direction', prop: 'f_topic_direction', label: '赛题方向' }, ], searchList: [ { label: '', __config__: { jnpfKey: 'input' } }, ], children: [ { searchList: [ { label: '', __config__: { jnpfKey: 'select' } }, ], }, ], tableList: [ { searchList: [ { label: '', __config__: { jnpfKey: 'input' } }, { label: '', __config__: { jnpfKey: 'select' } }, ], }, ], } const result = normalizeCodegenSearchList(columnData) // Top-level: searchList[0] falls back to columnList[0] → f_team_name → 1 fix // children[0]: columnList=[] so falls back to fields; entry count 1 → 0 fix // tableList[0]: same as children → 0 fix expect(result.changed).toBe(1) expect(result.columnData.searchList[0].id).toBe('f_team_name') }) it('repairs nested entries with per-scope columnList fallback', () => { const columnData = { columnList: [ { id: 'f_team_name', prop: 'f_team_name', label: '团队名称' }, { id: 'f_topic_direction', prop: 'f_topic_direction', label: '赛题方向' }, ], searchList: [ { label: '', __config__: { jnpfKey: 'input' } }, ], children: [ { columnList: [ { id: 'f_topic_direction', prop: 'f_topic_direction', label: '赛题方向' }, ], searchList: [ { label: '', __config__: { jnpfKey: 'select' } }, ], }, ], tableList: [ { columnList: [ { id: 'f_team_name', prop: 'f_team_name', label: '团队名称' }, { id: 'f_topic_direction', prop: 'f_topic_direction', label: '赛题方向' }, ], searchList: [ { label: '', __config__: { jnpfKey: 'input' } }, { label: '', __config__: { jnpfKey: 'select' } }, ], }, ], } const result = normalizeCodegenSearchList(columnData) expect(result.changed).toBe(4) expect(result.columnData.searchList[0].id).toBe('f_team_name') expect(result.columnData.children[0].searchList[0].id).toBe('f_topic_direction') expect(result.columnData.tableList[0].searchList[0].id).toBe('f_team_name') expect(result.columnData.tableList[0].searchList[1].id).toBe('f_topic_direction') }) })