field-submit-value.test.mjs
3.45 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
96
97
98
99
100
101
102
103
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
describe('field-submit-value', async () => {
const {
buildSelectSubmitValue,
buildMultipleSelectSubmitValue,
buildCarBrandSubmitValue,
extractSelectStorageValueFromRowField,
parseSelectEchoValue,
parseMultipleSelectEchoValue,
parseCarBrandEchoValue
} = await import('../form-engine/field-submit-value.js')
const carInfo = {
vehicleBrandId: 'lantu',
vehicleBrandName: '岚图',
vehicleSubBrandId: 'lantu',
vehicleSubBrandName: '岚图',
vehicleSeriesId: 'dreamer',
vehicleSeriesName: '梦想家',
vehicleShapeId: '2025_ev_long_range_flagship',
vehicleShapeName: '2025款 EV 超长续航旗舰版'
}
it('IT-SUBMIT-001: static select serializes to { id, name }', () => {
const field = {
type: 'select',
options: [{ label: '张三', value: 'u-1' }]
}
assert.deepEqual(buildSelectSubmitValue(field, 'u-1'), { id: 'u-1', name: '张三' })
})
it('IT-SUBMIT-002: optionsKey select keeps full object', () => {
const field = { type: 'select', optionsKey: '4sStaffList' }
const value = { id: 'u-1', name: '张三', phone: '13800138000' }
assert.deepEqual(buildSelectSubmitValue(field, value), value)
})
it('IT-SUBMIT-003: multipleSelect serializes object array', () => {
const field = { type: 'multipleSelect', optionsKey: 'storeStaffList' }
const value = [
{ id: 'u-1', name: '张三' },
{ id: 'u-2', name: '李四' }
]
assert.deepEqual(buildMultipleSelectSubmitValue(field, value), value)
})
it('IT-SUBMIT-003b: remote same-name staff keeps each selected id', () => {
const field = {
type: 'multipleSelect',
optionsKey: 'storeStaffList',
options: [
{ id: 'u-1', name: '张三', value: 'u-1', label: '张三' },
{ id: 'u-2', name: '张三', value: 'u-2', label: '张三' }
]
}
assert.deepEqual(buildMultipleSelectSubmitValue(field, [
{ id: 'u-2', name: '张三' }
]), [{ id: 'u-2', name: '张三' }])
})
it('IT-SUBMIT-004: carBrand serializes to 4-level cascade array', () => {
assert.deepEqual(buildCarBrandSubmitValue(carInfo), [
{ id: 'lantu', name: '岚图' },
{ id: 'lantu', name: '岚图' },
{ id: 'dreamer', name: '梦想家' },
{ id: '2025_ev_long_range_flagship', name: '2025款 EV 超长续航旗舰版' }
])
})
it('IT-SUBMIT-005: echo round-trip for select and carBrand', () => {
const selectField = { type: 'select', optionsKey: '4sStaffList' }
const staff = { id: 'u-1', name: '张三', phone: '13800138000' }
assert.deepEqual(parseSelectEchoValue(staff, selectField), staff)
const restored = parseCarBrandEchoValue(buildCarBrandSubmitValue(carInfo))
assert.equal(restored.vehicleShapeId, '2025_ev_long_range_flagship')
assert.equal(restored.vehicleShapeName, '2025款 EV 超长续航旗舰版')
})
it('IT-SUBMIT-006: multipleSelect echo preserves object array', () => {
const field = { type: 'multipleSelect', optionsKey: 'storeStaffList' }
const value = [{ id: 'u-1', name: '张三' }]
assert.deepEqual(parseMultipleSelectEchoValue(value, field), value)
})
it('IT-SUBMIT-007: extractSelectStorageValueFromRowField keeps dual-key phone', () => {
const staff = {
id: '982873a3744e44fbb439432e51edadef',
name: '林永健test003',
phone: '17875511831'
}
const rowField = {
key: 'F2-9-1',
type: 'select',
optionsKey: '4sStaffList',
value: '林永健test003',
'F2-9-1': staff
}
assert.deepEqual(extractSelectStorageValueFromRowField(rowField), staff)
})
})