feat(platform): copy realtime operations summary

This commit is contained in:
lingniu
2026-07-04 13:40:48 +08:00
parent d77754b0a0
commit 1da75a5d75
2 changed files with 226 additions and 6 deletions

View File

@@ -6362,6 +6362,155 @@ test('exports current realtime vehicles as CSV', async () => {
expect(revokeObjectURL).toHaveBeenCalledWith('blob:realtime-export');
});
test('copies realtime operations summary from realtime page', async () => {
window.history.replaceState(null, '', '/#/realtime?protocol=JT808&online=online');
Object.defineProperty(window, '__LINGNIU_APP_CONFIG__', {
configurable: true,
value: { amapWebJsKey: 'amap-key' }
});
const writeText = vi.fn(() => Promise.resolve());
Object.defineProperty(navigator, 'clipboard', {
configurable: true,
value: { writeText }
});
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/realtime/vehicles')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{
vin: 'VIN-RT-SUMMARY-001',
plate: '粤A摘要1',
phone: '13300000001',
oem: 'G7s',
protocols: ['JT808'],
sourceStatus: [{ protocol: 'JT808', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }],
sourceCount: 1,
onlineSourceCount: 1,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'JT808',
longitude: 113.2,
latitude: 23.1,
speedKmh: 32,
socPercent: 76,
totalMileageKm: 1200.5,
lastSeen: '2026-07-03 20:12:10',
serviceStatus: {
status: 'healthy',
severity: 'ok',
title: '服务正常',
detail: '1/1 来源在线',
sourceCount: 1,
onlineSourceCount: 1
}
},
{
vin: 'VIN-RT-SUMMARY-002',
plate: '粤A摘要2',
phone: '13300000002',
oem: '现代',
protocols: ['GB32960', 'JT808'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03 20:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: false, lastSeen: '2026-07-03 19:58:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }
],
sourceCount: 2,
onlineSourceCount: 1,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'GB32960',
longitude: 113.4,
latitude: 23.2,
speedKmh: 18,
socPercent: 69,
totalMileageKm: 2200.5,
lastSeen: '2026-07-03 20:12:08',
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: 'JT808 离线GB32960 仍可支撑车辆服务',
sourceCount: 2,
onlineSourceCount: 1
}
},
{
vin: 'VIN-RT-SUMMARY-003',
plate: '粤A摘要3',
phone: '13300000003',
oem: '宇通',
protocols: ['YUTONG_MQTT'],
sourceStatus: [{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03 18:12:10', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true }],
sourceCount: 1,
onlineSourceCount: 0,
online: false,
bindingStatus: 'bound',
primaryProtocol: 'YUTONG_MQTT',
longitude: 0,
latitude: 0,
speedKmh: 0,
socPercent: 60,
totalMileageKm: 3200.5,
lastSeen: '2026-07-03 18:12:10',
serviceStatus: {
status: 'offline',
severity: 'error',
title: '车辆离线',
detail: 'YUTONG_MQTT 超过在线窗口',
sourceCount: 1,
onlineSourceCount: 0
}
}
],
total: 3,
limit: 50,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 50, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect((await screen.findAllByText('VIN-RT-SUMMARY-001')).length).toBeGreaterThan(0);
fireEvent.click(screen.getByRole('button', { name: '复制实时摘要' }));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('【实时监控摘要】'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('当前筛选数据来源JT808在线在线'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('车辆总数3当前页3'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('在线车辆2定位有效2'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('降级服务2来源类型3'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('地图配置:已配置'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('重点车辆:'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('粤A摘要3 / YUTONG_MQTT / 车辆离线'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('实时页面http://localhost:3000/#/realtime?protocol=JT808&online=online'));
});
test('opens vehicle service from realtime map service queue', async () => {
window.history.replaceState(null, '', '/#/realtime');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {