feat(platform): copy vehicle governance summary

This commit is contained in:
lingniu
2026-07-04 13:23:56 +08:00
parent 9d35f65be6
commit 817590c104
2 changed files with 176 additions and 18 deletions

View File

@@ -972,6 +972,102 @@ test('exports current vehicle coverage page as csv', async () => {
expect(revokeObjectURL).toHaveBeenCalledWith('blob:vehicle-coverage');
});
test('copies vehicle governance summary from vehicle center', async () => {
window.history.replaceState(null, '', '/#/vehicles?missingProtocol=YUTONG_MQTT');
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, activeConnections: 0, capacityFindings: [], redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage/summary')) {
return {
ok: true,
json: async () => ({
data: {
totalVehicles: 12,
onlineVehicles: 5,
singleSourceVehicles: 7,
multiSourceVehicles: 2,
noDataVehicles: 3,
unboundVehicles: 4,
archiveIncompleteVehicles: 6,
archiveMissingFields: [{ field: 'phone', title: '缺手机号', count: 3 }],
missingSources: [{ protocol: 'YUTONG_MQTT', count: 8 }]
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/vehicles/coverage')) {
return {
ok: true,
json: async () => ({
data: {
items: [{
vin: 'VIN-GOV-001',
plate: '粤A治理1',
phone: '',
oem: 'G7s',
protocols: ['JT808'],
missingProtocols: ['YUTONG_MQTT'],
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,
lastSeen: '2026-07-03 20:12:10',
bindingStatus: 'bound',
serviceStatus: { status: 'degraded', severity: 'warning', title: '来源不完整', detail: '缺少 YUTONG_MQTT', sourceCount: 1, onlineSourceCount: 1 },
sourceConsistency: { sourceCount: 1, onlineSourceCount: 1, locatedSourceCount: 1, missingProtocols: ['YUTONG_MQTT'], mileageDeltaKm: 0, sourceTimeDeltaSeconds: 0, scope: 'overview', status: 'degraded', severity: 'warning', title: '来源不完整', detail: '缺少 YUTONG_MQTT' }
}],
total: 12,
limit: 20,
offset: 0
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: { items: [], total: 0, limit: 20, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('VIN-GOV-001')).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '复制治理摘要' }));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('【车辆治理摘要】'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('当前筛选缺失来源YUTONG_MQTT'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('车辆总数12在线5'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('单源7多源2暂无来源3'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('待绑定4档案不完整6'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('档案缺项:缺手机号 3'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('缺失来源YUTONG_MQTT 8'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('处置队列:'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('[P0] 维护身份绑定 4'));
expect(writeText).toHaveBeenCalledWith(expect.stringContaining('[P1] 补齐 YUTONG_MQTT 来源 8'));
});
test('filters vehicle list from recommended action', async () => {
window.history.replaceState(null, '', '/#/vehicles');
const fetchMock = vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {