store-v231-template-schema.test.mjs
3.94 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import fs from 'node:fs'
import path from 'node:path'
import { fileURLToPath } from 'node:url'
import { getVisibleList, isFieldVisible } from '../form-engine/visibility.js'
const here = path.dirname(fileURLToPath(import.meta.url))
const fixturesDir = path.join(here, '..', 'fixtures')
function loadJson(name) {
return JSON.parse(fs.readFileSync(path.join(fixturesDir, name), 'utf8'))
}
function loadBareArray(name) {
const source = fs.readFileSync(path.join(fixturesDir, name), 'utf8')
return Function(`return (\n${source}\n)`)()
}
function collectFields(list = []) {
const result = []
const walk = field => {
result.push(field)
for (const child of field.children || []) {
if (Array.isArray(child)) child.forEach(walk)
else walk(child)
}
}
list.forEach(walk)
return result
}
const v230Daily = loadJson('schema-store-daily-v2.3.0.json')
const v230Production = loadJson('schema-store-daily-v2.3.0.prod.json')
const daily = loadJson('schema-store-daily-v2.3.1.json')
const production = loadJson('schema-store-daily-v2.3.1.prod.json')
const newFieldKeys = ['F2-108', 'F2-109', 'F2-110']
const existingSceneCodes = [100101, 100102, 100103, 110101, 110102, 110201, 110202]
describe('store daily template V2.3.1 schema', () => {
it('IT-V231-001: keeps existing fields but excludes unrestricted blocks from used-car', () => {
assert.equal(daily.version, '2.3.1')
assert.equal(daily.formCode, 'store_daily_report')
assert.equal(daily.title, '门店日报 V2.3.1')
assert.deepEqual(daily.list.slice(0, 7).map(field => field.key), [
'F2-101',
'F2-102',
'F2-103',
'F2-104',
'F2-105',
'F2-106',
'F2-107'
])
assert.deepEqual(daily.list.slice(1, 6), v230Daily.list.slice(1, 6))
assert.deepEqual(production.list.slice(1, 6), v230Production.list.slice(1, 6))
for (const schema of [daily, production]) {
for (const key of ['F2-101', 'F2-107']) {
const field = schema.list.find(item => item.key === key)
assert.deepEqual(field.sceneType, [0, 1])
assert.deepEqual(field.baseSceneCode, existingSceneCodes)
}
}
assert.deepEqual(daily.list.slice(7).map(field => field.key), newFieldKeys)
assert.equal(collectFields(daily.list).length, 28)
})
it('IT-V231-002: used-car counters match the XLSX contract', () => {
const expectedLabels = ['新车订单数', '订单置换数', '置换评估数']
newFieldKeys.forEach((key, index) => {
const field = daily.list.find(item => item.key === key)
const rules = { min: 0, integer: true }
if (key === 'F2-109') {
rules.comparisons = [{
operator: 'lte',
fieldKey: 'F2-108',
message: '订单置换数不可大于新车订单数'
}]
}
assert.deepEqual(field, {
label: expectedLabels[index],
sortNum: String(161 + index),
key,
type: 'numberInput',
required: true,
sceneType: [7],
brandId: [],
baseSceneCode: [120101],
rules,
value: 0
})
})
})
it('IT-V231-003: used-car context renders exactly the three counters', () => {
const usedCarContext = {
sceneType: 7,
baseSceneCode: 120101,
sceneList: [{ baseSceneCode: 120101 }]
}
assert.deepEqual(
getVisibleList(daily.list, usedCarContext, {}).map(field => field.key),
newFieldKeys
)
assert.deepEqual(
getVisibleList(production.list, usedCarContext, {}).map(field => field.key),
newFieldKeys
)
for (const key of newFieldKeys) {
const field = daily.list.find(item => item.key === key)
for (const baseSceneCode of [100101, 110101, 110201]) {
assert.equal(isFieldVisible(field, {
sceneType: baseSceneCode === 100101 ? 1 : 0,
baseSceneCode,
sceneList: [{ baseSceneCode }]
}, {}), false)
}
}
})
it('IT-V231-004: daily and production JS fixtures parse and match JSON', () => {
assert.deepEqual(loadBareArray('schema-store-daily-v2.3.1.js'), daily.list)
assert.deepEqual(loadBareArray('schema-store-daily-v2.3.1.prod.js'), production.list)
})
})