Files
dacli/tests/unit/di_list_selector.test.ts
T
ssw 51ffaf00ba feat(dacli): hard-bind form smartProps, DI list enCode, codegen sub-table searchList, form info --bindings, test run dictionary mapping
- 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.
2026-07-23 13:59:11 +08:00

42 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { flattenDataInterfaceSelector } from '../../src/commands/di/list.ts'
describe('di list selector fallback', () => {
it('flattens interface leaves and keeps category folders out of the result', () => {
const result = flattenDataInterfaceSelector([
{
id: 'category-a',
category: '0',
fullName: '报名接口',
children: [
{ id: 'di-1', category: '1', enCode: 'statusQuery', fullName: '状态查询' },
{ id: 'di-2', category: 1, enCode: 'auditQuery', fullName: '审核查询' },
],
},
{ id: 'category-b', category: '0', children: [] },
])
expect(result).toEqual([
{ id: 'di-1', category: '1', enCode: 'statusQuery', fullName: '状态查询' },
{ id: 'di-2', category: 1, enCode: 'auditQuery', fullName: '审核查询' },
])
})
it('filters by keyword and applies pagination after flattening', () => {
const selector = [
{
category: '0',
children: [
{ id: 'di-1', category: '1', enCode: 'statusQuery', fullName: '状态查询' },
{ id: 'di-2', category: '1', enCode: 'auditQuery', fullName: '审核查询' },
{ id: 'di-3', category: '1', enCode: 'statusDetail', fullName: '状态详情' },
],
},
]
const all = flattenDataInterfaceSelector(selector)
const filtered = all.filter((item) => `${item.enCode} ${item.fullName}`.includes('status'))
expect(filtered.slice(1, 2).map((item) => item.id)).toEqual(['di-3'])
})
})