store-app-json-content.test.mjs
3.22 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createFormEngine } from '../form-engine/core.js'
import { buildDailyReportSaveRequest, parseRequestJsonLists } from '../form-engine/save-request.js'
import { DAILY_REPORT_TEMPLATE_TYPE } from '../config/dailyReportConstants.js'
import { loadSchemaFixture } from './schemaFixture.mjs'
describe('store App jsonContent', () => {
it('IT-STORE-APP-001: save jsonContent uses childrenValue and dual key for F2-9-1', () => {
const storeSchema = loadSchemaFixture('store')
const engine = createFormEngine(storeSchema)
engine.setPageContext({
baseSceneCode: 110201,
brandIds: [3454, 3067],
merchantId: '1001',
sceneList: [{ baseSceneCode: 110201 }]
})
const f29Group = storeSchema.list.find(item => item.key === 'F2-9')
engine.addGroupRow(f29Group)
engine.setAppGroupFieldValue('F2-9', 0, 'F2-9-1', {
id: '4s-001',
displayLabel: '交付专员A'
})
const { request } = buildDailyReportSaveRequest({
reportDate: '2026-06-02',
userContext: { merchantId: 1001, staffUuid: 's1', staffName: '李四' },
pageContext: { merchantId: 1001 },
engine,
reportTemplateId: 10002,
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
const parsed = JSON.parse(request.jsonContent)
const f29 = parsed.find(item => item.key === 'F2-9')
assert.ok(f29)
assert.ok(Array.isArray(f29.childrenValue))
assert.equal(f29.children, undefined)
assert.equal(f29.value, undefined)
assert.deepEqual(f29.childrenValue[0]['F2-9']['F2-9-1'], {
text: '交付专员A',
value: '4s-001'
})
})
it('IT-STORE-APP-002: jsonContent includes top-level F2-1/F2-2 and subform F2-9', () => {
const storeSchema = loadSchemaFixture('store')
const engine = createFormEngine(storeSchema)
engine.setPageContext({
baseSceneCode: 110201,
brandIds: [3454, 3067],
merchantId: '1001',
sceneList: [{ baseSceneCode: 110201 }]
})
const staffList = [{ id: 'staff-001', name: '张三' }]
engine.setFieldValue('F2-1', staffList)
engine.setFieldValue('F2-2', 3)
engine.setAppGroupFieldValue('F2-9', 0, 'F2-9-1', {
id: '4s-001',
displayLabel: '交付专员A'
})
const { request } = buildDailyReportSaveRequest({
reportDate: '2026-06-02',
userContext: { merchantId: 1001, staffUuid: 's1', staffName: '李四' },
pageContext: { merchantId: 1001 },
engine,
reportTemplateId: 10002,
templateType: DAILY_REPORT_TEMPLATE_TYPE.store
})
const parsed = JSON.parse(request.jsonContent)
const f21 = parsed.find(item => item.key === 'F2-1')
const f22 = parsed.find(item => item.key === 'F2-2')
const f29 = parsed.find(item => item.key === 'F2-9')
assert.ok(f21, 'jsonContent should include F2-1')
assert.ok(f22, 'jsonContent should include F2-2')
assert.ok(f29, 'jsonContent should include F2-9')
assert.equal(f21.value, '张三')
assert.deepEqual(f21['F2-1'], ['staff-001'])
assert.equal(f22.value, 3)
assert.ok(Array.isArray(f29.childrenValue))
assert.equal(f29.children, undefined)
const requestLists = parseRequestJsonLists(request.requestJson)
const f21List = requestLists.fieldDataList.find(item => item.fieldKey === 'F2-1')
assert.ok(f21List)
assert.deepEqual(JSON.parse(f21List.fieldValue), staffList)
})
})