优化
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
import { addFeeTier, removeFeeTier, validateFeeTiers } from './overseasStorageFeeTiers'
|
||||
import type { OverseasFeeType, OverseasStorageFeeTier } from './overseasStorageFee'
|
||||
|
||||
function tier(id: string, feeType: OverseasFeeType, startDay: number, endDay: number | null): OverseasStorageFeeTier {
|
||||
return { id, feeType, billingUnit: feeType === 'STORAGE' ? 'CBM' : 'PALLET', startDay, endDay, unitPrice: 1, sortNo: 1 }
|
||||
}
|
||||
|
||||
describe('overseas storage fee tier editing', () => {
|
||||
it('adds a new open-ended tier and closes the previous tail', () => {
|
||||
const tiers = [tier('s1', 'STORAGE', 1, null), tier('r1', 'RETURN_STORAGE', 1, null)]
|
||||
expect(addFeeTier(tiers, 'STORAGE')).toBeNull()
|
||||
expect(tiers.filter((item) => item.feeType === 'STORAGE').map(({ startDay, endDay }) => ({ startDay, endDay })))
|
||||
.toEqual([{ startDay: 1, endDay: 1 }, { startDay: 2, endDay: null }])
|
||||
expect(validateFeeTiers(tiers)).toBeNull()
|
||||
})
|
||||
|
||||
it('removes a middle tier and extends the previous range', () => {
|
||||
const tiers = [
|
||||
tier('s1', 'STORAGE', 1, 7), tier('s2', 'STORAGE', 8, 30), tier('s3', 'STORAGE', 31, null),
|
||||
tier('r1', 'RETURN_STORAGE', 1, null),
|
||||
]
|
||||
expect(removeFeeTier(tiers, tiers[1]!)).toBeNull()
|
||||
expect(tiers.slice(0, 2).map(({ startDay, endDay }) => ({ startDay, endDay })))
|
||||
.toEqual([{ startDay: 1, endDay: 30 }, { startDay: 31, endDay: null }])
|
||||
expect(validateFeeTiers(tiers)).toBeNull()
|
||||
})
|
||||
|
||||
it('does not delete the only tier of a fee type', () => {
|
||||
const tiers = [tier('s1', 'STORAGE', 1, null), tier('r1', 'RETURN_STORAGE', 1, null)]
|
||||
expect(removeFeeTier(tiers, tiers[0]!)).toBe('每种费用至少需要保留1档')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user