feat(platform): add realtime map service queue

This commit is contained in:
lingniu
2026-07-04 11:27:22 +08:00
parent 02011035ae
commit e057dc151f
4 changed files with 182 additions and 9 deletions

View File

@@ -4287,7 +4287,7 @@ test('opens vehicle service from realtime vehicles with primary source evidence'
render(<App />);
expect(await screen.findByText('VIN-MQTT-001')).toBeInTheDocument();
expect((await screen.findAllByText('VIN-MQTT-001')).length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
@@ -4370,7 +4370,7 @@ test('opens vehicle service from realtime vehicles with current source filter',
render(<App />);
expect(await screen.findByText('VIN-RT-FILTER')).toBeInTheDocument();
expect((await screen.findAllByText('VIN-RT-FILTER')).length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '车辆服务' }));
await waitFor(() => {
@@ -4435,8 +4435,8 @@ test('shows canonical service status in realtime vehicles', async () => {
render(<App />);
expect(await screen.findByText('VIN-RT-DEGRADED')).toBeInTheDocument();
expect(screen.getByText('来源不完整')).toBeInTheDocument();
expect((await screen.findAllByText('VIN-RT-DEGRADED')).length).toBeGreaterThan(0);
expect(screen.getAllByText('来源不完整').length).toBeGreaterThan(0);
});
test('frames realtime page as one vehicle service with source evidence', async () => {
@@ -4508,7 +4508,99 @@ test('frames realtime page as one vehicle service with source evidence', async (
expect(screen.getByText('GB32960 在线')).toBeInTheDocument();
expect(screen.getByText('JT808 在线')).toBeInTheDocument();
expect(screen.getByText('YUTONG_MQTT 未接入')).toBeInTheDocument();
expect(screen.getByText('2/2 来源在线')).toBeInTheDocument();
expect(screen.getAllByText('2/2 来源在线').length).toBeGreaterThan(0);
});
test('opens vehicle service from realtime map service queue', 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-MAP-001',
plate: '粤AMAP01',
phone: '',
oem: 'G7s',
protocols: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false },
{ protocol: 'JT808', online: false, lastSeen: '2026-07-03 19:12:10', hasRealtime: true, hasHistory: false, hasRaw: false, hasMileage: false }
],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 30,
socPercent: 78,
totalMileageKm: 119925,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'JT808 离线GB32960 仍可支撑车辆服务',
sourceCount: 2,
onlineSourceCount: 1
}
}],
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-MAP-001',
plate: '粤AMAP01',
sourceCount: 2,
onlineSourceCount: 1,
coverageStatus: 'degraded',
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('地图车辆服务队列')).toBeInTheDocument();
expect(screen.getAllByText('粤AMAP01').length).toBeGreaterThan(0);
expect(screen.getByText('JT808 离线GB32960 仍可支撑车辆服务')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '地图车辆服务' }));
await waitFor(() => {
expect(window.location.hash).toBe('#/detail?keyword=VIN-MAP-001&protocol=GB32960');
});
});
test('loads realtime vehicles from shareable source filter hash', async () => {
@@ -4559,7 +4651,7 @@ test('loads realtime vehicles from shareable source filter hash', async () => {
render(<App />);
expect(await screen.findByText('VIN-RT-FILTERED')).toBeInTheDocument();
expect((await screen.findAllByText('VIN-RT-FILTERED')).length).toBeGreaterThan(0);
expect(fetchMock).toHaveBeenCalledWith(expect.stringContaining('/api/realtime/vehicles?limit=50&offset=0&keyword=%E7%B2%A4ART002&protocol=JT808&online=online&serviceStatus=degraded'), undefined);
});