feat(platform-web): show dashboard row service status

This commit is contained in:
lingniu
2026-07-04 02:11:32 +08:00
parent 6b1e36a5a6
commit 4c27cfa28d
2 changed files with 146 additions and 0 deletions

View File

@@ -57,6 +57,121 @@ test('shows vehicle service status distribution on dashboard', async () => {
expect(screen.getByText('39')).toBeInTheDocument();
});
test('shows row service status in dashboard vehicle previews', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-COVERAGE-WARN',
plate: '粤A预警1',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '覆盖部分离线',
detail: '覆盖预览由 API 判定',
sourceCount: 2,
onlineSourceCount: 1
}
}],
total: 1,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-REALTIME-OFFLINE',
plate: '粤A离线1',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
sourceCount: 1,
onlineSourceCount: 0,
online: false,
bindingStatus: 'bound',
serviceStatus: {
status: 'offline',
severity: 'error',
title: '实时车辆离线',
detail: '实时预览由 API 判定',
sourceCount: 1,
onlineSourceCount: 0
},
primaryProtocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 0,
socPercent: 0,
totalMileageKm: 100,
lastSeen: '2026-07-03 20:12:10'
}],
total: 1,
limit: 8,
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-COVERAGE-WARN')).toBeInTheDocument();
expect(screen.getByText('覆盖部分离线')).toBeInTheDocument();
expect(screen.getByText('VIN-REALTIME-OFFLINE')).toBeInTheDocument();
expect(screen.getByText('实时车辆离线')).toBeInTheDocument();
});
test('opens vehicle detail from shareable hash', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=%E7%B2%A4AG18312');
vi.spyOn(globalThis, 'fetch').mockResolvedValue({