json-content-persist.test.mjs
3.32 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
/**
* jsonContent 场景持久化与回显单测
* 运行:npm run test:dynamicForm
*/
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixture } from './schemaFixture.mjs'
describe('jsonContentPersist', async () => {
const { createFormEngine } = await import('../form-engine/core.js')
const { buildDynamicSavePayload } = await import('../form-engine/submit-adapter.js')
const { getVisibleList } = await import('../form-engine/visibility.js')
const { enrichPageContextWithDetailEcho } = await import(
'../form-engine/app-subform-json.js'
)
const { mergeTemplateDefaultsIntoInitialValues } = await import(
'../form-engine/values.js'
)
const staffSchema = loadSchemaFixture('staff')
const boutiqueCtx = {
baseSceneCode: 100101,
brandIds: [3454],
merchantId: '100',
sceneList: [{ baseSceneCode: 100101 }]
}
it('IT-STAFF-SAVE-SCENE-001: boutique save excludes warranty-only fields and template-0 cross-scene groups', () => {
const initialValues = mergeTemplateDefaultsIntoInitialValues(
staffSchema.list,
{ 'F1-1': '在岗' }
)
const engine = createFormEngine(staffSchema)
engine.init(staffSchema, { ...boutiqueCtx, initialValues })
const payload = buildDynamicSavePayload({
reportTemplateId: 1001,
engine,
reportDate: '2026-06-15',
normalizedFieldDataList: true
})
const jsonKeys = JSON.parse(payload.jsonContent).map(item => item.key)
assert.ok(jsonKeys.includes('F1-1'))
assert.ok(!jsonKeys.includes('F1-2'), '延保专属 F1-2 不应入库')
const warrantyGroup = staffSchema.list.find(item => item.key === 'F1-6')
if (warrantyGroup) {
assert.ok(!jsonKeys.includes('F1-6'), '跨场景 brand group 仅模板 0 不应入库')
}
})
it('IT-ECHO-SCENE-001: wrong-scene group in jsonContent does not expand children via forceEchoBlock', () => {
const warrantyGroup = staffSchema.list.find(
item =>
item.type === 'group' &&
item.baseSceneCode?.length &&
!item.baseSceneCode.includes(100101)
)
if (!warrantyGroup) {
return
}
const jsonContent = JSON.stringify([
{ key: 'F1-1', type: 'radio', label: '出勤', value: '在岗' },
{
key: warrantyGroup.key,
type: 'group',
label: warrantyGroup.label,
children: warrantyGroup.children?.map(child => ({
...child,
value: child.type === 'numberInput' ? 0 : child.value
}))
}
])
const ctx = enrichPageContextWithDetailEcho(
{ ...boutiqueCtx },
{ jsonContent }
)
const values = { 'F1-1': '在岗' }
const visible = getVisibleList(staffSchema.list, ctx, values)
const leaked = visible.find(item => item.key === warrantyGroup.key)
assert.equal(leaked, undefined, '跨场景 group 不应出现在可见列表')
})
it('IT-ECHO-SCENE-002: off-duty brand group still persists when user entered values', () => {
const engine = createFormEngine(staffSchema)
engine.init(staffSchema, boutiqueCtx)
engine.setFieldValue('F1-1', '在岗')
engine.setFieldValue('F1-5-1', 2)
engine.setFieldValue('F1-1', '调休')
const payload = buildDynamicSavePayload({
reportTemplateId: 1001,
engine,
reportDate: '2026-06-15',
normalizedFieldDataList: true
})
const jsonContent = JSON.parse(payload.jsonContent)
const f15 = jsonContent.find(item => item.key === 'F1-5')
assert.ok(f15, '调休时应持久化已填品牌 group')
})
})