feat(platform): surface priority alert evidence

This commit is contained in:
lingniu
2026-07-04 15:02:27 +08:00
parent cac978f46f
commit 21294e8b79
3 changed files with 208 additions and 0 deletions

View File

@@ -820,6 +820,121 @@ test('dashboard exposes end-to-end operations workflow entries', async () => {
});
});
test('dashboard surfaces highest priority quality issue with evidence shortcuts', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/ops/health')) {
return {
ok: true,
json: async () => ({
data: { linkHealth: [], kafkaLag: 0, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 88,
activeToday: 96,
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: 88,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 0,
identityRequiredVehicles: 0,
archiveIncompleteVehicles: 0,
serviceStatuses: [],
protocols: [],
missingSources: [],
archiveMissingFields: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: '',
plate: '粤A告警1',
phone: '13307795425',
sourceEndpoint: '115.231.168.135:43625',
protocol: 'JT808',
issueType: 'VIN_MISSING',
severity: 'error',
lastSeen: '2026-07-03 20:12:10',
detail: 'JT808 数据缺少 VIN 映射'
}],
total: 1,
limit: 5,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/summary')) {
return {
ok: true,
json: async () => ({
data: { issueVehicleCount: 7, issueRecordCount: 9, errorCount: 1, warningCount: 8, protocols: [], issueTypes: [] },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('最高优先级告警')).toBeInTheDocument();
expect(screen.getByText('粤A告警1 / 13307795425')).toBeInTheDocument();
expect(screen.getByText('VIN 缺失')).toBeInTheDocument();
expect(screen.getByText('JT808 数据缺少 VIN 映射')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '首页告警轨迹证据' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/history?keyword=%E7%B2%A4A%E5%91%8A%E8%AD%A61&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
});
test('dashboard keeps core vehicle service metrics when preview requests fail', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {