feat(platform): recommend vehicle detail actions

This commit is contained in:
lingniu
2026-07-04 09:24:46 +08:00
parent 5952bb1a6f
commit 16dd9feb1c
3 changed files with 198 additions and 0 deletions

View File

@@ -5223,3 +5223,105 @@ test('shows cross-source consistency for one vehicle service', async () => {
fireEvent.click(screen.getByRole('button', { name: '查看缺 YUTONG_MQTT 车辆' }));
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=YUTONG_MQTT');
});
test('shows actionable vehicle service recommendations on detail', async () => {
window.history.replaceState(null, '', '/#/detail?keyword=VIN-ACTION-001');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/vehicle-service')) {
return {
ok: true,
json: async () => ({
data: {
vin: 'VIN-ACTION-001',
lookupKey: 'VIN-ACTION-001',
lookupResolved: true,
resolution: {
lookupKey: 'VIN-ACTION-001',
resolved: true,
vin: 'VIN-ACTION-001',
plate: '粤A处置1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
online: true,
lastSeen: '2026-07-03T20:12:10+08:00'
},
realtimeSummary: {
vin: 'VIN-ACTION-001',
plate: '粤A处置1',
phone: '13307795425',
oem: 'G7s',
protocols: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceCount: 3,
onlineSourceCount: 2,
online: true,
bindingStatus: 'bound',
primaryProtocol: 'GB32960',
longitude: 113.2,
latitude: 23.1,
speedKmh: 32,
socPercent: 78,
totalMileageKm: 1000.5,
lastSeen: '2026-07-03T20:12:10+08:00'
},
serviceStatus: {
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。',
sourceCount: 3,
onlineSourceCount: 2
},
sourceConsistency: {
sourceCount: 3,
onlineSourceCount: 2,
locatedSourceCount: 2,
missingProtocols: ['YUTONG_MQTT'],
mileageDeltaKm: 0.4,
sourceTimeDeltaSeconds: 35,
scope: 'all_sources',
status: 'degraded',
severity: 'warning',
title: '来源不完整',
detail: '2/3 个来源在线,车辆服务可用但缺少 YUTONG_MQTT 来源。'
},
sources: ['GB32960', 'JT808', 'YUTONG_MQTT'],
sourceStatus: [
{ protocol: 'GB32960', online: true, lastSeen: '2026-07-03T20:12:10+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'JT808', online: true, lastSeen: '2026-07-03T20:12:05+08:00', hasRealtime: true, hasHistory: true, hasRaw: true, hasMileage: true },
{ protocol: 'YUTONG_MQTT', online: false, lastSeen: '2026-07-03T20:11:40+08:00', hasRealtime: true, hasHistory: false, hasRaw: true, hasMileage: false }
],
realtime: [],
history: { items: [], total: 0, limit: 20, offset: 0 },
raw: { items: [], total: 2, limit: 10, offset: 0 },
mileage: { items: [], total: 0, limit: 20, offset: 0 },
quality: { items: [], total: 3, limit: 20, offset: 0 }
},
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
return {
ok: true,
json: async () => ({
data: path.includes('/api/ops/health')
? { linkHealth: [], kafkaLag: 0, redisOnlineKeys: 0, tdengineWritable: true, mysqlWritable: true, runtime: { requestTimeoutMs: 5000 } }
: { items: [], total: 0, limit: 10, offset: 0 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
});
render(<App />);
expect(await screen.findByText('服务处置建议')).toBeInTheDocument();
expect(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '处理质量问题 3 项' })).toBeInTheDocument();
expect(screen.getByRole('button', { name: '排查 YUTONG_MQTT 离线' })).toBeInTheDocument();
fireEvent.click(screen.getByRole('button', { name: '补齐 YUTONG_MQTT 来源' }));
expect(window.location.hash).toBe('#/vehicles?serviceStatus=degraded&missingProtocol=YUTONG_MQTT');
});