feat(listings): 折算比按整数展示并统一筛选口径
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest'
|
||||
|
||||
import { listingRatioText } from '@/features/listings/labels'
|
||||
|
||||
type RatioItem = {
|
||||
price_cent: number
|
||||
haf_coin_amount: number
|
||||
asset_summary?: Record<string, unknown>
|
||||
}
|
||||
|
||||
function listing(patch: Partial<RatioItem> = {}): RatioItem {
|
||||
return { price_cent: 0, haf_coin_amount: 0, asset_summary: {}, ...patch }
|
||||
}
|
||||
|
||||
describe('listingRatioText', () => {
|
||||
it('优先使用 publish_ratio,并按四舍五入取整到万', () => {
|
||||
expect(listingRatioText(listing({ asset_summary: { publish_ratio: 33.8256 } }))).toBe('34w')
|
||||
expect(listingRatioText(listing({ asset_summary: { publish_ratio: 33.4 } }))).toBe('33w')
|
||||
})
|
||||
|
||||
it('缺少 publish_ratio 时按「万币 / 元」兜底计算', () => {
|
||||
expect(listingRatioText(listing({ haf_coin_amount: 30_000_000, price_cent: 9_369 }))).toBe(
|
||||
'32w'
|
||||
)
|
||||
})
|
||||
|
||||
it('价格或币量缺失时返回空串,不渲染占位', () => {
|
||||
expect(listingRatioText(listing({ haf_coin_amount: 30_000_000 }))).toBe('')
|
||||
expect(listingRatioText(listing({ price_cent: 10_000 }))).toBe('')
|
||||
expect(listingRatioText(listing({ asset_summary: { publish_ratio: 0 } }))).toBe('')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user