53 lines
3.6 KiB
TypeScript
53 lines
3.6 KiB
TypeScript
import { createRequire } from 'node:module'
|
||
import { enableAutoUnmount, flushPromises, mount } from '@vue/test-utils'
|
||
import { afterEach, beforeEach, expect, it, vi } from 'vitest'
|
||
import type { OverseasFee, StorageRentCalculation } from '../api/overseasFees'
|
||
import StorageRentFeeDetails from './StorageRentFeeDetails.vue'
|
||
|
||
const { default: ElementPlus } = createRequire(import.meta.url)('element-plus') as typeof import('element-plus')
|
||
enableAutoUnmount(afterEach)
|
||
beforeEach(() => vi.stubGlobal('ResizeObserver', class { observe() {} unobserve() {} disconnect() {} }))
|
||
afterEach(() => vi.unstubAllGlobals())
|
||
const calculation: StorageRentCalculation = {
|
||
sourceBusinessNo: 'TH202611020001', batchNo: 'RB1', ruleCode: 'RETURN_PALLET', billingQuantity: 1, billingUnit: 'PALLET',
|
||
storageDays: 40, previouslyChargedDays: 10, calculatedAmount: 50,
|
||
tiers: [{ startDay: 11, endDay: 30, days: 20, unitPrice: 1.5, amount: 30 }, { startDay: 31, endDay: 40, days: 10, unitPrice: 2, amount: 20 }],
|
||
}
|
||
function fee(calculations?: StorageRentCalculation[]) {
|
||
return { originalCurrency: 'USD', currency: 'CNY', originalAmount: 50, amount: 500, exchangeRate: 10,
|
||
storageRent: { outboundNo: 'OUT1', outboundAt: '2026-11-02T12:00:00Z', calculatedAmount: 50, chargedAmount: null,
|
||
lines: [{ lotId: '1', inboundAt: '2026-09-24T12:00:00Z', quantity: 1, days: 40, calculatedAmount: 50 }], calculations },
|
||
} as OverseasFee
|
||
}
|
||
it('explains whole pallet tiers and skips previously charged days in every fee detail consumer', async () => {
|
||
const wrapper = mount(StorageRentFeeDetails, { props: { fee: fee([calculation]) }, global: { plugins: [ElementPlus] } })
|
||
await flushPromises()
|
||
expect(wrapper.text()).toContain('余一箱仍计一托')
|
||
expect(wrapper.text()).toContain('此前已计费10 天')
|
||
expect(wrapper.text()).toContain('20 天 × 1 托 × USD 1.5 = USD 30')
|
||
expect(wrapper.text()).toContain('10 天 × 1 托 × USD 2 = USD 20')
|
||
expect(wrapper.text()).toContain('USD 50.00 × 10 = CNY 500.00')
|
||
expect(wrapper.text()).toContain('本批次计算金额:USD 50')
|
||
})
|
||
it('shows transit volume and free tier calculations with the saved currency', async () => {
|
||
const transit: StorageRentCalculation = { ...calculation, ruleCode: 'TRANSIT', billingUnit: 'CBM', billingQuantity: 0.8,
|
||
storageDays: 10, previouslyChargedDays: 0, calculatedAmount: 1.92,
|
||
tiers: [{ startDay: 1, endDay: 7, days: 7, unitPrice: 0, amount: 0 }, { startDay: 8, endDay: 10, days: 3, unitPrice: 0.8, amount: 1.92 }] }
|
||
const wrapper = mount(StorageRentFeeDetails, { props: { fee: fee([transit]) }, global: { plugins: [ElementPlus] } })
|
||
await flushPromises()
|
||
expect(wrapper.text()).toContain('7 天 × 0.8 CBM × USD 0 = USD 0')
|
||
expect(wrapper.text()).toContain('3 天 × 0.8 CBM × USD 0.8 = USD 1.92')
|
||
})
|
||
it('distinguishes historical fractional pricing from new whole pallet pricing', async () => {
|
||
const historical: StorageRentCalculation = { ...calculation, ruleCode: 'RETURN_SHARE', billingQuantity: 0.5625,
|
||
storageDays: 1, previouslyChargedDays: 0, calculatedAmount: 0.84375,
|
||
tiers: [{ startDay: 1, endDay: 1, days: 1, unitPrice: 1.5, amount: 0.84375 }] }
|
||
const wrapper = mount(StorageRentFeeDetails, { props: { fee: fee([historical]) }, global: { plugins: [ElementPlus] } })
|
||
await flushPromises()
|
||
expect(wrapper.text()).toContain('历史费用:按原托份额计费')
|
||
expect(wrapper.text()).toContain('1 天 × 0.5625 托 × USD 1.5 = USD 0.84375')
|
||
await wrapper.setProps({ fee: fee([]) })
|
||
expect(wrapper.text()).toContain('未保存完整计算依据')
|
||
expect(wrapper.text()).not.toContain('1 天 × 0.5625')
|
||
})
|