feat(platform): expose realtime service status

This commit is contained in:
lingniu
2026-07-04 02:08:31 +08:00
parent 526377c13f
commit 6b1e36a5a6
11 changed files with 220 additions and 28 deletions

View File

@@ -288,6 +288,66 @@ test('keeps primary protocol when opening vehicle service from realtime vehicles
});
});
test('shows canonical service status in realtime vehicles', async () => {
window.history.replaceState(null, '', '/#/realtime');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-RT-DEGRADED',
plate: '粤ART001',
phone: '',
oem: 'G7s',
protocols: ['GB32960'],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '部分来源离线',
detail: '由实时车辆 API 统一判定',
sourceCount: 2,
onlineSourceCount: 1
}
}],
total: 1,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-RT-DEGRADED')).toBeInTheDocument();
expect(screen.getByText('部分来源离线')).toBeInTheDocument();
});
test('shows vehicle service status in vehicle list', async () => {
window.history.replaceState(null, '', '/#/vehicles');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {