feat(platform-web): resolve vehicle context from detail hash

This commit is contained in:
lingniu
2026-07-04 02:39:31 +08:00
parent 80bd726455
commit d67540c457
2 changed files with 97 additions and 6 deletions

View File

@@ -393,6 +393,77 @@ test('opens vehicle detail from shareable hash', async () => {
expect(screen.getAllByText('车辆服务').length).toBeGreaterThanOrEqual(1);
});
test('shows vehicle context when opening detail from shareable hash', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicles/resolve')) {
return {
ok: true,
json: async () => ({
data: {
lookupKey: 'VIN001',
resolved: true,
vin: 'VIN001',
plate: '粤AG18312',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
online: true,
lastSeen: '2026-07-03 20:12:10',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '部分来源离线',
detail: '1/2 个来源在线',
sourceCount: 2,
onlineSourceCount: 1
}
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN001',
lookupKey: 'VIN001',
lookupResolved: true,
sources: ['GB32960', 'JT808'],
sourceStatus: [],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 0, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 0, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('粤AG18312 / VIN001')).toBeInTheDocument();
expect(screen.getByText('当前车辆:部分来源离线')).toBeInTheDocument();
});
test('applies protocol from shareable history hash to API requests', async () => {
window.history.replaceState(null, '', '/#/history?keyword=%E7%B2%A4AG18312&protocol=JT808');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input, init) => {