feat(platform-web): keep realtime source in vehicle links

This commit is contained in:
lingniu
2026-07-04 01:25:13 +08:00
parent 55834a4651
commit edca567d52
2 changed files with 77 additions and 2 deletions

View File

@@ -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(<App />);
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');
});
});