Files
admin-web/src/modules/overseas-business/storageRentPresentation.test.ts
T

51 lines
3.5 KiB
TypeScript
Raw Normal View History

2026-10-26 13:43:08 +08:00
import { describe, expect, it } from 'vitest'
import { storageRentBillingShare, storageRentChargeStatus, storageRentGeneratedAmounts, storageRentSummaryStatus, storageRentTime } from './storageRentPresentation'
import type { StorageRentLot } from './api/storageRent'
it('distinguishes missing charges, genuine free rent and incomplete settlement', () => {
const lot = { status: 'CLEARED', originalQuantity: 4, billingQuantity: 1, billingUnit: 'PALLET', chargeCount: 2, settledChargeCount: 2, settledAmount: 10 } as StorageRentLot
expect(storageRentSummaryStatus(lot)).toBe('已扣款')
expect(storageRentSummaryStatus({ ...lot, settledChargeCount: 1 })).toBe('有待完成扣款')
expect(storageRentSummaryStatus({ ...lot, settledAmount: 0 })).toBe('免租 · 已结算')
expect(storageRentSummaryStatus({ ...lot, chargeCount: 0 })).toBe('仓租记录待核对')
expect(storageRentBillingShare(2, lot)).toBe('0.5 托')
2026-11-03 11:43:50 +08:00
expect(storageRentBillingShare(1, lot, { billingQuantity: 1, billingUnit: 'PALLET' })).toBe('1 托')
2026-10-26 13:43:08 +08:00
})
describe('仓租原币汇总显示', () => {
it('displays server currency groups without adding different currencies', () => {
expect(storageRentGeneratedAmounts({ generatedAmounts: [{ currency: 'USD', amount: 12 }, { currency: 'CNY', amount: 23 }], generatedAmount: null, generatedCurrency: null })).toEqual(['USD 12.00', 'CNY 23.00'])
expect(storageRentGeneratedAmounts({ generatedAmounts: [{ currency: 'EUR', amount: 0 }], generatedAmount: 0, generatedCurrency: 'EUR' })).toEqual(['EUR 0.00'])
})
it('keeps scalar single currency totals and empty totals free of assumed currencies', () => {
expect(storageRentGeneratedAmounts({ generatedAmounts: [], generatedAmount: 8.5, generatedCurrency: 'CNY' })).toEqual(['CNY 8.50'])
expect(storageRentGeneratedAmounts({ generatedAmounts: [], generatedAmount: 0, generatedCurrency: null })).toEqual(['0.00'])
expect(storageRentGeneratedAmounts({ generatedAmounts: [], generatedAmount: null, generatedCurrency: null })).toEqual(['—'])
})
})
describe('仓租扣费状态', () => {
it('labels only settled zero-original-amount charges as rent free', () => {
expect(storageRentChargeStatus({ status: 'SETTLED', originalAmount: 0 })).toBe('免租')
expect(storageRentChargeStatus({ status: 'SETTLED', originalAmount: '0.00' })).toBe('免租')
expect(storageRentChargeStatus({ status: 'SETTLED', originalAmount: 12 })).toBe('已扣费')
expect(storageRentChargeStatus({ status: 'SETTLED', originalAmount: null })).toBe('已扣费')
expect(storageRentChargeStatus({ status: 'CONSUMED', originalAmount: 0 })).toBe('扣费中')
expect(storageRentChargeStatus({ status: 'SETTLE_FAILED', originalAmount: 0 })).toBe('扣费失败')
})
})
describe('仓租带时区时间显示', () => {
it('converts UTC and equivalent offset timestamps before displaying local business dates', () => {
expect(storageRentTime('2026-10-22T18:30:45Z', 'Asia/Shanghai')).toBe('2026-10-23 02:30:45')
expect(storageRentTime('2026-10-23T02:30:45+08:00', 'Asia/Shanghai')).toBe('2026-10-23 02:30:45')
expect(storageRentTime('2026-10-22T02:30:45Z', 'America/Los_Angeles')).toBe('2026-10-21 19:30:45')
})
it('defaults to the browser timezone and handles missing or invalid values', () => {
const value = '2026-10-22T18:30:45Z'
expect(storageRentTime(value)).toBe(storageRentTime(value, Intl.DateTimeFormat().resolvedOptions().timeZone))
expect(storageRentTime(null)).toBe('—')
expect(storageRentTime('invalid')).toBe('—')
})
})