staff-template-schema.test.mjs
4.77 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixtureV211 } from './schemaFixture.mjs'
const staffSchema = loadSchemaFixtureV211('staff')
function findFieldByKey(list, key) {
return list.find(item => item.key === key)
}
function findChildByKey(group, key) {
return (group?.children || []).find(child => child.key === key)
}
/** 递归收集 schema 内全部 key */
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('staff daily template V2.1.1 schema', () => {
it('IT-STAFF-TPL-001: fixture metadata and F1-1 attendance radio', () => {
assert.equal(staffSchema.version, '2.1.1')
assert.equal(staffSchema.formCode, 'staff_daily_report')
assert.equal(staffSchema.list.length, 13)
const f11 = findFieldByKey(staffSchema.list, 'F1-1')
assert.equal(f11?.type, 'radio')
assert.equal(f11?.value, '在岗')
assert.deepEqual(
f11?.options?.map(o => o.value),
['在岗', '调休']
)
})
it('IT-STAFF-TPL-002: F1-2/F1-3 on-duty show rules', () => {
for (const key of ['F1-2', 'F1-3']) {
const field = findFieldByKey(staffSchema.list, key)
assert.equal(field?.rules?.keys?.[0], 'F1-1', key)
assert.match(String(field?.rules?.result), /在岗/, key)
}
})
it('IT-STAFF-TPL-003: F1-12/F1-13 five-realm boutique top-level fields', () => {
for (const key of ['F1-12', 'F1-13']) {
const field = findFieldByKey(staffSchema.list, key)
assert.equal(field?.type, 'numberInput', key)
assert.deepEqual(
field?.brandId,
[3454, 3503, 3458, 3574, 3502],
key
)
assert.deepEqual(field?.baseSceneCode, [100101, 100102, 100103], key)
assert.equal(field?.rules?.keys?.[0], 'F1-1', key)
assert.match(String(field?.rules?.result), /在岗/, key)
}
})
it('IT-STAFF-TPL-004: F1-5问界 group children after V2.1.1 trim', () => {
const group = findFieldByKey(staffSchema.list, 'F1-5')
assert.equal(group?.type, 'group')
assert.deepEqual(group?.brandId, [3454])
assert.deepEqual(group?.baseSceneCode, [100101, 100102, 100103, 110201, 110202])
const childKeys = (group?.children || []).map(c => c.key).sort()
assert.deepEqual(childKeys, ['F1-5-3', 'F1-5-4', 'F1-5-5', 'F1-5-6'])
assert.deepEqual(findChildByKey(group, 'F1-5-3')?.baseSceneCode, [
100101, 100102, 100103
])
assert.deepEqual(findChildByKey(group, 'F1-5-4')?.baseSceneCode, [
110201, 110202
])
})
it('IT-STAFF-TPL-005: removed F1-5-1/F1-5-2 not in schema', () => {
const keys = collectAllKeys(staffSchema.list)
assert.ok(!keys.includes('F1-5-1'))
assert.ok(!keys.includes('F1-5-2'))
assert.ok(!keys.includes('F1-10-1'))
assert.ok(!keys.includes('F1-10-2'))
})
it('IT-STAFF-TPL-006: F1-11 other-brand group has twelve children', () => {
const group = findFieldByKey(staffSchema.list, 'F1-11')
assert.equal(group?.type, 'group')
assert.deepEqual(group?.filterBrandId, [
3454, 3503, 3458, 3574, 3502, 3067
])
const keys = (group?.children || []).map(c => c.key).sort()
assert.equal(keys.length, 12)
assert.ok(keys.includes('F1-11-8'))
assert.ok(keys.includes('F1-11-9'))
assert.ok(keys.includes('F1-11-10'))
const f118 = group.children.find(c => c.key === 'F1-11-8')
assert.deepEqual(f118?.baseSceneCode, [110101, 110102])
})
it('IT-STAFF-TPL-007: F1-5 childrenRules cover active children', () => {
const group = findFieldByKey(staffSchema.list, 'F1-5')
const rules = group?.childrenRules || {}
for (const key of ['F1-5-3', 'F1-5-4', 'F1-5-5', 'F1-5-6']) {
assert.equal(rules[key]?.integer, true, key)
assert.equal(rules[key]?.min, 0, key)
}
})
it('IT-STAFF-TPL-008: F1-10岚图 group is warranty-only', () => {
const group = findFieldByKey(staffSchema.list, 'F1-10')
assert.deepEqual(group?.baseSceneCode, [110201, 110202])
const childKeys = (group?.children || []).map(c => c.key)
assert.deepEqual(childKeys, ['F1-10-3', 'F1-10-4', 'F1-10-5'])
})
it('IT-STAFF-TPL-009: F1-11-1 lantu-or-other-brand uses empty brandId', () => {
const group = findFieldByKey(staffSchema.list, 'F1-11')
const child = findChildByKey(group, 'F1-11-1')
assert.deepEqual(child?.brandId, [])
assert.deepEqual(child?.filterBrandId, [3454, 3503, 3458, 3574, 3502])
assert.deepEqual(child?.baseSceneCode, [100101, 100102, 100103])
})
it('IT-STAFF-TPL-010: F1-3 refund amount has unit 元 from Excel rule', () => {
const field = findFieldByKey(staffSchema.list, 'F1-3')
assert.equal(field?.label, '延保退单金额')
assert.equal(field?.unit, '元')
assert.equal(field?.rules?.decimal, true)
})
})