app-submit-order.test.mjs
2.7 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createFormEngine } from '../form-engine/core.js'
import { buildAppDailySavePayload } from '../form-engine/app-daily-save.js'
import {
buildAppDailyReportSubmitPayload,
buildAppNormalizedListsFromJsonContent
} from '../form-engine/app-subform-json.js'
const originChildren = [
{ key: 'F2-9-1', label: '交付专员', type: 'select', optionsKey: '4sStaffList' },
{ key: 'F2-9-2', label: '今日交车', type: 'numberInput' }
]
const formListWithChildren = [
{
key: 'F2-9',
label: '子表',
type: 'subform',
origin_children: originChildren,
children: [
[
{
key: 'F2-9-1',
type: 'select',
optionsKey: '4sStaffList',
value: '张三',
'F2-9-1': { id: 'uuid-1', name: '张三' }
},
{ key: 'F2-9-2', type: 'numberInput', value: 5 }
]
]
}
]
describe('app submit order (mixins.submitReport)', () => {
it('IT-APP-ORDER-001: lists from children then jsonContent as childrenValue', () => {
const listsViaStringify = buildAppNormalizedListsFromJsonContent(
JSON.stringify(formListWithChildren)
)
const payload = buildAppDailyReportSubmitPayload(formListWithChildren)
const parsed = JSON.parse(payload.jsonContent)
const sub = parsed.find(item => item.key === 'F2-9')
assert.ok(Array.isArray(formListWithChildren[0].children))
assert.equal(sub.children, undefined)
assert.ok(Array.isArray(sub.childrenValue) && sub.childrenValue.length > 0)
assert.deepEqual(payload.fieldDataList, listsViaStringify.fieldDataList)
assert.deepEqual(payload.subformDataList, listsViaStringify.subformDataList)
})
it('IT-APP-ORDER-002: buildAppDailySavePayload uses unified submit entry', () => {
const engine = createFormEngine({
list: [
{
key: 'F3-1',
label: '洽谈',
type: 'subform',
children: [[{ key: 'F3-1-3', type: 'select', optionsKey: '4sStaffList' }]]
}
]
})
engine.init(
{
list: [
{
key: 'F3-1',
label: '洽谈',
type: 'subform',
children: [[{ key: 'F3-1-3', type: 'select', optionsKey: '4sStaffList' }]]
}
]
},
{ baseSceneCode: 110201, brandIds: [3454] }
)
engine.setAppGroupFieldValue('F3-1', 0, 'F3-1-3', {
id: 'uuid-staff-003',
displayLabel: '王五'
})
const payload = buildAppDailySavePayload({ reportTemplateId: 10003, engine })
assert.equal(payload.fieldDataList.length, 0)
assert.ok(
payload.subformDataList.some(
item => item.columnFieldKey === 'F3-1-3' && item.parentFieldKey === 'F3-1'
)
)
const parsed = JSON.parse(payload.jsonContent)
assert.deepEqual(parsed[0].childrenValue[0]['F3-1']['F3-1-3'], {
text: '王五',
value: 'uuid-staff-003'
})
})
})