feat(platform): add vehicle command center

This commit is contained in:
lingniu
2026-07-04 11:15:56 +08:00
parent 688cf0a155
commit e94d0e348f
3 changed files with 228 additions and 4 deletions

View File

@@ -211,6 +211,146 @@ test('dashboard presents one vehicle service operating posture', async () => {
expect(screen.getByText('7 质量关注')).toBeInTheDocument();
});
test('dashboard exposes vehicle command center map actions', async () => {
window.history.replaceState(null, '', '/#/dashboard');
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, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/dashboard/summary')) {
return {
ok: true,
json: async () => ({
data: {
onlineVehicles: 3,
activeToday: 4,
frameToday: 1286320,
issueVehicles: 7,
kafkaLag: 0,
protocols: [],
serviceStatuses: [],
linkHealth: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicle-service/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 1033,
boundVehicles: 1024,
onlineVehicles: 208,
singleSourceVehicles: 391,
multiSourceVehicles: 181,
noDataVehicles: 461,
identityRequiredVehicles: 9,
serviceStatuses: [],
protocols: [],
missingSources: []
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{
vin: 'VIN-COMMAND-001',
plate: '粤A指挥1',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
primaryProtocol: 'GB32960',
sourceCount: 3,
onlineSourceCount: 2,
online: true,
longitude: 113.2,
latitude: 23.1,
speedKmh: 31,
socPercent: 78,
totalMileageKm: 100.5,
lastSeen: '2026-07-03 20:12:10'
},
{
vin: 'VIN-COMMAND-002',
plate: '粤A指挥2',
protocols: ['JT808'],
primaryProtocol: 'JT808',
sourceCount: 3,
onlineSourceCount: 0,
online: false,
longitude: 0,
latitude: 0,
lastSeen: '2026-07-03 19:55:10'
}
],
total: 2,
limit: 8,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/quality/issues')) {
return {
ok: true,
json: async () => ({
data: {
items: [{ vin: 'VIN-COMMAND-002', plate: '粤A指挥2', protocol: 'VEHICLE_SERVICE', issueType: 'NO_SOURCE', severity: 'error', detail: '无来源', lastSeen: '2026-07-03 19:55:10' }],
total: 1,
limit: 5,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 8, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('车辆态势指挥台')).toBeInTheDocument();
expect(screen.getByText('在线 1 / 2')).toBeInTheDocument();
expect(screen.getByText('有效定位 1')).toBeInTheDocument();
expect(screen.getByText('降级/离线 2')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '处理高优先级告警' }));
expect(window.location.hash).toBe('#/quality?issueType=NO_SOURCE');
cleanup();
window.history.replaceState(null, '', '/#/dashboard');
render(<App />);
expect(await screen.findByText('车辆态势指挥台')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '查看实时态势' }));
expect(window.location.hash).toBe('#/realtime?online=online');
});
test('dashboard shows vehicle service action queue', async () => {
window.history.replaceState(null, '', '/#/dashboard');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {