car-brand-picker-bridge.test.mjs
3.52 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import { createRequire } from 'node:module'
import { readFileSync } from 'node:fs'
const require = createRequire(import.meta.url)
const bridge = require('../services/carBrandPickerBridge.js')
describe('carBrandPickerBridge', () => {
it('IT-CAR-BRIDGE-001: completeCarPick invokes onResult', () => {
bridge.clearPending()
let result = null
bridge.openCarBrandPick({
merchantId: 10086,
useMerchantBrandMock: true,
onResult(carInfo) {
result = carInfo
}
})
assert.equal(bridge.getPending()?.merchantId, 10086)
const ok = bridge.completeCarPick({
vehicleBrandId: 1,
vehicleBrandName: '问界',
vehicleSubBrandId: 2,
vehicleSubBrandName: 'AITO',
vehicleSeriesId: 3,
vehicleSeriesName: 'M7',
vehicleShapeId: 4,
vehicleShapeName: 'Max'
})
assert.equal(ok, true)
assert.equal(result.vehicleShapeId, 4)
assert.equal(result.displayText, '问界/AITO/M7/Max')
assert.equal(bridge.getPending(), null)
})
it('IT-CAR-BRIDGE-003: carries normalized current three-level selection to series navigation', () => {
const manualThreeLevels = {
vehicleBrandId: 1,
vehicleBrandName: '鸿蒙智行',
vehicleSubBrandId: 2,
vehicleSubBrandName: 'AITO 问界',
vehicleSeriesId: 3,
vehicleSeriesName: '问界M5'
}
bridge.clearPending()
bridge.openCarBrandPick({
merchantId: 10086,
currentValue: manualThreeLevels,
onResult() {}
})
assert.equal(bridge.getPending().currentValue.vehicleSeriesId, 3)
const nav = bridge.getSeriesNavParams({}, [], '', bridge.getPending().currentValue)
assert.equal(nav.currentValue.vehicleSeriesName, '问界M5')
})
it('IT-CAR-BRIDGE-004: snapshots JSON and cascade current values with zero IDs', () => {
const jsonValue = JSON.stringify({
vehicleBrandId: 0,
vehicleBrandName: '零号品牌',
vehicleSubBrandId: 0,
vehicleSubBrandName: '零号子品牌',
vehicleSeriesId: 0,
vehicleSeriesName: '零号车系'
})
bridge.clearPending()
bridge.openCarBrandPick({ merchantId: 1, currentValue: jsonValue, onResult() {} })
assert.equal(bridge.getPending().currentValue.vehicleSeriesId, 0)
assert.equal(bridge.getPending().currentValue.displayText, '零号品牌/零号子品牌/零号车系')
const cascade = [
{ id: '1', name: '岚图' },
{ id: '2', name: '岚图汽车' },
{ id: '3', name: 'FREE' }
]
bridge.openCarBrandPick({ merchantId: 2, currentValue: cascade, onResult() {} })
const nav = bridge.getSeriesNavParams({}, [], '', cascade)
cascade[2].name = '外部篡改'
assert.equal(bridge.getPending().merchantId, 2)
assert.equal(bridge.getPending().currentValue.vehicleSeriesName, 'FREE')
assert.equal(nav.currentValue.displayText, '岚图/岚图汽车/FREE')
})
it('IT-CAR-BRIDGE-005: negotiation page declares currentValue outside the engine branch', () => {
const source = readFileSync(
new URL('../pages/negotiationDetail/negotiationDetail.js', import.meta.url),
'utf8'
)
const start = source.indexOf('openCarBrandForField({ childKey, groupKey, rowIndex } = {})')
const end = source.indexOf('\n\t/** 品牌选择回调', start)
const method = source.slice(start, end)
assert.match(method, /if \(this\.data\.formDisabled \|\| !childKey\) return\s*\n\t\tlet currentValue\s*\n\t\tif \(this\.engine\)/)
assert.match(method, /useMerchantBrandMock: false,\s*\n\t\t\tcurrentValue,/)
})
it('IT-CAR-BRIDGE-002: route uses packageDynamicForm prefix', () => {
assert.match(bridge.PICK_ROUTE, /^packageDynamicForm\./)
})
})