From 857c96734dd703a05efe2b540dcd21509a94400a Mon Sep 17 00:00:00 2001 From: lingniu Date: Sat, 4 Jul 2026 06:23:20 +0800 Subject: [PATCH] fix(platform): keep mileage source when opening vehicle --- .../apps/web/src/pages/Mileage.tsx | 4 +- .../apps/web/src/test/App.test.tsx | 152 ++++++++++++++++++ 2 files changed, 154 insertions(+), 2 deletions(-) diff --git a/vehicle-data-platform/apps/web/src/pages/Mileage.tsx b/vehicle-data-platform/apps/web/src/pages/Mileage.tsx index b6c05a32..b8184c22 100644 --- a/vehicle-data-platform/apps/web/src/pages/Mileage.tsx +++ b/vehicle-data-platform/apps/web/src/pages/Mileage.tsx @@ -74,7 +74,7 @@ export function Mileage({ initialVin, initialProtocol, onOpenVehicle }: { initia title="里程统计" description="按车辆汇总每日里程、区间里程和异常差值分析" actions={( - )} @@ -149,7 +149,7 @@ export function Mileage({ initialVin, initialProtocol, onOpenVehicle }: { initia title: '操作', width: 110, render: (_: unknown, row: DailyMileageRow) => ( - + ) } ]} diff --git a/vehicle-data-platform/apps/web/src/test/App.test.tsx b/vehicle-data-platform/apps/web/src/test/App.test.tsx index 7b79f327..f6080a0a 100644 --- a/vehicle-data-platform/apps/web/src/test/App.test.tsx +++ b/vehicle-data-platform/apps/web/src/test/App.test.tsx @@ -1536,6 +1536,158 @@ test('shows vehicle and source scope on mileage hash', async () => { expect(screen.getByText('当前来源:GB32960')).toBeInTheDocument(); }); +test('opens current vehicle service from mileage header with current source evidence', async () => { + window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-HEADER&protocol=GB32960'); + 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/mileage/summary')) { + return { + ok: true, + json: async () => ({ + data: { vehicleCount: 1, recordCount: 0, sourceCount: 1, totalMileageKm: 0, averageMileagePerVin: 0 }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/vehicles/resolve')) { + return { + ok: true, + json: async () => ({ + data: { + lookupKey: 'VIN-MILEAGE-HEADER', + resolved: true, + vin: 'VIN-MILEAGE-HEADER', + plate: '', + phone: '', + oem: '', + protocols: ['GB32960'], + online: true, + lastSeen: '2026-07-03 20:12:10' + }, + 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(); + + expect(await screen.findByText('当前来源:GB32960')).toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: '当前车辆服务' })); + + await waitFor(() => { + expect(window.location.hash).toBe('#/detail?keyword=VIN-MILEAGE-HEADER&protocol=GB32960'); + }); +}); + +test('opens vehicle service from mileage row with row source evidence', async () => { + window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-ROW&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/mileage/summary')) { + return { + ok: true, + json: async () => ({ + data: { vehicleCount: 1, recordCount: 1, sourceCount: 1, totalMileageKm: 12.3, averageMileagePerVin: 12.3 }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/mileage/daily')) { + return { + ok: true, + json: async () => ({ + data: { + items: [{ + vin: 'VIN-MILEAGE-ROW', + plate: '粤AG18312', + source: 'JT808', + date: '2026-07-03', + startMileageKm: 100, + endMileageKm: 112.3, + dailyMileageKm: 12.3, + anomalySeverity: '' + }], + total: 1, + limit: 20, + offset: 0 + }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/vehicles/resolve')) { + return { + ok: true, + json: async () => ({ + data: { + lookupKey: 'VIN-MILEAGE-ROW', + resolved: true, + vin: 'VIN-MILEAGE-ROW', + plate: '粤AG18312', + phone: '', + oem: 'G7s', + protocols: ['JT808'], + online: true, + lastSeen: '2026-07-03 20:12:10' + }, + 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(); + + expect(await screen.findByText('VIN-MILEAGE-ROW')).toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: '车辆服务' })); + + await waitFor(() => { + expect(window.location.hash).toBe('#/detail?keyword=VIN-MILEAGE-ROW&protocol=JT808'); + }); +}); + test('opens vehicle service from history results with row source evidence', async () => { window.history.replaceState(null, '', '/#/history?keyword=%E7%B2%A4AG18312&protocol=JT808'); vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {