feat(listings): 仓库物资区分赠送与额外收费并展示小计
This commit is contained in:
@@ -1,6 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { listingRatioText } from '@/features/listings/labels'
|
||||
import {
|
||||
listingPriceDetail,
|
||||
listingRatioText,
|
||||
listingResources,
|
||||
resourceBadgeText,
|
||||
resourceChargeText,
|
||||
} from '@/features/listings/labels'
|
||||
|
||||
type RatioItem = {
|
||||
price_cent: number
|
||||
@@ -30,3 +36,116 @@ describe('listingRatioText', () => {
|
||||
expect(listingRatioText(listing({ asset_summary: { publish_ratio: 0 } }))).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('listingPriceDetail', () => {
|
||||
const item = {
|
||||
price_cent: 191350,
|
||||
asset_summary: { pure_coin_price_cent: 176350, extra_item_price_cent: 15000 },
|
||||
}
|
||||
|
||||
it('把额外物资标成收费项', () => {
|
||||
expect(listingPriceDetail(item)).toBe('(纯币租金 ¥1,763.50 + 额外物资收费 ¥150.00)')
|
||||
expect(listingPriceDetail(item, { compact: true })).toBe('纯币 ¥1,763.50 + 物资收费 ¥150.00')
|
||||
})
|
||||
|
||||
it('只有纯币租金时省略收费项,无拆分时不渲染', () => {
|
||||
expect(
|
||||
listingPriceDetail({
|
||||
price_cent: 176350,
|
||||
asset_summary: { pure_coin_price_cent: 176350, extra_item_price_cent: 0 },
|
||||
})
|
||||
).toBe('(纯币租金 ¥1,763.50)')
|
||||
expect(listingPriceDetail({ price_cent: 176350, asset_summary: {} })).toBe('')
|
||||
})
|
||||
})
|
||||
|
||||
describe('resourceChargeText', () => {
|
||||
it('区分赠送、收费与未标注', () => {
|
||||
expect(resourceChargeText('赠送')).toBe('赠送')
|
||||
expect(resourceChargeText('收费')).toBe('额外收费')
|
||||
expect(resourceChargeText('收费', true)).toBe('收费')
|
||||
expect(resourceChargeText('付费')).toBe('未标注')
|
||||
expect(resourceChargeText('')).toBe('未标注')
|
||||
expect(resourceChargeText(undefined)).toBe('未标注')
|
||||
})
|
||||
})
|
||||
|
||||
describe('listingResources', () => {
|
||||
it('归一化模式、计算收费项小计并过滤空项', () => {
|
||||
const rows = listingResources({
|
||||
resources: [
|
||||
{ key: 'ammo6', label: '6级弹', quantity: 50, mode: '收费', price_cent: 10 },
|
||||
{ key: 'helmet6', label: '6头', quantity: 5, mode: '收费', price: '3.9元/个' },
|
||||
{ key: 'med', label: '医疗包', quantity: 3, mode: '赠送', price_cent: 100 },
|
||||
{ key: 'legacy', label: '旧数据', quantity: 2, mode: '付费', price: '2.5元/个' },
|
||||
{ key: 'empty', label: '', quantity: 1, mode: '收费' },
|
||||
{ key: 'zero', label: '零数量', quantity: 0, mode: '收费' },
|
||||
],
|
||||
})
|
||||
|
||||
expect(rows).toEqual([
|
||||
{
|
||||
label: '6级弹',
|
||||
quantity: 50,
|
||||
mode: 'paid',
|
||||
modeText: '额外收费',
|
||||
amountCent: 500,
|
||||
amountText: '5.0',
|
||||
},
|
||||
{
|
||||
label: '6头',
|
||||
quantity: 5,
|
||||
mode: 'paid',
|
||||
modeText: '额外收费',
|
||||
amountCent: 1950,
|
||||
amountText: '19.5',
|
||||
},
|
||||
{
|
||||
label: '医疗包',
|
||||
quantity: 3,
|
||||
mode: 'gift',
|
||||
modeText: '赠送',
|
||||
amountCent: 0,
|
||||
amountText: '',
|
||||
},
|
||||
{
|
||||
label: '旧数据',
|
||||
quantity: 2,
|
||||
mode: 'unknown',
|
||||
modeText: '未标注',
|
||||
amountCent: 0,
|
||||
amountText: '',
|
||||
},
|
||||
])
|
||||
})
|
||||
|
||||
it('缺少 resources 时返回空数组', () => {
|
||||
expect(listingResources(undefined)).toEqual([])
|
||||
expect(listingResources({})).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('resourceBadgeText', () => {
|
||||
const base = { label: '6级弹', quantity: 50, modeText: '额外收费' } as const
|
||||
|
||||
it('收费项带小计金额,赠送与未标注用固定文案', () => {
|
||||
expect(resourceBadgeText({ ...base, mode: 'paid', amountCent: 500, amountText: '5.0' })).toBe(
|
||||
'额外收费 ¥5.0'
|
||||
)
|
||||
expect(
|
||||
resourceBadgeText({ ...base, mode: 'paid', amountCent: 500, amountText: '5.0' }, 'compact')
|
||||
).toBe('收费 ¥5.0')
|
||||
expect(resourceBadgeText({ ...base, mode: 'paid', amountCent: 0, amountText: '' })).toBe(
|
||||
'额外收费'
|
||||
)
|
||||
expect(resourceBadgeText({ ...base, mode: 'gift', amountCent: 0, amountText: '' })).toBe(
|
||||
'随号赠送'
|
||||
)
|
||||
expect(
|
||||
resourceBadgeText({ ...base, mode: 'gift', amountCent: 0, amountText: '' }, 'compact')
|
||||
).toBe('赠送')
|
||||
expect(resourceBadgeText({ ...base, mode: 'unknown', amountCent: 0, amountText: '' })).toBe(
|
||||
'未标注'
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user