fix(platform): keep realtime source when opening vehicle

This commit is contained in:
lingniu
2026-07-04 07:08:42 +08:00
parent 84f578bcc7
commit df78bb5e20
2 changed files with 79 additions and 1 deletions

View File

@@ -160,7 +160,7 @@ export function Realtime({
title: '操作',
width: 110,
render: (_: unknown, row: VehicleRealtimeRow) => (
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, row.primaryProtocol)}></Button>
<Button disabled={!canOpenVehicle(row.vin)} onClick={() => onOpenVehicle(row.vin, filters.protocol || row.primaryProtocol)}></Button>
)
}
]}

View File

@@ -2413,6 +2413,84 @@ test('opens vehicle service from realtime vehicles with primary source evidence'
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=VIN-MQTT-001&protocol=YUTONG_MQTT'), undefined);
});
test('opens vehicle service from realtime vehicles with current source filter', async () => {
window.history.replaceState(null, '', '/#/realtime?keyword=VIN-RT-FILTER&protocol=JT808');
const fetchMock = 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-RT-FILTER',
plate: '粤ART808',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceCount: 2,
onlineSourceCount: 2,
online: true,
primaryProtocol: 'GB32960',
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/vehicle-service/overview')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-RT-FILTER',
plate: '粤ART808',
sourceCount: 2,
onlineSourceCount: 2,
coverageStatus: 'online',
primaryProtocol: 'GB32960',
lastSeen: '2026-07-03 20:12:10',
historyCount: 0,
rawCount: 0,
mileageCount: 0,
qualityIssueCount: 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-RT-FILTER')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-RT-FILTER&protocol=JT808');
});
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/vehicle-service/overview?keyword=VIN-RT-FILTER&protocol=JT808'), undefined);
});
test('shows canonical service status in realtime vehicles', async () => {
window.history.replaceState(null, '', '/#/realtime');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {