order-display-helpers.test.mjs
3.76 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
import assert from 'node:assert/strict'
import { describe, it } from 'node:test'
import {
buildOrderDisplayInfo,
formatOrderGoodsUnitPrice,
resolveOrderGoodsUnitPrice,
resolveOrderPackageFinalPrice,
resolveConstructionButton,
sumOrderMoney
} from '../../tabWorkOrder/utils/orderDisplay.helpers.js'
describe('工单客户信息展示适配', () => {
it('客户对象中的手机号和车牌号不会被订单顶层空值覆盖', () => {
const result = buildOrderDisplayInfo({
orderCode: 'ORDER-NESTED',
customerPhone: '',
plateNumber: null,
customer: {
customerName: '测试客户',
customerPhone: '13800138000',
plateNumber: '粤A12345'
},
payOrder: {
payType: '门店收款'
}
})
assert.equal(result.orderCode, 'ORDER-NESTED')
assert.equal(result.customerName, '测试客户')
assert.equal(result.payType, '门店收款')
assert.equal(result.customerPhone, '13800138000')
assert.equal(result.plateNumber, '粤A12345')
})
it('客户对象缺少字段时回退订单顶层的有效手机号和车牌号', () => {
const result = buildOrderDisplayInfo({
customerPhone: '13900139000',
plateNumber: '粤B54321',
customer: {
customerPhone: ' '
}
})
assert.equal(result.customerPhone, '13900139000')
assert.equal(result.plateNumber, '粤B54321')
})
it('confirmFlag=1 保留兼容确认施工状态映射', () => {
assert.deepEqual(resolveConstructionButton(1), {
showBtn: '确认订单是否施工',
btnName: 'confirmConstruction'
})
assert.deepEqual(resolveConstructionButton('1'), {
showBtn: '确认订单是否施工',
btnName: 'confirmConstruction'
})
assert.deepEqual(resolveConstructionButton(0), { showBtn: false })
assert.deepEqual(resolveConstructionButton(2), { showBtn: false })
assert.deepEqual(resolveConstructionButton('unexpected'), {
showBtn: false
})
})
})
describe('工单商品金额展示适配', () => {
it('套餐子商品总价除以数量时消除浮点尾数', () => {
assert.equal(
resolveOrderGoodsUnitPrice({
finalPrice: 9999.95,
number: 5,
upgradePrice: 1999.99
}),
1999.99
)
})
it('数量无效时回退商品单价且不产生 Infinity 或 NaN', () => {
assert.equal(
resolveOrderGoodsUnitPrice({
finalPrice: 9999.95,
number: 0,
upgradePrice: 1999.99
}),
1999.99
)
assert.equal(
resolveOrderGoodsUnitPrice({
finalPrice: 9999.95,
number: 'invalid',
upgradePrice: 1999.99
}),
1999.99
)
})
it('赠品始终按零价格展示', () => {
assert.equal(
resolveOrderGoodsUnitPrice({
discountType: 4,
finalPrice: 100,
number: 5,
upgradePrice: 20
}),
0
)
})
it('页面展示价格始终保留两位小数', () => {
assert.equal(
formatOrderGoodsUnitPrice({ finalPrice: 9999.95, number: 5 }),
'1999.99'
)
assert.equal(
formatOrderGoodsUnitPrice({ finalPrice: 0, number: 5 }),
'0.00'
)
assert.equal(
formatOrderGoodsUnitPrice({ discountType: 4, number: 5 }),
'0.00'
)
})
it('套餐汇总直接使用非赠品子项权威总价', () => {
assert.equal(sumOrderMoney([1999.98, 1498.99, 1999.99]), 5498.96)
assert.equal(
resolveOrderPackageFinalPrice([
{ finalPrice: 10, number: 3 },
{ finalPrice: 10, upgradePrice: 4 },
{ discountType: 4, finalPrice: 100 }
]),
20
)
assert.equal(
resolveOrderPackageFinalPrice([
{ finalPrice: 9999.9 },
{ finalPrice: 7494.95 },
{ finalPrice: 9999.95 }
]),
27494.8
)
})
})