feat(platform): add vehicle-first statistics overview

This commit is contained in:
lingniu
2026-07-04 16:44:55 +08:00
parent bdb2ebc723
commit d7f1a9279f
4 changed files with 104 additions and 2 deletions

View File

@@ -6490,7 +6490,7 @@ test('shows mileage statistics workspace with trend source and definition', asyn
expect(screen.getAllByText('JT808').length).toBeGreaterThanOrEqual(1);
expect(screen.getAllByText('GB32960').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('当前页里程')).toBeInTheDocument();
expect(screen.getByText('140 km')).toBeInTheDocument();
expect(screen.getAllByText('140 km').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('异常记录')).toBeInTheDocument();
expect(screen.getAllByText('1').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('最大单日')).toBeInTheDocument();
@@ -6508,6 +6508,61 @@ test('shows mileage statistics workspace with trend source and definition', asyn
expect(screen.getByText((content) => content.includes('区间总值应等于各日里程之和'))).toBeInTheDocument();
});
test('shows vehicle-first statistics domains for one vehicle service', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-STATS-SERVICE&protocol=JT808');
vi.spyOn(globalThis, 'fetch').mockImplementation(async (input) => {
const path = String(input);
if (path.includes('/api/mileage/summary')) {
return {
ok: true,
json: async () => ({
data: { vehicleCount: 3, recordCount: 6, sourceCount: 2, totalMileageKm: 210, averageMileagePerVin: 70 },
traceId: 'trace-test',
timestamp: 1783094400000
})
} as Response;
}
if (path.includes('/api/mileage/daily')) {
return {
ok: true,
json: async () => ({
data: {
items: [
{ vin: 'VIN-STATS-SERVICE', plate: '粤A统计服务1', source: 'JT808', date: '2026-07-01', startMileageKm: 100, endMileageKm: 150, dailyMileageKm: 50, anomalySeverity: '' },
{ vin: 'VIN-STATS-SERVICE', plate: '粤A统计服务1', source: 'GB32960', date: '2026-07-01', startMileageKm: 200, endMileageKm: 240, dailyMileageKm: 40, anomalySeverity: '' },
{ vin: 'VIN-STATS-SERVICE-2', plate: '粤A统计服务2', source: 'JT808', date: '2026-07-02', startMileageKm: 300, endMileageKm: 380, dailyMileageKm: 80, anomalySeverity: 'warning' }
],
total: 3,
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('车辆统计服务总览')).toBeInTheDocument();
expect(screen.getAllByText('里程统计').length).toBeGreaterThanOrEqual(1);
expect(screen.getByText('在线率与离线时长')).toBeInTheDocument();
expect(screen.getByText('数据完整性')).toBeInTheDocument();
expect(screen.getByText('来源一致性')).toBeInTheDocument();
expect(screen.getByText('三类数据源最终汇总为一个车辆服务统计视图')).toBeInTheDocument();
expect(screen.getByText('当前统计证据')).toBeInTheDocument();
expect(screen.getByText('3 车 / 2 来源 / 3 条明细')).toBeInTheDocument();
});
test('copies mileage statistics summary for operations reporting', async () => {
window.history.replaceState(null, '', '/#/mileage?keyword=VIN-MILEAGE-COPY&protocol=JT808&dateFrom=2026-07-01&dateTo=2026-07-03');
const writeText = vi.fn(() => Promise.resolve());