fix(platform): keep history source when opening vehicle

This commit is contained in:
lingniu
2026-07-04 06:20:29 +08:00
parent b9a173f8d2
commit 6dd00f4ebb
2 changed files with 57 additions and 3 deletions

View File

@@ -1707,6 +1707,60 @@ test('opens vehicle service from raw history rows with row source evidence', asy
});
});
test('opens current vehicle service from history header with current source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN-JT808-HEADER&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/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN-JT808-HEADER',
resolved: true,
vin: 'VIN-JT808-HEADER',
plate: '粤AG18312',
phone: '13307795425',
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: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('当前来源JT808')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '当前车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-JT808-HEADER&protocol=JT808');
});
});
test('opens unified vehicle service from realtime vehicles without primary protocol', async () => {
window.history.replaceState(null, '', '/#/realtime');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
@@ -2515,7 +2569,7 @@ test('opens source-specific raw history directly from vehicle detail source evid
});
});
test('opens unified vehicle service from an empty history query', async () => {
test('opens vehicle service from an empty history query with current source evidence', async () => {
window.history.replaceState(null, '', '/#/history?keyword=VIN404&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
@@ -2556,7 +2610,7 @@ test('opens unified vehicle service from an empty history query', async () => {
fireEvent.click(await screen.findByRole('button', { name: '当前车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN404');
expect(window.location.hash).toBe('#/detail?keyword=VIN404&protocol=JT808');
});
});