feat(platform): export vehicle service dossier

This commit is contained in:
lingniu
2026-07-04 11:07:46 +08:00
parent 8dc64bd294
commit 688cf0a155
2 changed files with 157 additions and 1 deletions

View File

@@ -5271,6 +5271,101 @@ test('copies shareable vehicle service detail link', async () => {
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('/#/detail?keyword=VIN001&protocol=JT808'));
});
test('exports vehicle detail service dossier as csv', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-REPORT-001&protocol=GB32960');
const createObjectURL = vi.spyOn(URL, 'createObjectURL').mockReturnValue('blob:vehicle-report');
const revokeObjectURL = vi.spyOn(URL, 'revokeObjectURL').mockImplementation(() => undefined);
const click = vi.spyOn(HTMLAnchorElement.prototype, 'click').mockImplementation(() => undefined);
const appendChild = vi.spyOn(document.body, 'appendChild');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-REPORT-001',
lookupKey: 'VIN-REPORT-001',
lookupResolved: true,
serviceOverview: {
vin: 'VIN-REPORT-001',
plate: '粤A档案导出',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
primaryProtocol: 'GB32960',
coverageStatus: 'partial',
sourceCount: 3,
onlineSourceCount: 2,
lastSeen: '2026-07-03 20:12:10',
realtimeCount: 3,
historyCount: 12,
rawCount: 34,
mileageCount: 7,
qualityIssueCount: 1
},
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线',
sourceCount: 3,
onlineSourceCount: 2
},
sourceConsistency: {
sourceCount: 3,
onlineSourceCount: 2,
locatedSourceCount: 2,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 1.4,
sourceTimeDeltaSeconds: 125,
scope: 'vehicle',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'MQTT 离线32960 与 808 仍可支撑车辆服务'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:08', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03 20:10:05', hasRealtime: true, hasHistory: false, hasRaw: true, hasMileage: false }
],
realtime: [],
history: { items: [], total: 12, limit: 20, offset: 0 },
raw: { items: [], total: 34, limit: 10, offset: 0 },
mileage: { items: [], total: 7, limit: 20, offset: 0 },
quality: { items: [], total: 1, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆服务结论')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: /导出档案 CSV/ }));
expect(createObjectURL).toHaveBeenCalled();
expect(click).toHaveBeenCalled();
expect(revokeObjectURL).toHaveBeenCalledWith('blob:vehicle-report');
const link = appendChild.mock.calls.find(([node]) => node instanceof HTMLAnchorElement)?.[0] as HTMLAnchorElement | undefined;
expect(link?.download).toBe('vehicle-service-VIN-REPORT-001-GB32960.csv');
});
test('opens history with the currently selected vehicle detail source', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {