import { describe, expect, it } from 'vitest' import { fmtDelta, fmtNum, fmtPct } from '@/utils/format' import { auditTagType, iscTagType, roleTagType, statusTagType } from '@/utils/semantics' describe('数字格式化(A4 千分位基线)', () => { it('fmtNum:千分位与空值占位', () => { expect(fmtNum(1234567)).toBe('1,234,567') expect(fmtNum('98765')).toBe('98,765') expect(fmtNum(0)).toBe('0') expect(fmtNum(null)).toBe('-') expect(fmtNum(undefined)).toBe('-') expect(fmtNum('')).toBe('-') expect(fmtNum('abc')).toBe('abc') // 非数字字符串原样返回 }) it('fmtPct:百分比与非法值', () => { expect(fmtPct(0.9832)).toBe('98.32%') expect(fmtPct(1, 0)).toBe('100%') expect(fmtPct(null)).toBe('-') }) it('fmtDelta:带符号环比', () => { expect(fmtDelta(12)).toBe('+12') expect(fmtDelta(-3)).toBe('-3') expect(fmtDelta(undefined)).toBe('-') }) }) describe('语义色映射(B2)', () => { it('roleTagType:五角色五色,未知角色回落 info', () => { expect(roleTagType('admin')).toBe('danger') expect(roleTagType('ops')).toBe('warning') expect(roleTagType('service')).toBe('success') expect(roleTagType('group')).toBe('primary') expect(roleTagType('customer')).toBe('info') expect(roleTagType('unknown')).toBe('info') }) it('statusTagType:1 启用绿 / 0 禁用灰', () => { expect(statusTagType(1)).toBe('success') expect(statusTagType('0')).toBe('info') }) it('auditTagType:1 通过 / -1 拒绝 / 0 待审', () => { expect(auditTagType(1)).toBe('success') expect(auditTagType(-1)).toBe('danger') expect(auditTagType(0)).toBe('warning') }) it('iscTagType:000 成功 / 5xx 服务侧 / 其余客户端侧', () => { expect(iscTagType('ISC:000')).toBe('success') expect(iscTagType('ISC:500')).toBe('danger') expect(iscTagType('ISC:404')).toBe('warning') }) })