import type { VehicleRealtimeRow } from '../../api/types'; import { describe, expect, it } from 'vitest'; import { formatNumber, normalizeMonitorBounds, statusLabel, vehicleStatus } from './monitor'; function vehicle(overrides: Partial = {}): VehicleRealtimeRow { return { vin: 'LTEST000000000001', plate: '粤A00001', phone: '', oem: '', protocols: ['JT808'], sourceStatus: [], sourceCount: 1, onlineSourceCount: 1, online: true, bindingStatus: 'bound', primaryProtocol: 'JT808', longitude: 113.2, latitude: 23.1, speedKmh: 0, socPercent: 80, totalMileageKm: 10, lastSeen: '2026-07-14 01:00:00', ...overrides }; } describe('monitor domain', () => { it('keeps online, motion and unknown status semantics separate', () => { expect(vehicleStatus(vehicle({ online: false }))).toBe('offline'); expect(vehicleStatus(vehicle({ speedKmh: 32 }))).toBe('driving'); expect(vehicleStatus(vehicle({ speedKmh: 0 }))).toBe('idle'); expect(vehicleStatus(vehicle({ lastSeen: '' }))).toBe('unknown'); }); it('formats dense monitor values consistently', () => { expect(formatNumber(12560)).toBe('12,560'); expect(statusLabel('driving')).toBe('行驶'); }); it('normalizes valid WGS-84 viewport bounds and drops unsafe map ranges', () => { expect(normalizeMonitorBounds('113,22,114,24')).toBe('113.000000,22.000000,114.000000,24.000000'); expect(normalizeMonitorBounds('105,31,103,29')).toBe(''); expect(normalizeMonitorBounds('-181,0,181,1')).toBe(''); expect(normalizeMonitorBounds('113,22,Infinity,24')).toBe(''); }); });