feat(platform): summarize missing vehicle sources

This commit is contained in:
lingniu
2026-07-04 05:38:17 +08:00
parent 6ac980adad
commit bc6715b35b
7 changed files with 150 additions and 0 deletions

View File

@@ -128,6 +128,72 @@ test('dashboard renders vehicle service summary metrics', async () => {
expect(fetchMock).toHaveBeenCalledWith('/api/vehicle-service/summary', undefined);
});
test('opens dashboard coverage from missing source distribution', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = 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/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [{ protocol: 'YUTONG_MQTT', online: 1, total: 8 }],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 983 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('缺失车辆')).toBeInTheDocument();
expect(screen.getByText('983')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '查看缺 YUTONG_MQTT' }));
await waitFor(() => {
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('missingProtocol=YUTONG_MQTT'), undefined);
});
expect(screen.getByText('当前筛选:缺 YUTONG_MQTT')).toBeInTheDocument();
});
test('opens vehicle list filtered by service summary KPI', async () => {
window.history.replaceState(null, '', '/#/dashboard');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {