- form create: extract applyFinalSmartProps/shouldRunFinalSmartProps so
--ai-only paths also re-run smart props after the final buildFormData.
Adds unit test for the gate predicate.
- form update: mergeFormFieldUpdates deep-merges __config__ and matches
vmodel/__vModel__, preventing schema loss on partial diffs.
- form info: new --bindings projection flattens field configs to
{field, jnpfKey, dataType, dictionaryType, modelId, required} for
callers without jq piercing the JNPF nested formData JSON.
- form codegen: normalizeCodegenSearchList now walks children/tableList
payloads; new _codegen_schema helper repairs searchList id/prop across
nested scopes, avoiding SearchTypeModel.id NPE in JNPF CodeGenerateFactoryV3.
- di list: enrichDataInterfaceListWithEnCode backfills the enCode field
selector omits; walks every category folder so callers can filter on
enCode reliably.
- test run: pickChoiceValue routes select/radio/checkbox through
loadDict.getDictionaryDataSelector (cached) before falling back to
options[0].value, removing the brittle dependency on option order.
Tests: 56/56 PASS across 9 unit specs.
114 lines
3.9 KiB
TypeScript
114 lines
3.9 KiB
TypeScript
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')
|
|
})
|
|
})
|