刘光辉
2 小时以前 cf11e63b659afcc9792ab3e395f1b45d844431a8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { describe, expect, it, vi } from 'vitest';
 
import { applyDetailFieldMapping, processDetailData, resolveDetailTitle } from './detailData';
 
vi.mock('@jnpf/utils', () => ({
  getScriptFunc: vi.fn(() => ({ formData }) => {
    formData.dynamicItems = [{ dynamicName: '脚本生成的数据' }];
    return formData;
  }),
}));
 
describe('processDetailData', () => {
  it('uses the openDetail title and falls back to the default detail title', () => {
    expect(resolveDetailTitle('自定义详情标题', '详情')).toBe('自定义详情标题');
    expect(resolveDetailTitle('', '详情')).toBe('详情');
  });
 
  it('normalizes virtual child-table keys before processing custom detail data', async () => {
    const table = {
      controlKey: 'dynamicItems',
      __vModel__: '',
      __config__: {
        isVirtualField: true,
        jnpfKey: 'table',
        children: [
          {
            controlKey: 'dynamicName',
            __vModel__: '',
            __config__: { isVirtualField: true, isVirtualFieldInherited: true, isSubTable: true, jnpfKey: 'input' },
          },
        ],
      },
    };
    const formConf = {
      fields: [table],
      funcs: { customDetailData: true, customDetailDataFunc: 'custom detail script' },
    };
 
    const result = await processDetailData(formConf, {}, {});
 
    expect(table.__vModel__).toBe('dynamicItems');
    expect(table.__config__.children[0]?.__vModel__).toBe('dynamicName');
    expect(result.dynamicItems).toEqual([{ dynamicName: '脚本生成的数据' }]);
  });
 
  it('overrides raw detail values with explicitly mapped params', () => {
    const fields = [
      { __config__: { children: [] }, __vModel__: 'muban_mincheng' },
      { __config__: { children: [] }, __vModel__: 'shiyan_buzhou' },
    ];
    const formData = { muban_mincheng: '', shiyan_buzhou: '' };
    const params = { detail: { mubanMingcheng: '微生物限度检验模板', shiyanBuzhou: '按检验规程执行' } };
 
    const result = applyDetailFieldMapping(fields, formData, params, {
      muban_mincheng: 'detail.mubanMingcheng',
      shiyan_buzhou: 'detail.shiyanBuzhou',
    });
 
    expect(result).toEqual({ muban_mincheng: '微生物限度检验模板', shiyan_buzhou: '按检验规程执行' });
  });
});