v211-template-visibility.test.mjs
10.7 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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { loadSchemaFixtureV211 } from './schemaFixture.mjs'
const BASE_SCENE_CODE = {
'1.1': 100101,
'1.2': 100102,
'1.3': 100103,
'2.1.1': 110101,
'2.1.2': 110102,
'2.3.1': 110201,
'2.3.2': 110202
}
/** 与 convert 脚本 extract_scene_codes 契约一致(边界匹配,防 2.1.1 误命中 1.1) */
function extractSceneCodes(visibility) {
const codes = []
for (const token of Object.keys(BASE_SCENE_CODE).sort((a, b) => b.length - a.length)) {
const pattern = new RegExp(`(?<![\\d.])${token.replace(/\./g, '\\.')}(?![\\d.])`)
if (pattern.test(visibility)) {
codes.push(BASE_SCENE_CODE[token])
}
}
return [...new Set(codes)].sort((a, b) => a - b)
}
function findFieldByKey(list, key) {
return list.find(item => item.key === key)
}
function findChildByKey(group, key) {
return (group?.children || []).find(child => child.key === key)
}
const staffSchema = loadSchemaFixtureV211('staff')
const storeSchema = loadSchemaFixtureV211('store')
describe('V2.1.1 scene code extraction contract', () => {
it('IT-V211-001: 2.1.1 visibility must not include boutique codes', () => {
assert.deepEqual(extractSceneCodes('[场景 包含 2.1.1 or 2.1.2] 则 [显示]'), [
110101, 110102
])
})
it('IT-V211-002: combined warranty/equity visibility excludes boutique', () => {
assert.deepEqual(
extractSceneCodes(
'[场景 包含 2.3.1 or 2.3.2 or 2.1.1 or 2.1.2] 则 [显示]'
),
[110101, 110102, 110201, 110202]
)
})
it('IT-V211-003: boutique-only visibility unchanged', () => {
assert.deepEqual(extractSceneCodes('[场景 包含 1.1 or 1.2 or 1.3] 则 [显示]'), [
100101, 100102, 100103
])
})
})
describe('V2.1.1 staff template baseSceneCode', () => {
const f111 = findFieldByKey(staffSchema.list, 'F1-11')
it('IT-V211-STAFF-001: F1-11 equity children use QY codes only', () => {
for (const key of ['F1-11-5', 'F1-11-6', 'F1-11-8']) {
const child = findChildByKey(f111, key)
assert.deepEqual(child?.baseSceneCode, [110101, 110102], key)
}
})
it('IT-V211-STAFF-002: F1-11 warranty child keeps YB codes only', () => {
const child = findChildByKey(f111, 'F1-11-7')
assert.deepEqual(child?.baseSceneCode, [110201, 110202])
})
})
describe('V2.1.1 store template baseSceneCode', () => {
it('IT-V211-STORE-001: F2-11 equity children use QY codes only', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-11')
const row = subform?.children?.[0] || []
for (const key of ['F2-11-6', 'F2-11-7', 'F2-11-8']) {
const child = row.find(item => item.key === key)
assert.deepEqual(child?.baseSceneCode, [110101, 110102], key)
}
})
it('IT-V211-STORE-002: F2-14 equity children use QY codes only', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-14')
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-V211-STORE-003: other-brand combined parents exclude boutique codes', () => {
const expected = [110101, 110102, 110201, 110202]
for (const key of ['F2-44', 'F2-51', 'F2-8', 'F2-11', 'F2-14']) {
const field = findFieldByKey(storeSchema.list, key)
assert.deepEqual(field?.baseSceneCode, expected, key)
}
})
})
/** 与 form-engine matchesBaseSceneCode 契约一致,避免测试环境 ESM/CJS 混用 */
function matchesBaseSceneCode(field, ctx) {
const fieldCodes = (field?.baseSceneCode || []).map(code => Number(code))
if (!fieldCodes.length) return true
const merchantCodes = (ctx.sceneList || []).map(item => Number(item?.baseSceneCode))
return fieldCodes.some(code => merchantCodes.includes(code))
}
/** 与 form-engine brandSpec 契约一致 */
function matchesBrandSpec(field, ctx) {
const brandIds = ctx.brandIds || []
if (field.brandId?.length > 0) {
const hasIntersection = field.brandId.some(id => brandIds.includes(id))
if (!hasIntersection) return false
}
if (field.filterBrandId?.length > 0 && brandIds.length > 0) {
const hasOtherBrand = brandIds.some(id => !field.filterBrandId.includes(id))
if (!hasOtherBrand) return false
}
return true
}
function isFieldVisibleForTest(field, ctx) {
return matchesBaseSceneCode(field, ctx) && matchesBrandSpec(field, ctx)
}
describe('V2.1.1 visibility contract under boutique-only scene', () => {
const boutiqueCtx = {
baseSceneCode: 100101,
brandIds: [3454, 2161],
sceneList: [{ baseSceneCode: 100101 }]
}
const equityCtx = {
baseSceneCode: 110101,
brandIds: [9999],
sceneList: [{ baseSceneCode: 110101 }]
}
const warrantyCtx = {
baseSceneCode: 110201,
brandIds: [9999],
sceneList: [{ baseSceneCode: 110201 }]
}
const otherBrandCtx = {
baseSceneCode: 100101,
brandIds: [9999],
sceneList: [{ baseSceneCode: 100101 }]
}
it('IT-V211-STAFF-003: F1-11 equity/warranty children do not match boutique scene', () => {
const f111 = findFieldByKey(staffSchema.list, 'F1-11')
for (const key of ['F1-11-5', 'F1-11-6', 'F1-11-7', 'F1-11-8']) {
const child = findChildByKey(f111, key)
assert.equal(matchesBaseSceneCode(child, boutiqueCtx), false, key)
}
for (const key of ['F1-11-1', 'F1-11-2', 'F1-11-9']) {
const child = findChildByKey(f111, key)
assert.equal(matchesBaseSceneCode(child, boutiqueCtx), true, key)
}
})
it('IT-V211-STORE-004: other-brand warranty/equity parents do not match boutique scene', () => {
for (const key of ['F2-11', 'F2-14', 'F2-44', 'F2-51', 'F2-8']) {
const field = findFieldByKey(storeSchema.list, key)
assert.equal(matchesBaseSceneCode(field, otherBrandCtx), false, key)
}
})
it('IT-V211-STORE-005: F2-11 equity row cells do not match boutique scene', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-11')
const rowTemplate = subform?.children?.[0] || []
for (const key of ['F2-11-6', 'F2-11-7', 'F2-11-8']) {
const cell = rowTemplate.find(item => item.key === key)
assert.equal(matchesBaseSceneCode(cell, otherBrandCtx), false, key)
}
})
it('IT-V211-STORE-006: F2-14-12 matches warranty scene only', () => {
const subform = findFieldByKey(storeSchema.list, 'F2-14')
const rowTemplate = subform?.children?.[0] || []
const cell = rowTemplate.find(item => item.key === 'F2-14-12')
assert.equal(matchesBaseSceneCode(cell, warrantyCtx), true)
assert.equal(matchesBaseSceneCode(cell, equityCtx), false)
assert.equal(matchesBaseSceneCode(cell, boutiqueCtx), false)
})
it('IT-V211-STAFF-004: equity scene matches F1-11广联权益 children only', () => {
const f111 = findFieldByKey(staffSchema.list, 'F1-11')
for (const key of ['F1-11-5', 'F1-11-6', 'F1-11-8']) {
const child = findChildByKey(f111, key)
assert.equal(matchesBaseSceneCode(child, equityCtx), true, key)
}
for (const key of ['F1-11-1', 'F1-11-3', 'F1-11-7']) {
const child = findChildByKey(f111, key)
assert.equal(matchesBaseSceneCode(child, equityCtx), false, key)
}
})
it('IT-V211-STAFF-005: F1-12 boutique fields do not match equity-only scene', () => {
for (const key of ['F1-12', 'F1-13']) {
const field = findFieldByKey(staffSchema.list, key)
assert.equal(matchesBaseSceneCode(field, equityCtx), false, key)
}
})
})
describe('V2.1.1 store lantu-or-other-brand visibility', () => {
const boutiqueScene = [{ baseSceneCode: 100101 }]
const otherOnlyCtx = {
baseSceneCode: 100101,
brandIds: [9999],
sceneList: boutiqueScene
}
const lantuOnlyCtx = {
baseSceneCode: 100101,
brandIds: [3067],
sceneList: boutiqueScene
}
const fiveRealmOnlyCtx = {
baseSceneCode: 100101,
brandIds: [3454],
sceneList: boutiqueScene
}
const mixedCtx = {
baseSceneCode: 100101,
brandIds: [3454, 9999],
sceneList: boutiqueScene
}
it('IT-V211-STORE-007: F2-57/F2-58 visible for other-brand-only merchant', () => {
for (const key of ['F2-57', 'F2-58']) {
const field = findFieldByKey(storeSchema.list, key)
assert.equal(isFieldVisibleForTest(field, otherOnlyCtx), true, key)
}
})
it('IT-V211-STORE-008: F2-57/F2-58 visible for lantu-only merchant', () => {
for (const key of ['F2-57', 'F2-58']) {
const field = findFieldByKey(storeSchema.list, key)
assert.equal(isFieldVisibleForTest(field, lantuOnlyCtx), true, key)
}
})
it('IT-V211-STORE-009: F2-57/F2-58 hidden for five-realm-only merchant', () => {
for (const key of ['F2-57', 'F2-58']) {
const field = findFieldByKey(storeSchema.list, key)
assert.equal(isFieldVisibleForTest(field, fiveRealmOnlyCtx), false, key)
}
})
it('IT-V211-STORE-010: F2-57/F2-58 visible when five-realm plus other brand', () => {
for (const key of ['F2-57', 'F2-58']) {
const field = findFieldByKey(storeSchema.list, key)
assert.equal(isFieldVisibleForTest(field, mixedCtx), true, key)
}
})
it('IT-V211-STORE-011: F2-23 visible for other-brand-only merchant', () => {
const field = findFieldByKey(storeSchema.list, 'F2-23')
assert.equal(isFieldVisibleForTest(field, otherOnlyCtx), true)
})
it('IT-V211-STORE-012: F2-37 visible for lantu-or-other-brand with boutique scene', () => {
const field = findFieldByKey(storeSchema.list, 'F2-37')
assert.equal(isFieldVisibleForTest(field, otherOnlyCtx), true)
assert.equal(isFieldVisibleForTest(field, lantuOnlyCtx), true)
assert.equal(isFieldVisibleForTest(field, fiveRealmOnlyCtx), false)
})
it('IT-V211-STORE-013: F2-37 hidden when boutique scene missing', () => {
const field = findFieldByKey(storeSchema.list, 'F2-37')
const warrantyOnlyCtx = {
baseSceneCode: 110201,
brandIds: [9999],
sceneList: [{ baseSceneCode: 110201 }]
}
assert.equal(isFieldVisibleForTest(field, warrantyOnlyCtx), false)
})
})
describe('V2.1.1 staff lantu-or-other-brand visibility', () => {
const boutiqueScene = [{ baseSceneCode: 100101 }]
const otherOnlyCtx = {
baseSceneCode: 100101,
brandIds: [9999],
sceneList: boutiqueScene
}
const lantuOnlyCtx = {
baseSceneCode: 100101,
brandIds: [3067],
sceneList: boutiqueScene
}
const fiveRealmOnlyCtx = {
baseSceneCode: 100101,
brandIds: [3454],
sceneList: boutiqueScene
}
it('IT-V211-STAFF-006: F1-11-1 visible for other-brand-only merchant', () => {
const f111 = findFieldByKey(staffSchema.list, 'F1-11')
const child = findChildByKey(f111, 'F1-11-1')
assert.equal(isFieldVisibleForTest(child, otherOnlyCtx), true)
})
it('IT-V211-STAFF-007: F1-11-1 visible for lantu-only merchant', () => {
const f111 = findFieldByKey(staffSchema.list, 'F1-11')
const child = findChildByKey(f111, 'F1-11-1')
assert.equal(isFieldVisibleForTest(child, lantuOnlyCtx), true)
})
it('IT-V211-STAFF-008: F1-11-1 hidden for five-realm-only merchant', () => {
const f111 = findFieldByKey(staffSchema.list, 'F1-11')
const child = findChildByKey(f111, 'F1-11-1')
assert.equal(isFieldVisibleForTest(child, fiveRealmOnlyCtx), false)
})
})