quotationCustomerDailyFields.test.mjs
8.88 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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import * as customerDailyFields from '../pages/carQuotation/services/customerDailyFields.helpers.js'
import {
buildEquityCustomerDailyListDisplay,
buildEquityCustomerDailyDisplay,
buildEquityCustomerDailyDetail,
EQUITY_CUSTOMER_TAGS,
formatEquityCustomerTags,
formatEquityDeliveryDateForDisplay,
formatEquityDeliveryDateForSubmit,
isEquityActualDeliveryDateVisible,
isEquityCustomerTagsVisible,
parseEquityCustomerTags,
reconcileEquityCustomerDailyFields,
serializeEquityCustomerTags
} from '../pages/carQuotation/services/customerDailyFields.helpers.js'
describe('quotation customer daily fields', () => {
it('IT-EQ-DAILY-001: parses, deduplicates, sorts and formats supported tags', () => {
assert.deepEqual(parseEquityCustomerTags('3,1,3,5'), ['1', '3'])
assert.equal(serializeEquityCustomerTags([3, 1, 3]), '1,3')
assert.equal(formatEquityCustomerTags('3,1'), '已触客/已交付引荐')
assert.deepEqual(EQUITY_CUSTOMER_TAGS.map(item => item.value), ['1', '3'])
})
it('IT-EQ-DAILY-002: customer-tag visibility supports standard and simple values', () => {
assert.equal(isEquityCustomerTagsVisible(0), true)
assert.equal(isEquityCustomerTagsVisible('售后'), true)
assert.equal(isEquityCustomerTagsVisible(2), false)
})
it('IT-EQ-DAILY-005: delivery-date visibility requires template scene and pre-sales', () => {
for (const fragment of ['2.3.1', '2.3.2', '2.1.1', '2.1.2']) {
assert.equal(
isEquityActualDeliveryDateVisible({
salesType: 0,
baseSceneName: `${fragment} 权益场景`
}),
true
)
}
assert.equal(
isEquityActualDeliveryDateVisible({
salesType: '售前',
baseSceneCode: 'scene-2.3.1-upgrade'
}),
true
)
assert.equal(
isEquityActualDeliveryDateVisible({
salesType: 1,
baseSceneName: '2.3.1 权益场景'
}),
false
)
assert.equal(
isEquityActualDeliveryDateVisible({
salesType: 0,
baseSceneName: '2.4.1 非适用场景'
}),
false
)
})
it('IT-EQ-DAILY-010: real numeric equity and warranty scene codes show for pre-sales', () => {
for (const baseSceneCode of [110101, '110102', 110201, '110202']) {
assert.equal(
isEquityActualDeliveryDateVisible({ salesType: 0, baseSceneCode }),
true,
`numeric equity scene ${baseSceneCode}`
)
}
assert.equal(
isEquityActualDeliveryDateVisible({
salesType: 1,
baseSceneCode: 110201
}),
false
)
})
it('IT-EQ-DAILY-003: reconciliation clears hidden fields immediately', () => {
assert.deepEqual(
reconcileEquityCustomerDailyFields(
{
salesType: 2,
customerTags: '1,3',
actualDeliveryDate: '2026-08-04 10:00:00'
},
{ baseSceneName: '2.3.1 权益场景' }
),
{ salesType: 2, customerTags: '', actualDeliveryDate: '' }
)
assert.deepEqual(
reconcileEquityCustomerDailyFields(
{
salesType: 1,
customerTags: '3,1',
actualDeliveryDate: '2026-08-04 10:00:00'
},
{ baseSceneName: '2.3.1 权益场景' }
),
{ salesType: 1, customerTags: '1,3', actualDeliveryDate: '' }
)
assert.equal(
reconcileEquityCustomerDailyFields(
{
salesType: 0,
customerTags: '1',
actualDeliveryDate: '2026-08-04 10:00:00'
},
{ baseSceneName: '2.4.1 非适用场景' }
).actualDeliveryDate,
''
)
})
it('IT-EQ-DAILY-004: date display and submit formats are stable', () => {
assert.equal(
formatEquityDeliveryDateForDisplay('2026-08-04 10:00:00'),
'2026-08-04'
)
assert.equal(
formatEquityDeliveryDateForSubmit('2026-08-04'),
'2026-08-04 00:00:00'
)
assert.equal(formatEquityDeliveryDateForSubmit(), '')
})
it('IT-EQ-DAILY-006: adapts stored selections from find-by-id owner response', () => {
assert.deepEqual(
buildEquityCustomerDailyDetail({
id: 10001,
orderId: 20001,
owner: {
salesType: 0,
customerTags: '3,1,3',
actualDeliveryDate: '2026-08-04 10:30:45'
},
quotationGoodsInfoList: []
}),
{
customerDailyInfo: {
showCustomerTags: true,
showActualDeliveryDate: true,
actualDeliveryDate: '2026-08-04'
},
customerTagLabels: ['已触客', '已交付引荐']
}
)
})
it('IT-EQ-DAILY-007: builds list and detail visibility from returned values', () => {
assert.deepEqual(
buildEquityCustomerDailyDisplay({
salesType: 2,
customerTags: '3,1,3,5',
actualDeliveryDate: '2026-08-14 09:08:07'
}),
{
showCustomerTags: true,
showActualDeliveryDate: true,
customerTagLabels: ['已触客', '已交付引荐'],
customerTagsText: '已触客/已交付引荐',
actualDeliveryDate: '2026-08-14'
}
)
assert.deepEqual(buildEquityCustomerDailyDisplay({ salesType: 0 }), {
showCustomerTags: false,
showActualDeliveryDate: false,
customerTagLabels: [],
customerTagsText: '',
actualDeliveryDate: ''
})
assert.equal(
buildEquityCustomerDailyDetail({ owner: { salesType: 0 } })
.customerDailyInfo.showCustomerTags,
false
)
})
it('IT-EQ-DAILY-008: shows returned tags without a delivery date', () => {
assert.deepEqual(buildEquityCustomerDailyDisplay({ customerTags: '1' }), {
showCustomerTags: true,
showActualDeliveryDate: false,
customerTagLabels: ['已触客'],
customerTagsText: '已触客',
actualDeliveryDate: ''
})
})
it('IT-EQ-DAILY-009: shows a returned delivery date without tags', () => {
assert.deepEqual(
buildEquityCustomerDailyDisplay({
actualDeliveryDate: '2026-08-14 09:08:07'
}),
{
showCustomerTags: false,
showActualDeliveryDate: true,
customerTagLabels: [],
customerTagsText: '',
actualDeliveryDate: '2026-08-14'
}
)
})
it('IT-EQ-DAILY-011: list delivery date only uses the quotation item root value', () => {
assert.deepEqual(
buildEquityCustomerDailyListDisplay({
customerTags: '1',
actualDeliveryDate: '2026-08-17 09:00:00',
owner: {
customerTags: '3',
actualDeliveryDate: '2026-08-18 10:00:00'
}
}),
{
showCustomerTags: true,
showActualDeliveryDate: true,
customerTagLabels: ['已触客'],
customerTagsText: '已触客',
actualDeliveryDate: '2026-08-17'
}
)
assert.deepEqual(
buildEquityCustomerDailyListDisplay({
customerTags: '',
actualDeliveryDate: '',
owner: {
customerTags: '3',
actualDeliveryDate: '2026-08-18 10:00:00'
}
}),
{
showCustomerTags: false,
showActualDeliveryDate: false,
customerTagLabels: [],
customerTagsText: '',
actualDeliveryDate: ''
}
)
})
it('IT-EQ-DAILY-012: delivery date is required only while its field is visible', () => {
assert.equal(
typeof customerDailyFields.isEquityActualDeliveryDateMissing,
'function'
)
assert.equal(
customerDailyFields.isEquityActualDeliveryDateMissing(true, ''),
true
)
assert.equal(
customerDailyFields.isEquityActualDeliveryDateMissing(true, 'not-a-date'),
true
)
assert.equal(
customerDailyFields.isEquityActualDeliveryDateMissing(
true,
'2026-08-17'
),
false
)
assert.equal(
customerDailyFields.isEquityActualDeliveryDateMissing(false, ''),
false
)
})
it('IT-EQ-DAILY-013: formats millisecond delivery timestamps in China time', () => {
assert.equal(
formatEquityDeliveryDateForDisplay(1787068800000),
'2026-08-19'
)
assert.equal(
formatEquityDeliveryDateForDisplay('1787068800000'),
'2026-08-19'
)
})
it('IT-EQ-DAILY-014: list displays only the root millisecond delivery timestamp', () => {
assert.deepEqual(
buildEquityCustomerDailyListDisplay({
actualDeliveryDate: 1787068800000,
owner: { actualDeliveryDate: '2026-08-20 00:00:00' }
}),
{
showCustomerTags: false,
showActualDeliveryDate: true,
customerTagLabels: [],
customerTagsText: '',
actualDeliveryDate: '2026-08-19'
}
)
})
it('IT-EQ-DAILY-015: rejects invalid and non-millisecond delivery dates', () => {
assert.equal(formatEquityDeliveryDateForDisplay(1787068800), '')
assert.equal(
formatEquityDeliveryDateForDisplay(Number.POSITIVE_INFINITY),
''
)
assert.equal(formatEquityDeliveryDateForDisplay('2026-13-40'), '')
})
})