goodsPositionBucket.helpers.test.mjs
3.16 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
KNOWN_POSITIONS,
resolveGoodsPosition,
isKnownPosition,
createEmptyPositionBuckets,
pushToPositionBucket,
filterUpgradeListByPopupType
} from '../tabWorkOrder/services/goodsPositionBucket.helpers.js'
describe('goodsPositionBucket.helpers', () => {
it('resolveGoodsPosition prefers merchantGoodsPosition then upgradeGoodsPosition', () => {
assert.equal(resolveGoodsPosition({ merchantGoodsPosition: 2 }), 2)
assert.equal(
resolveGoodsPosition({ upgradeGoodsPosition: 3 }),
3
)
assert.equal(resolveGoodsPosition({}), undefined)
assert.equal(resolveGoodsPosition(null), undefined)
})
it('isKnownPosition accepts 1-7 only', () => {
assert.equal(isKnownPosition(1), true)
assert.equal(isKnownPosition(7), true)
assert.equal(isKnownPosition(8), false)
assert.equal(isKnownPosition(null), false)
})
it('pushToPositionBucket routes by position regardless of goodsType', () => {
const buckets = createEmptyPositionBuckets()
const film = { merchantGoodsPosition: 1, goodsInfo: { goodsType: 1 } }
const other = { merchantGoodsPosition: 1, goodsInfo: { goodsType: 99 } }
pushToPositionBucket(buckets, film)
pushToPositionBucket(buckets, other)
assert.equal(buckets.frontGearArr.length, 2)
assert.equal(buckets.other.length, 0)
})
it('pushToPositionBucket sends unknown position to other', () => {
const buckets = createEmptyPositionBuckets()
pushToPositionBucket(buckets, { merchantGoodsPosition: 99 })
pushToPositionBucket(buckets, { merchantGoodsPosition: null })
assert.equal(buckets.other.length, 2)
assert.equal(buckets.frontGearArr.length, 0)
})
it('pushToPositionBucket covers all known positions', () => {
const buckets = createEmptyPositionBuckets()
KNOWN_POSITIONS.forEach(pos => {
pushToPositionBucket(buckets, { id: pos }, pos)
})
assert.equal(buckets.frontGearArr.length, 1)
assert.equal(buckets.sideBeforeRearGearArr.length, 1)
assert.equal(buckets.sideRearGearArr.length, 1)
assert.equal(buckets.sideAfterRearGearArr.length, 1)
assert.equal(buckets.skylightArr.length, 3)
assert.equal(buckets.other.length, 0)
})
it('filterUpgradeListByPopupType type 4 returns items without known position', () => {
const list = [
{ id: 1, merchantGoodsPosition: 1, goodsInfo: { goodsType: 99 } },
{ id: 2, goodsInfo: { goodsType: 2 } },
{ id: 3, merchantGoodsPosition: 8 }
]
const result = filterUpgradeListByPopupType(list, 4)
assert.deepEqual(
result.map(i => i.id),
[2, 3]
)
})
it('filterUpgradeListByPopupType type 1/2/3 filter by position', () => {
const list = [
{ id: 'a', merchantGoodsPosition: 1 },
{ id: 'b', merchantGoodsPosition: 2 },
{ id: 'c', merchantGoodsPosition: 5 }
]
assert.deepEqual(
filterUpgradeListByPopupType(list, 1).map(i => i.id),
['a']
)
assert.deepEqual(
filterUpgradeListByPopupType(list, 2, 2).map(i => i.id),
['b']
)
assert.deepEqual(
filterUpgradeListByPopupType(list, 3).map(i => i.id),
['c']
)
})
})