customerInfo.pagination.test.mjs
2.36 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
import { describe, it } from 'node:test'
import assert from 'node:assert/strict'
import {
DEFAULT_PAGE_SIZE,
buildCustomerListRequestParams,
canLoadMorePage,
mapCustomerListWithCarType
} from '../shared-subpackage-components/CustomerInfo/customerInfo.pagination.js'
describe('customerInfo.pagination', () => {
it('DEFAULT_PAGE_SIZE is 20', () => {
assert.equal(DEFAULT_PAGE_SIZE, 20)
})
it('canLoadMorePage matches index onReachBottom logic with pageSize 20', () => {
assert.equal(canLoadMorePage(25, 1), true)
assert.equal(canLoadMorePage(25, 2), false)
assert.equal(canLoadMorePage(40, 2), false)
assert.equal(canLoadMorePage(41, 2), true)
assert.equal(canLoadMorePage(0, 1), false)
})
it('buildCustomerListRequestParams forwards explicit numeric flags', () => {
const cases = [
{ input: 0, expected: 0 },
{ input: '0', expected: 0 },
{ input: 1, expected: 1 },
{ input: '1', expected: 1 }
]
cases.forEach(({ input, expected }) => {
const params = buildCustomerListRequestParams({
merchantId: '',
fallbackMerchantId: 1001,
pageNum: 2,
keyword: '张三',
lowPriceFlag: input
})
assert.deepEqual(params, {
merchantId: 1001,
pageNum: 2,
pageSize: DEFAULT_PAGE_SIZE,
statusList: [1],
keyword: '张三',
lowPriceFlag: expected
})
})
})
it('buildCustomerListRequestParams omits absent or null lowPriceFlag', () => {
const cases = [{}, { lowPriceFlag: null }]
cases.forEach((extraOptions) => {
const params = buildCustomerListRequestParams({
merchantId: 1002,
fallbackMerchantId: 1001,
pageNum: 1,
...extraOptions
})
assert.equal(Object.hasOwn(params, 'lowPriceFlag'), false)
})
})
it('mapCustomerListWithCarType builds carType from customer fields', () => {
const list = mapCustomerListWithCarType([
{
customer: {
carBrand: '宝马',
carChildsBrandName: '华晨宝马',
carSeriesName: '3系'
}
}
])
assert.equal(list[0].carType, '宝马-华晨宝马-3系')
})
it('mapCustomerListWithCarType skips items without carSeriesName', () => {
const list = mapCustomerListWithCarType([{ customer: { carBrand: '宝马' } }])
assert.equal(list[0].carType, undefined)
})
})