negotiation-summary-transform.test.mjs
3 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 { buildNegotiationSummaryTables } from '../form-engine/negotiation-summary-transform.js'
import { serializeFormListForAppJsonStorage } from '../form-engine/app-subform-json.js'
describe('negotiation summary transform', () => {
it('IT-SUMMARY-001: App jsonContent children dual-key → recordRows', () => {
const jsonContent = JSON.stringify([
{
key: 'F3-1',
label: '洽谈明细',
type: 'subform',
children: [
[
{
key: 'F3-1-3',
label: '推荐人',
type: 'select',
value: '张三',
'F3-1-3': 'uuid-staff-001'
},
{
key: 'F3-1-6',
label: '车型配置',
type: 'carBrandSelect',
value: '问界-鸿蒙-M7-增程版'
}
],
[
{
key: 'F3-1-3',
label: '推荐人',
type: 'select',
value: '李四',
'F3-1-3': 'uuid-staff-002'
},
{
key: 'F3-1-6',
label: '车型配置',
type: 'carBrandSelect',
value: '理想-L9-Max'
}
]
]
}
])
const sections = buildNegotiationSummaryTables(jsonContent)
assert.equal(sections.length, 1)
assert.equal(sections[0].label, '洽谈明细')
assert.equal(sections[0].recordRows.length, 2)
const row1Staff = sections[0].recordRows[0].fields.find(f => f.label === '推荐人')
assert.equal(row1Staff.value, '张三')
const row2Staff = sections[0].recordRows[1].fields.find(f => f.label === '推荐人')
assert.equal(row2Staff.value, '李四')
const row1Car = sections[0].recordRows[0].fields.find(f => f.label === '车型配置')
assert.equal(row1Car.value, '问界-鸿蒙-M7-增程版')
const row2Car = sections[0].recordRows[1].fields.find(f => f.label === '车型配置')
assert.equal(row2Car.value, '理想-L9-Max')
})
it('IT-SUMMARY-002: empty or invalid jsonContent → []', () => {
assert.deepEqual(buildNegotiationSummaryTables(''), [])
assert.deepEqual(buildNegotiationSummaryTables('not-json'), [])
assert.deepEqual(buildNegotiationSummaryTables(JSON.stringify([{ key: 'F3-1', type: 'radio' }])), [])
})
it('IT-SUMMARY-003: childrenValue jsonContent builds same summary as children', () => {
const withChildren = JSON.stringify([
{
key: 'F3-1',
label: '洽谈明细',
type: 'subform',
origin_children: [
{ key: 'F3-1-3', label: '推荐人', type: 'select' },
{ key: 'F3-1-6', label: '车型配置', type: 'carBrandSelect' }
],
children: [
[
{ key: 'F3-1-3', label: '推荐人', type: 'select', value: '张三' },
{ key: 'F3-1-6', label: '车型配置', type: 'carBrandSelect', value: '问界-M7' }
]
]
}
])
const withChildrenValue = JSON.stringify(
serializeFormListForAppJsonStorage(JSON.parse(withChildren))
)
const fromChildren = buildNegotiationSummaryTables(withChildren)
const fromChildrenValue = buildNegotiationSummaryTables(withChildrenValue)
assert.deepEqual(fromChildrenValue, fromChildren)
})
})