feat(web): Vitest 测试基建与首批单测(#27)+ 公共格式化函数

This commit is contained in:
weijuesen
2026-08-13 14:51:57 +08:00
parent e9991a2954
commit 0e6dc007f3
6 changed files with 1241 additions and 17 deletions
+21
View File
@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest';
import { aiClassLabel, riskLevelLabel } from './format';
describe('aiClassLabel', () => {
it('映射 healthy/sick 为中文', () => {
expect(aiClassLabel('healthy')).toBe('健康');
expect(aiClassLabel('sick')).toBe('疑似异常');
});
it('未知类别原样返回', () => {
expect(aiClassLabel('unknown')).toBe('unknown');
});
});
describe('riskLevelLabel', () => {
it('映射四级风险', () => {
expect(riskLevelLabel('green')).toBe('绿');
expect(riskLevelLabel('yellow')).toBe('黄');
expect(riskLevelLabel('orange')).toBe('橙');
expect(riskLevelLabel('red')).toBe('红');
});
});
+15
View File
@@ -0,0 +1,15 @@
const AI_CLASS_LABELS: Record<string, string> = {
healthy: '健康',
sick: '疑似异常',
};
const RISK_LEVEL_LABELS: Record<string, string> = {
green: '绿',
yellow: '黄',
orange: '橙',
red: '红',
};
export const aiClassLabel = (cls: string) => AI_CLASS_LABELS[cls] || cls;
export const riskLevelLabel = (level: string) => RISK_LEVEL_LABELS[level] || level;