From edca567d5287b93455ffce8819f800b2ff2f6c58 Mon Sep 17 00:00:00 2001 From: lingniu Date: Sat, 4 Jul 2026 01:25:13 +0800 Subject: [PATCH] feat(platform-web): keep realtime source in vehicle links --- .../apps/web/src/pages/Realtime.tsx | 4 +- .../apps/web/src/test/App.test.tsx | 75 +++++++++++++++++++ 2 files changed, 77 insertions(+), 2 deletions(-) diff --git a/vehicle-data-platform/apps/web/src/pages/Realtime.tsx b/vehicle-data-platform/apps/web/src/pages/Realtime.tsx index ed4dfe0e..31bd097c 100644 --- a/vehicle-data-platform/apps/web/src/pages/Realtime.tsx +++ b/vehicle-data-platform/apps/web/src/pages/Realtime.tsx @@ -11,7 +11,7 @@ function canOpenVehicle(vin?: string) { return Boolean(value && value !== 'unknown'); } -export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string) => void }) { +export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string, protocol?: string) => void }) { const [rows, setRows] = useState([]); const [loading, setLoading] = useState(true); const [filters, setFilters] = useState>({}); @@ -105,7 +105,7 @@ export function Realtime({ onOpenVehicle }: { onOpenVehicle: (vin: string) => vo title: '操作', width: 110, render: (_: unknown, row: VehicleRealtimeRow) => ( - + ) } ]} 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 68afd9a9..dafcec26 100644 --- a/vehicle-data-platform/apps/web/src/test/App.test.tsx +++ b/vehicle-data-platform/apps/web/src/test/App.test.tsx @@ -168,3 +168,78 @@ test('keeps row protocol when opening vehicle service from history results', asy expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-001&protocol=JT808'); }); }); + +test('keeps primary protocol when opening vehicle service from realtime vehicles', async () => { + window.history.replaceState(null, '', '/#/realtime'); + vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => { + const path = String(input); + if (path.includes('/api/realtime/vehicles')) { + return { + ok: true, + json: async () => ({ + data: { + items: [{ + vin: 'VIN-MQTT-001', + plate: '川AHTWO1', + phone: '', + oem: '宇通', + protocols: ['GB32960', 'YUTONG_MQTT'], + sourceCount: 2, + onlineSourceCount: 1, + online: true, + primaryProtocol: 'YUTONG_MQTT', + longitude: 113.2, + latitude: 23.1, + speedKmh: 30, + socPercent: 78, + totalMileageKm: 119925, + lastSeen: '2026-07-03 20:12:10' + }], + total: 1, + limit: 50, + offset: 0 + }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + } + if (path.includes('/api/vehicles/resolve')) { + return { + ok: true, + json: async () => ({ + data: { + lookupKey: 'VIN-MQTT-001', + resolved: true, + vin: 'VIN-MQTT-001', + plate: '川AHTWO1', + phone: '', + oem: '宇通', + protocols: ['GB32960', 'YUTONG_MQTT'], + 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: 10, offset: 0 }, + traceId: 'trace-test', + timestamp: 1783094400000 + }) + } as Response; + }); + + render(); + + expect(await screen.findByText('VIN-MQTT-001')).toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', { name: '车辆服务' })); + + await waitFor(() => { + expect(window.location.hash).toBe('#/detail?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT'); + }); +});