feat(platform-web): show source consistency

This commit is contained in:
lingniu
2026-07-04 03:57:26 +08:00
parent 2e50f43ff4
commit 353b71ebbb
2 changed files with 132 additions and 0 deletions

View File

@@ -1720,3 +1720,87 @@ test('shows selected source scope on vehicle detail', async () => {
expect(screen.getByText('部分来源离线')).toBeInTheDocument();
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service?keyword=VIN001&protocol=JT808'), undefined);
});
test('shows cross-source consistency for one vehicle service', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-CONSISTENCY-001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-CONSISTENCY-001',
lookupKey: 'VIN-CONSISTENCY-001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN-CONSISTENCY-001',
resolved: true,
vin: 'VIN-CONSISTENCY-001',
plate: '粤A一致1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
online: true,
lastSeen: '2026-07-03 20:12:10'
},
realtimeSummary: {
vin: 'VIN-CONSISTENCY-001',
plate: '粤A一致1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 32,
socPercent: 78,
totalMileageKm: 1000.5,
lastSeen: '2026-07-03T20:12:10+08:00'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03T20:12:10+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03T20:12:05+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03T20:11:40+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
realtime: [
{ vin: 'VIN-CONSISTENCY-001', plate: '粤A一致1', protocol: 'GB32960', longitude: 113.2, latitude: 23.1, speedKmh: 32, socPercent: 78, totalMileageKm: 1000.5, lastSeen: '2026-07-03T20:12:10+08:00' },
{ vin: 'VIN-CONSISTENCY-001', plate: '粤A一致1', protocol: 'JT808', longitude: 113.201, latitude: 23.101, speedKmh: 30, socPercent: 0, totalMileageKm: 1000.8, lastSeen: '2026-07-03T20:12:05+08:00' },
{ vin: 'VIN-CONSISTENCY-001', plate: '粤A一致1', protocol: 'YUTONG_MQTT', longitude: 113.2, latitude: 23.1, speedKmh: 31, socPercent: 77, totalMileageKm: 1000.7, lastSeen: '2026-07-03T20:11:40+08:00' }
],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('跨来源一致性')).toBeInTheDocument();
expect(screen.getByText('3 个来源')).toBeInTheDocument();
expect(screen.getByText('2/3 在线')).toBeInTheDocument();
expect(screen.getByText('3 个来源有位置')).toBeInTheDocument();
expect(screen.getByText('0.3 km')).toBeInTheDocument();
expect(screen.getByText('30 秒')).toBeInTheDocument();
});