fix(mileage): skip missing daily mileage in interval totals
ci/woodpecker/push/woodpecker Pipeline was successful
ci/woodpecker/push/woodpecker Pipeline was successful
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import { monitoringMileageValue, recentMileageStats } from './mileage-display';
|
||||
import type { VehicleRecentDay } from './api';
|
||||
import type { MonitoringVehicle } from './types';
|
||||
|
||||
const day = (dailyKm: number, isDataSynced = true): VehicleRecentDay => ({
|
||||
date: '2026-10-12', dailyKm, isDataSynced, sourceProtocol: null, sourceCategory: null,
|
||||
});
|
||||
|
||||
test('详情合计、平均值和有数据天排除缺失日,保留真实零里程', () => {
|
||||
assert.deepEqual(recentMileageStats([day(100), day(900, false), day(200), day(0)]), {
|
||||
totalKm: 300, synced: 3, avg: 100, max: 200, totalDays: 4,
|
||||
});
|
||||
assert.equal(recentMileageStats([day(0, false)]).synced, 0);
|
||||
});
|
||||
|
||||
test('列表全区间缺失时显示横杠,即使存在累计里程', () => {
|
||||
const vehicle = { dailyKm: 0, isDataSynced: false, totalKm: 64413.6 } as MonitoringVehicle;
|
||||
assert.equal(monitoringMileageValue(vehicle), '—');
|
||||
assert.equal(monitoringMileageValue({ ...vehicle, isDataSynced: true }), 0);
|
||||
assert.equal(monitoringMileageValue({ ...vehicle, isDataSynced: true, dailyKm: 5417 }), 5417);
|
||||
});
|
||||
Reference in New Issue
Block a user