Files
lingniu-vehicle-ingest/vehicle-data-platform/apps/web/src/v2/domain/telemetry.test.ts
2026-07-18 11:09:27 +08:00

24 lines
1.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, expect, it } from 'vitest';
import { formatTelemetryTime, formatTelemetryValue, telemetryQualityLabel } from './telemetry';
describe('latest telemetry presentation', () => {
it('formats server-authoritative scalar values without inferring metadata', () => {
expect(formatTelemetryValue(42.567)).toBe('42.57');
expect(formatTelemetryValue(true)).toBe('是');
expect(formatTelemetryValue(null)).toBe('—');
expect(formatTelemetryValue(1, '启动1')).toBe('启动1');
});
it('translates server quality states', () => {
expect(telemetryQualityLabel('good')).toBe('正常');
expect(telemetryQualityLabel('stale')).toBe('陈旧');
expect(telemetryQualityLabel('warning')).toBe('异常');
});
it('keeps telemetry timestamps compact for local and RFC3339 values', () => {
expect(formatTelemetryTime('2026-07-14T09:24:34+08:00')).toBe('09:24:34');
expect(formatTelemetryTime('2026-07-14 09:24:34')).toBe('09:24:34');
expect(formatTelemetryTime('2026-07-18T02:57:02Z')).toBe('10:57:02');
});
});