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
62
63
64
65
66
| import { describe, expect, it, vi } from 'vitest';
|
| import { BATCH_ROWS_FIELD, createBatchFormConf } from './batchFormAdapter';
|
| function field(name: string, formId: string, extra: Record<string, any> = {}) {
| return {
| __vModel__: name,
| __config__: {
| formId,
| jnpfKey: 'input',
| label: name,
| span: 12,
| ...extra,
| },
| };
| }
|
| describe('batchFormAdapter', () => {
| it('creates a row-scoped table without mutating the released form config', () => {
| vi.spyOn(Date, 'now').mockReturnValue(1);
| const source: any = {
| fields: [field('name', 'f1'), field('code', 'f2')],
| batchConfig: {
| enabled: true,
| fieldOverrides: [
| { formId: 'f2', order: 0, readonly: true, visible: false, width: 240 },
| { formId: 'f1', order: 1 },
| ],
| },
| funcs: { beforeSubmit: 'original' },
| };
|
| const result = createBatchFormConf(source, [{ name: 'A' }], 'create');
| const table = result.fields[0];
|
| expect(source.fields[0]!.__config__.isSubTable).toBeUndefined();
| expect(table.__vModel__).toBe(BATCH_ROWS_FIELD);
| expect(table.batchMainForm).toBe(true);
| expect(table.__config__.children.map((item) => item.__vModel__)).toEqual(['code', 'name']);
| expect(table.__config__.children[0].disabled).toBe(true);
| expect(table.__config__.children[0].__config__).toMatchObject({ noShow: true, columnWidth: 240, parentVModel: BATCH_ROWS_FIELD });
| expect(result.funcs.beforeSubmit).toBe('');
| });
|
| it('uses list layout for nested layouts and disables copying while editing', () => {
| const source = {
| fields: [
| {
| __config__: {
| formId: 'row',
| jnpfKey: 'row',
| children: [field('name', 'f1')],
| },
| },
| ],
| batchConfig: { enabled: true, layout: 'table' },
| };
|
| const result = createBatchFormConf(source, [{ id: '1', name: 'A' }], 'edit');
| const table = result.fields[0];
|
| expect(table.layoutType).toBe('list');
| expect(table.columnBtnsList.find((item) => item.value === 'copy').show).toBe(false);
| expect(table.footerBtnsList.find((item) => item.value === 'add').show).toBe(false);
| });
| });
|
|