feat(platform): link history locations to mileage evidence

This commit is contained in:
lingniu
2026-07-04 11:54:48 +08:00
parent 2ba30b21cd
commit f305066eff
3 changed files with 140 additions and 4 deletions

View File

@@ -4293,6 +4293,101 @@ test('opens vehicle service from history results with row source evidence', asyn
});
});
test('opens same-day mileage statistics from history location row', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-HISTORY-MILEAGE&protocol=JT808');
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, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/history/locations')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-HISTORY-MILEAGE',
plate: '粤A历史账',
protocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 0,
totalMileageKm: 218.8,
lastSeen: '2026-07-03 20:12:10',
deviceTime: '2026-07-03 20:12:10',
serverTime: '2026-07-03 20:12:11'
}],
total: 1,
limit: 10,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 18.8, averageMileagePerVin: 18.8 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-HISTORY-MILEAGE',
plate: '粤A历史账',
source: 'JT808',
date: '2026-07-03',
startMileageKm: 200,
endMileageKm: 218.8,
dailyMileageKm: 18.8,
anomalySeverity: 'normal'
}],
total: 1,
limit: 20,
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-HISTORY-MILEAGE')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '核对里程' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/mileage?keyword=VIN-HISTORY-MILEAGE&protocol=JT808&dateFrom=2026-07-03&dateTo=2026-07-04');
});
});
test('opens vehicle service from raw history rows with row source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=%E7%B2%A4AG18312&protocol=GB32960');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {