productStrategy.test.mjs
1.75 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import * as orderStrategyUi from '../pages/carQuotation/services/orderStrategyUi.js'
const { ORDER_TYPE, shouldShowOrderStrategyBox } = orderStrategyUi
describe('orderStrategyUi shouldShowOrderStrategyBox', () => {
it('shows strategy UI only for discount, gift, and combination order types', () => {
assert.equal(shouldShowOrderStrategyBox(ORDER_TYPE.DISCOUNT), true)
assert.equal(shouldShowOrderStrategyBox(ORDER_TYPE.GIFT), true)
assert.equal(shouldShowOrderStrategyBox(ORDER_TYPE.COMBINATION), true)
})
it('hides strategy UI for normal, impulse, and internal settlement', () => {
assert.equal(shouldShowOrderStrategyBox(ORDER_TYPE.NORMAL), false)
assert.equal(shouldShowOrderStrategyBox(ORDER_TYPE.IMPULSE), false)
assert.equal(shouldShowOrderStrategyBox(ORDER_TYPE.INTERNAL_SETTLEMENT), false)
})
})
describe('orderStrategyUi buildOrderTypeSelectionState', () => {
it('keeps a selected discount order type in the parent patch when goods change later', () => {
assert.equal(typeof orderStrategyUi.buildOrderTypeSelectionState, 'function')
const orderInfo = {
orderType: ORDER_TYPE.NORMAL,
vdQuotationGoodsList: [{ goods: { id: 'goods-1' } }]
}
const snapshot = structuredClone(orderInfo)
const result = orderStrategyUi.buildOrderTypeSelectionState(
orderInfo,
ORDER_TYPE.DISCOUNT
)
assert.deepEqual(result, {
changed: true,
orderInfo: {
orderType: ORDER_TYPE.DISCOUNT,
vdQuotationGoodsList: [{ goods: { id: 'goods-1' } }]
},
orderPatch: { orderType: ORDER_TYPE.DISCOUNT }
})
assert.deepEqual(orderInfo, snapshot)
assert.notEqual(result.orderInfo, orderInfo)
})
})