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: '按检验规程执行' });
|
});
|
});
|