store-v230-context-visibility.test.mjs
22.9 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
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { readFileSync } from 'node:fs'
import { createFormEngine } from '../form-engine/core.js'
import {
buildDynamicSavePayload,
parseJsonContentDetailValues
} from '../form-engine/submit-adapter.js'
import {
buildDailyReportSaveRequest,
parseRequestJsonLists
} from '../form-engine/save-request.js'
import { DAILY_REPORT_TEMPLATE_TYPE } from '../config/dailyReportConstants.js'
import { getVisibleGroupChildFields } from '../form-engine/visibility.js'
import { getVisibleFieldOptions } from '../form-engine/option-visibility.js'
import { resolveMerchantOperatingBrandIds } from '../form-engine/car-brand-merchant-tree.js'
const schema = JSON.parse(readFileSync(
new URL('../fixtures/schema-store-daily-v2.3.0.json', import.meta.url),
'utf8'
))
const SOURCE_KEY = 'F2-107-3'
const DELIVERY_DATE_KEY = 'F2-107-4'
const CUSTOMER_TAGS_KEY = 'F2-107-7'
const PRODUCT_CATEGORY_KEY = 'F2-107-12'
const REFERRAL_KEY = 'F2-107-13'
const REFERRAL_REASON_KEY = 'F2-107-14'
const CONTACTED_KEY = 'F2-107-15'
const CONTACTED_REASON_KEY = 'F2-107-16'
const UNCONTACTED_REASON_KEY = 'F2-107-17'
const FIVE_REALM_ID = 3454
const OTHER_BRAND_ID = 999999
function context(sceneCodes, brandIds) {
const codes = Array.isArray(sceneCodes) ? sceneCodes : [sceneCodes]
return {
baseSceneCode: codes[0],
sceneList: codes.map(baseSceneCode => ({ baseSceneCode })),
brandIds
}
}
function contextFromMerchantBrands(sceneCodes, merchantCarBrandList) {
return {
...context(sceneCodes, resolveMerchantOperatingBrandIds(merchantCarBrandList)),
merchantCarBrandList
}
}
function createRowEngine(ctx, source, deliveryDate = '2026-08-12') {
const engineSchema = structuredClone(schema)
const engine = createFormEngine(engineSchema)
engine.init(engineSchema, ctx)
engine.addGroupRow('F2-107')
engine.setGroupFieldValue('F2-107', 0, SOURCE_KEY, source)
if (deliveryDate !== null) {
engine.setGroupFieldValue('F2-107', 0, DELIVERY_DATE_KEY, deliveryDate)
}
return engine
}
function visibleRowKeys(engine) {
const state = engine.getViewState()
const group = state.groupFields.find(field => field.key === 'F2-107')
const rowFields = state.groupRowsCache['F2-107']?.[0] || []
const rowMap = state.values['F2-107']?.[0] || {}
return getVisibleGroupChildFields(
group,
engine.getPageContext(),
state.values,
engine.getSchemaList(),
rowFields,
rowMap
).map(field => field.key)
}
describe('Store V2.3 delivery-date context visibility', () => {
const cases = [
['light-mod five-realm delivery source', context(100101, [FIVE_REALM_ID]), '3', true],
['light-mod five-realm sales source', context(100101, [FIVE_REALM_ID]), '0', false],
['light-mod other-brand sales source', context(100102, [OTHER_BRAND_ID]), '0', true],
['light-mod other-brand delivery source', context(100103, [OTHER_BRAND_ID]), '3', true],
['light-mod after-sale source', context(100101, [OTHER_BRAND_ID]), '1', false],
['warranty store source', context(110201, [FIVE_REALM_ID]), '0', true],
['equity store source', context(110101, [OTHER_BRAND_ID]), '0', true],
['warranty delivery source', context(110202, [OTHER_BRAND_ID]), '3', false],
['mixed brands use five-realm branch', context(100101, [FIVE_REALM_ID, OTHER_BRAND_ID]), '0', false],
['baseSceneCode fallback', { baseSceneCode: 100101, brandIds: [FIVE_REALM_ID] }, '3', true],
['missing scene fails closed', { brandIds: [FIVE_REALM_ID], sceneList: [] }, '3', false],
['missing brands fails closed', context(100101, []), '3', false]
]
it('IT-V230-CONTEXT-001: combines merchant scenes, brandIds and row source', () => {
for (const [name, ctx, source, expected] of cases) {
const engine = createRowEngine(ctx, source, null)
assert.equal(
visibleRowKeys(engine).includes(DELIVERY_DATE_KEY),
expected,
name
)
}
})
it('IT-V230-CONTEXT-002: context change clears a now-hidden date and skips validation', () => {
const requiredEngine = createRowEngine(
context(100101, [OTHER_BRAND_ID]),
'销售端引流-售前',
null
)
assert.ok(
requiredEngine.validate().errors.some(error => error.key.endsWith(DELIVERY_DATE_KEY))
)
const engine = createRowEngine(
context(100101, [OTHER_BRAND_ID]),
'销售端引流-售前'
)
assert.equal(
engine.getValues()['F2-107']?.[0]?.[DELIVERY_DATE_KEY],
'2026-08-12'
)
engine.setPageContext(context(100101, [FIVE_REALM_ID]))
assert.equal(engine.getValues()['F2-107']?.[0]?.[DELIVERY_DATE_KEY], undefined)
assert.ok(!visibleRowKeys(engine).includes(DELIVERY_DATE_KEY))
assert.ok(!engine.validate().errors.some(error => error.key.endsWith(DELIVERY_DATE_KEY)))
})
it('IT-V230-CONTEXT-003: save lists and jsonContent use the same context rule', () => {
for (const [name, ctx, source, expected] of cases) {
const engine = createRowEngine(ctx, source)
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const json = JSON.parse(payload.jsonContent)
const section = json.find(field => field.key === 'F2-107')
const jsonRow = section?.childrenValue?.[0]?.['F2-107'] || {}
const listHasDate = payload.subformDataList.some(
item => item.parentFieldKey === 'F2-107' && item.columnFieldKey === DELIVERY_DATE_KEY
)
assert.equal(Object.hasOwn(jsonRow, DELIVERY_DATE_KEY), expected, `${name} jsonContent`)
assert.equal(listHasDate, expected, `${name} subformDataList`)
}
})
it('IT-V230-CONTEXT-004: generated customer-tag field follows the confirmed brand matrix', () => {
const customerSection = schema.list.find(field => field.key === 'F2-107')
const tags = customerSection.children[0].find(field => field.key === 'F2-107-7')
const visibleTags = ctx => getVisibleFieldOptions(tags, ctx).map(option => option.value)
assert.deepEqual(visibleTags(context(100101, [FIVE_REALM_ID])), [
'1', '2', '3', '4', '5'
])
assert.deepEqual(visibleTags(context(100101, [OTHER_BRAND_ID])), ['1'])
assert.deepEqual(visibleTags(context(100101, [FIVE_REALM_ID, OTHER_BRAND_ID])), [
'1', '2', '4', '5'
])
assert.deepEqual(visibleTags(context(110201, [OTHER_BRAND_ID])), [
'1', '3'
])
})
it('IT-V230-CONTEXT-005: generated schema clears a selected tag after brand context changes', () => {
const engine = createRowEngine(
context(100101, [FIVE_REALM_ID]),
'交付端引流-售前',
null
)
engine.setGroupFieldValue('F2-107', 0, 'F2-107-7', [
'已触客', '已拉群', '已交付引荐'
])
engine.setPageContext(context(100101, [FIVE_REALM_ID, OTHER_BRAND_ID]))
assert.deepEqual(engine.getValues()['F2-107'][0]['F2-107-7'], [
'1', '2'
])
})
it('IT-V230-CONTEXT-006: a previously hidden product category reappears after selecting 已触客', () => {
const engine = createRowEngine(
context(110201, [OTHER_BRAND_ID]),
'门店引流-售前',
null
)
assert.equal(visibleRowKeys(engine).includes(PRODUCT_CATEGORY_KEY), false)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
assert.equal(visibleRowKeys(engine).includes(PRODUCT_CATEGORY_KEY), true)
})
it('IT-V230-CONTEXT-007: chained childrenShowRules fields can reappear in sequence', () => {
const engine = createRowEngine(
context(110201, [OTHER_BRAND_ID]),
'门店引流-售前',
null
)
assert.equal(visibleRowKeys(engine).includes(REFERRAL_KEY), false)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已交付引荐'])
assert.equal(visibleRowKeys(engine).includes(REFERRAL_KEY), true)
assert.equal(visibleRowKeys(engine).includes(REFERRAL_REASON_KEY), false)
engine.setGroupFieldValue('F2-107', 0, REFERRAL_KEY, '否')
assert.equal(visibleRowKeys(engine).includes(REFERRAL_REASON_KEY), true)
})
it('IT-V230-CONTEXT-008: object-array customer tags drive context-eligible childrenShowRules fields', () => {
const engine = createRowEngine(
context(110201, [OTHER_BRAND_ID]),
'门店引流-售前',
null
)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, [
{ id: 'tag-contacted', name: '已触客' },
{ id: 'tag-delivered', label: '已交付引荐' }
])
const keys = visibleRowKeys(engine)
assert.ok(keys.includes(PRODUCT_CATEGORY_KEY))
assert.ok(keys.includes(REFERRAL_KEY))
assert.ok(keys.includes('F2-107-18'))
assert.ok(!keys.includes('F2-107-17'))
const lightModificationEngine = createRowEngine(
context(100101, [OTHER_BRAND_ID]),
'销售端引流-售前',
null
)
lightModificationEngine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, [
{ id: 'tag-contacted', name: '已触客' }
])
assert.ok(visibleRowKeys(lightModificationEngine).includes(CONTACTED_KEY))
lightModificationEngine.setGroupFieldValue('F2-107', 0, CONTACTED_KEY, '否')
assert.ok(visibleRowKeys(lightModificationEngine).includes(CONTACTED_REASON_KEY))
})
it('IT-V230-CONTEXT-009: merchant.info other-brand tree enables product category after 已触客', () => {
const merchantCarBrandList = [
{
id: 2161,
name: '宝马',
childs: [{ id: 2161, name: '宝马' }]
}
]
const engine = createRowEngine(
contextFromMerchantBrands(110201, merchantCarBrandList),
'门店引流-售前',
null
)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
assert.deepEqual(engine.getPageContext().brandIds, [2161])
assert.ok(visibleRowKeys(engine).includes(PRODUCT_CATEGORY_KEY))
})
it('IT-V230-CONTEXT-010: string five-realm ids from merchant.info keep numeric field visibility', () => {
const merchantCarBrandList = [
{
id: 2978,
name: '鸿蒙智行',
childs: [{ id: '3454', name: 'AITO 问界' }]
}
]
const engine = createRowEngine(
contextFromMerchantBrands(110201, merchantCarBrandList),
'门店引流-售前',
null
)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
assert.deepEqual(engine.getPageContext().brandIds, [3454])
assert.ok(!visibleRowKeys(engine).includes(PRODUCT_CATEGORY_KEY))
})
it('IT-V230-CONTEXT-011: static customer tags and uncontacted reason echo after save', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const engine = createRowEngine(ctx, '交付端引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已拉群', '已触客'])
engine.setGroupFieldValue('F2-107', 0, 'F2-107-17', '客户暂未回复')
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
const savedTags = savedSection.childrenValue[0]['F2-107'][CUSTOMER_TAGS_KEY]
assert.deepEqual(savedTags, {
text: '已拉群/已触客',
value: ['2', '1']
})
const customerTagListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === CUSTOMER_TAGS_KEY
)
assert.deepEqual(JSON.parse(customerTagListItem.fieldValue), [
{ id: '2/1', name: '已拉群/已触客' }
])
const initialValues = parseJsonContentDetailValues(payload.jsonContent, schema.list)
const reloaded = createFormEngine(structuredClone(schema))
reloaded.init(structuredClone(schema), { ...ctx, initialValues })
assert.deepEqual(reloaded.getValues()['F2-107'][0][CUSTOMER_TAGS_KEY], [
'2', '1'
])
assert.equal(reloaded.getValues()['F2-107'][0]['F2-107-17'], undefined)
assert.ok(!visibleRowKeys(reloaded).includes('F2-107-17'))
})
it('IT-V230-CONTEXT-012: PAD dual-key customer tags echo as an internal array', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const detailJson = JSON.stringify([{
key: 'F2-107',
label: '今日非成交客户',
type: 'subform',
origin_children: schema.list.find(field => field.key === 'F2-107').children[0],
childrenValue: [{
'F2-107': {
'F2-107-3': '交付端引流-售前',
[CUSTOMER_TAGS_KEY]: {
text: '已拉群/已触客',
value: ['2', '1']
}
}
}]
}])
const initialValues = parseJsonContentDetailValues(detailJson, schema.list)
const engine = createFormEngine(structuredClone(schema))
engine.init(structuredClone(schema), { ...ctx, initialValues })
assert.deepEqual(engine.getValues()['F2-107'][0][CUSTOMER_TAGS_KEY], [
'2', '1'
])
})
it('IT-V230-CONTEXT-012b: historical Chinese PAD tag ids still echo after numeric mapping', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const detailJson = JSON.stringify([{
key: 'F2-107',
label: '今日非成交客户',
type: 'subform',
origin_children: schema.list.find(field => field.key === 'F2-107').children[0],
childrenValue: [{
'F2-107': {
[CUSTOMER_TAGS_KEY]: {
text: '已拉群/已触客',
value: ['已拉群', '已触客']
}
}
}]
}])
const initialValues = parseJsonContentDetailValues(detailJson, schema.list)
assert.deepEqual(initialValues['F2-107'][0][CUSTOMER_TAGS_KEY], [
'2', '1'
])
})
it('IT-V230-CONTEXT-012c: historical tag objects save with numeric PAD values', () => {
const ctx = context(100101, [FIVE_REALM_ID])
const engine = createRowEngine(ctx, '交付端引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, [
{ id: '已拉群', name: '已拉群' },
{ id: '已触客', name: '已触客' }
])
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
assert.deepEqual(savedSection.childrenValue[0]['F2-107'][CUSTOMER_TAGS_KEY], {
text: '已拉群/已触客',
value: ['2', '1']
})
const listItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === CUSTOMER_TAGS_KEY
)
assert.deepEqual(JSON.parse(listItem.fieldValue), [
{ id: '2/1', name: '已拉群/已触客' }
])
})
it('IT-V230-CONTEXT-013: customer source saves numeric value and restores by text', () => {
for (const [ctx, source, id] of [
[context(100101, [FIVE_REALM_ID]), '销售端引流-售前', '0'],
[context(100101, [FIVE_REALM_ID]), '交付端引流-售前', '3'],
[context(110201, [OTHER_BRAND_ID]), '门店引流-售前', '0'],
[context(110201, [OTHER_BRAND_ID]), '门店引流-售后', '1']
]) {
const engine = createRowEngine(ctx, source, null)
engine.setAppGroupFieldValue('F2-107', 0, SOURCE_KEY, {
id: source,
displayLabel: source
})
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
assert.deepEqual(savedSection.childrenValue[0]['F2-107'][SOURCE_KEY], {
text: source,
value: id
})
const sourceListItem = payload.subformDataList.find(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === SOURCE_KEY
)
assert.deepEqual(JSON.parse(sourceListItem.fieldValue), { id, name: source })
const initialValues = parseJsonContentDetailValues(payload.jsonContent, schema.list)
assert.equal(initialValues['F2-107'][0][SOURCE_KEY], id)
}
})
it('IT-V230-CONTEXT-013b: customer source options follow the active report scene', () => {
const sourceField = schema.list
.find(field => field.key === 'F2-107')
.children[0]
.find(field => field.key === SOURCE_KEY)
const values = ctx => getVisibleFieldOptions(sourceField, ctx).map(option => option.value)
assert.deepEqual(values(context(100101, [FIVE_REALM_ID])), [
'0', '3', '1'
])
assert.deepEqual(values(context(110201, [OTHER_BRAND_ID])), [
'0', '1'
])
})
it('IT-V230-CONTEXT-014: boutique save drops stale product category from every App payload shape', () => {
const boutiqueContext = {
...context([100101, 110201], [OTHER_BRAND_ID]),
baseSceneCode: 100101
}
const engine = createRowEngine(boutiqueContext, '销售端引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
engine.setGroupFieldValue('F2-107', 0, PRODUCT_CATEGORY_KEY, ['原厂延保'])
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
const savedRow = savedSection.childrenValue[0]['F2-107']
assert.equal(Object.hasOwn(savedRow, PRODUCT_CATEGORY_KEY), false)
assert.ok(!savedSection.origin_children.some(field => field.key === PRODUCT_CATEGORY_KEY))
assert.ok(!payload.subformDataList.some(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === PRODUCT_CATEGORY_KEY
))
})
it('IT-V230-CONTEXT-014c: five-realm boutique save omits effective-arrival fields from every App payload shape', () => {
const engine = createRowEngine(context(100101, [FIVE_REALM_ID]), '0', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['1'])
assert.equal(visibleRowKeys(engine).includes(CONTACTED_KEY), false)
assert.equal(visibleRowKeys(engine).includes(CONTACTED_REASON_KEY), false)
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
const savedRow = savedSection.childrenValue[0]['F2-107']
const savedOriginKeys = savedSection.origin_children.map(field => field.key)
assert.equal(savedOriginKeys.includes(CONTACTED_KEY), false)
assert.equal(savedOriginKeys.includes(CONTACTED_REASON_KEY), false)
assert.equal(Object.hasOwn(savedRow, CONTACTED_KEY), false)
assert.equal(Object.hasOwn(savedRow, CONTACTED_REASON_KEY), false)
assert.equal(payload.subformDataList.some(item =>
item.parentFieldKey === 'F2-107' &&
[CONTACTED_KEY, CONTACTED_REASON_KEY].includes(item.columnFieldKey)
), false)
})
it('IT-V230-CONTEXT-014d: five-realm boutique detail echo keeps legacy effective-arrival values hidden', () => {
const engineSchema = structuredClone(schema)
const engine = createFormEngine(engineSchema)
engine.init(engineSchema, {
...context(100101, [FIVE_REALM_ID]),
hasDetailEcho: true,
echoSubformKeys: ['F2-107'],
echoTopLevelKeys: ['F2-107'],
initialValues: {
'F2-107': [{
[SOURCE_KEY]: '0',
[CUSTOMER_TAGS_KEY]: ['1'],
[CONTACTED_KEY]: '\u5426',
[CONTACTED_REASON_KEY]: '\u5386\u53f2\u65e0\u6548\u5230\u5e97\u8bf4\u660e'
}]
}
})
const keys = visibleRowKeys(engine)
assert.equal(keys.includes(CONTACTED_KEY), false)
assert.equal(keys.includes(CONTACTED_REASON_KEY), false)
})
it('IT-V230-CONTEXT-014e: other-brand boutique save and detail echo retain effective-arrival fields', () => {
const pageContext = context(100101, [OTHER_BRAND_ID])
const engine = createRowEngine(pageContext, '0', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['1'])
engine.setGroupFieldValue('F2-107', 0, CONTACTED_KEY, '\u5426')
engine.setGroupFieldValue('F2-107', 0, CONTACTED_REASON_KEY, '\u5ba2\u6237\u672a\u8fdb\u5e97')
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
const savedRow = savedSection.childrenValue[0]['F2-107']
assert.equal(savedRow[CONTACTED_KEY], '\u5426')
assert.equal(savedRow[CONTACTED_REASON_KEY], '\u5ba2\u6237\u672a\u8fdb\u5e97')
const echoSchema = structuredClone(schema)
const echoEngine = createFormEngine(echoSchema)
echoEngine.init(echoSchema, {
...pageContext,
hasDetailEcho: true,
echoSubformKeys: ['F2-107'],
echoTopLevelKeys: ['F2-107'],
initialValues: parseJsonContentDetailValues(payload.jsonContent, schema.list)
})
const echoKeys = visibleRowKeys(echoEngine)
assert.equal(echoKeys.includes(CONTACTED_KEY), true)
assert.equal(echoKeys.includes(CONTACTED_REASON_KEY), true)
})
it('IT-V230-CONTEXT-014b: requestJson keeps fields visible only in a later customer row', () => {
const pageContext = {
...context(100101, [FIVE_REALM_ID]),
merchantId: 1001
}
const engineSchema = structuredClone(schema)
const engine = createFormEngine(engineSchema)
engine.init(engineSchema, pageContext)
engine.addGroupRow('F2-107')
engine.setGroupFieldValue('F2-107', 0, SOURCE_KEY, '0')
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['1'])
engine.addGroupRow('F2-107')
engine.setGroupFieldValue('F2-107', 1, SOURCE_KEY, '3')
engine.setGroupFieldValue('F2-107', 1, DELIVERY_DATE_KEY, '2026-08-18')
engine.setGroupFieldValue('F2-107', 1, CUSTOMER_TAGS_KEY, ['3'])
engine.setGroupFieldValue('F2-107', 1, REFERRAL_KEY, '\u5426')
engine.setGroupFieldValue('F2-107', 1, REFERRAL_REASON_KEY, '\u65e0\u6548\u5f15\u8350\u8bf4\u660e')
engine.setGroupFieldValue('F2-107', 1, UNCONTACTED_REASON_KEY, '\u672a\u89e6\u5ba2\u539f\u56e0')
const { request } = buildDailyReportSaveRequest({
reportDate: '2026-08-19',
userContext: {
merchantId: 1001,
staffUuid: 'staff-current',
staffName: '\u5f53\u524d\u7528\u6237'
},
pageContext,
engine,
reportTemplateId: 10002,
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
const requestLists = parseRequestJsonLists(request.requestJson)
const laterRowKeys = requestLists.subformDataList
.filter(item => item.parentFieldKey === 'F2-107' && item.rowIndex === 1)
.map(item => item.columnFieldKey)
assert.ok(laterRowKeys.includes(DELIVERY_DATE_KEY))
assert.ok(laterRowKeys.includes(REFERRAL_REASON_KEY))
assert.ok(laterRowKeys.includes(UNCONTACTED_REASON_KEY))
assert.equal(requestLists.subformDataList.some(item =>
item.parentFieldKey === 'F2-107' &&
item.rowIndex === 0 &&
[DELIVERY_DATE_KEY, REFERRAL_REASON_KEY, UNCONTACTED_REASON_KEY]
.includes(item.columnFieldKey)
), false)
const savedRows = JSON.parse(request.jsonContent)
.find(field => field.key === 'F2-107')
.childrenValue
assert.equal(savedRows[1]['F2-107'][DELIVERY_DATE_KEY], '2026-08-18')
assert.equal(savedRows[1]['F2-107'][REFERRAL_REASON_KEY], '\u65e0\u6548\u5f15\u8350\u8bf4\u660e')
assert.equal(savedRows[1]['F2-107'][UNCONTACTED_REASON_KEY], '\u672a\u89e6\u5ba2\u539f\u56e0')
})
it('IT-V230-CONTEXT-015: warranty save retains eligible product category', () => {
const engine = createRowEngine(context(110201, [OTHER_BRAND_ID]), '门店引流-售前', null)
engine.setGroupFieldValue('F2-107', 0, CUSTOMER_TAGS_KEY, ['已触客'])
engine.setGroupFieldValue('F2-107', 0, PRODUCT_CATEGORY_KEY, ['原厂延保'])
const payload = buildDynamicSavePayload({
reportTemplateId: 10002,
engine,
normalizedFieldDataList: true
})
const savedSection = JSON.parse(payload.jsonContent)
.find(field => field.key === 'F2-107')
assert.deepEqual(savedSection.childrenValue[0]['F2-107'][PRODUCT_CATEGORY_KEY], {
text: '原厂延保',
value: ['原厂延保']
})
assert.ok(savedSection.origin_children.some(field => field.key === PRODUCT_CATEGORY_KEY))
assert.ok(payload.subformDataList.some(item =>
item.parentFieldKey === 'F2-107' && item.columnFieldKey === PRODUCT_CATEGORY_KEY
))
})
})