feat(platform): copy vehicle governance summary
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user