store-template-schema.test.mjs
5.58 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixtureV211 } from './schemaFixture.mjs'
const storeSchema = loadSchemaFixtureV211('store')
function findFieldByKey(list, key) {
return list.find(item => item.key === key)
}
/** 递归按 key 查找字段(含 subform / group 子项) */
function findFieldByKeyDeep(list, key) {
for (const field of list || []) {
if (field?.key === key) return field
const children = field?.children
if (!Array.isArray(children)) continue
for (const child of children) {
if (Array.isArray(child)) {
const found = findFieldByKeyDeep(child, key)
if (found) return found
} else if (child?.key === key) {
return child
}
}
}
return null
}
function collectAllKeys(list = []) {
const keys = []
function walk(field) {
if (!field?.key) return
keys.push(field.key)
const children = field.children
if (!Array.isArray(children)) return
for (const child of children) {
if (Array.isArray(child)) {
child.forEach(walk)
} else {
walk(child)
}
}
}
list.forEach(walk)
return keys
}
describe('store daily template V2.1.1 schema', () => {
it('IT-STORE-TPL-001: fixture metadata and F2-1/F2-2 staff count wiring', () => {
assert.equal(storeSchema.version, '2.1.1')
assert.equal(storeSchema.formCode, 'store_daily_report')
assert.equal(storeSchema.list.length, 55)
const f21 = findFieldByKey(storeSchema.list, 'F2-1')
assert.equal(f21?.type, 'multipleSelect')
assert.equal(f21?.optionsKey, 'storeStaffList')
assert.deepEqual(f21?.completeFun, {
key: 'F2-2',
result: '(list.length)'
})
const f22 = findFieldByKey(storeSchema.list, 'F2-2')
assert.equal(f22?.type, 'numberInput')
assert.equal(f22?.value, 0)
assert.deepEqual(f22?.disabledFun, {
keys: ['F2-1'],
result: 'val1 != null'
})
})
it('IT-STORE-TPL-002: divider fields F2-91/F2-92/F2-94', () => {
const f291 = findFieldByKey(storeSchema.list, 'F2-91')
assert.equal(f291?.type, 'divider')
assert.equal(f291?.isYB, true)
assert.deepEqual(f291?.ybCode, [110201, 110202])
assert.deepEqual(f291?.qyCode, [110101, 110102])
const f292 = findFieldByKey(storeSchema.list, 'F2-92')
assert.equal(f292?.isQY, true)
const f294 = findFieldByKey(storeSchema.list, 'F2-94')
assert.equal(f294?.label, '延保/权益')
})
it('IT-STORE-TPL-003: F2-11 other-brand subform has filterBrandId', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-11')
assert.equal(subform?.type, 'subform')
assert.deepEqual(subform?.filterBrandId, [
3454, 3503, 3458, 3574, 3502, 3067
])
assert.deepEqual(subform?.baseSceneCode, [
110101, 110102, 110201, 110202
])
const orderChild = subform?.children?.[0]?.find(item => item.key === 'F2-11-1')
assert.equal(orderChild?.optionsKey, '4sStaffList')
})
it('IT-STORE-TPL-004: removed F2-30/F2-36 not in schema', () => {
const keys = collectAllKeys(storeSchema.list)
assert.ok(!keys.includes('F2-30'))
assert.ok(!keys.includes('F2-36'))
})
it('IT-STORE-TPL-005: brand-split metrics F2-38/F2-44 exist', () => {
const f238 = findFieldByKey(storeSchema.list, 'F2-38')
assert.equal(f238?.label, '问界店总交付数')
assert.deepEqual(f238?.brandId, [3454])
assert.deepEqual(f238?.baseSceneCode, [110201, 110202])
const f244 = findFieldByKey(storeSchema.list, 'F2-44')
assert.equal(f244?.label, '其他品牌店总交付数')
assert.deepEqual(f244?.baseSceneCode, [
110101, 110102, 110201, 110202
])
assert.deepEqual(f244?.filterBrandId, [
3454, 3503, 3458, 3574, 3502, 3067
])
})
it('IT-STORE-TPL-006: F2-14 other-brand after-sales subform equity children', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-14')
assert.equal(subform?.type, 'subform')
const row = subform?.children?.[0] || []
for (const key of ['F2-14-5', 'F2-14-6', 'F2-14-8']) {
const child = row.find(item => item.key === key)
assert.deepEqual(child?.baseSceneCode, [110101, 110102], key)
}
})
it('IT-STORE-TPL-007: F2-14-12 manufacturer warranty referral metric', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-14')
const row = subform?.children?.[0] || []
const child = row.find(item => item.key === 'F2-14-12')
assert.equal(child?.label, '今日厂家权益有效转介绍')
assert.deepEqual(child?.baseSceneCode, [110201, 110202])
assert.deepEqual(subform?.childrenRules?.['F2-14-12'], {
min: 0,
integer: true
})
})
it('IT-STORE-TPL-008: F2-57/F2-58 lantu-or-other-brand use empty brandId', () => {
const fiveRealmFilter = [3454, 3503, 3458, 3574, 3502]
for (const key of ['F2-57', 'F2-58']) {
const field = findFieldByKey(storeSchema.list, key)
assert.deepEqual(field?.brandId, [], key)
assert.deepEqual(field?.filterBrandId, fiveRealmFilter, key)
}
})
it('IT-STORE-TPL-009: F2-37 lantu-or-other-brand boutique metric', () => {
const field = findFieldByKey(storeSchema.list, 'F2-37')
assert.equal(field?.label, '其他品牌店总交付数')
assert.deepEqual(field?.brandId, [])
assert.deepEqual(field?.filterBrandId, [3454, 3503, 3458, 3574, 3502])
assert.deepEqual(field?.baseSceneCode, [100101, 100102, 100103])
})
it('IT-STORE-TPL-010: Excel 后置显示文字元/% fields have unit', () => {
const yuanKeys = [
'F2-11-12',
'F2-14-11',
'F2-26-4',
'F2-27-6',
'F2-28-6',
'F2-57-6',
'F2-58-4'
]
for (const key of yuanKeys) {
const field = findFieldByKeyDeep(storeSchema.list, key)
assert.equal(field?.unit, '元', key)
}
for (const key of ['F2-34', 'F2-35']) {
const field = findFieldByKeyDeep(storeSchema.list, key)
assert.equal(field?.unit, '%', key)
}
})
})