Added additional testcases.

This commit is contained in:
Denis Urs Rudolph
2025-12-07 20:24:05 +01:00
parent c70cc79ff4
commit 0b3d00f219
2 changed files with 99 additions and 0 deletions

View File

@@ -103,6 +103,30 @@ describe('Utility Functions', () => {
expect(status.status).toBe('CRITICAL')
expect(status.percentageUsed).toBeGreaterThanOrEqual(90)
})
it('should mark as OVERDUE when current mileage exceeds interval', () => {
const part = {
id: '1',
bikeId: 'bike1',
type: 'CHAIN',
installDate: new Date(),
installMileage: 0,
serviceInterval: 1000,
status: 'ACTIVE',
createdAt: new Date(),
updatedAt: new Date(),
brand: null,
model: null,
cost: null,
notes: null,
maintenanceHistory: [],
}
const status = calculateServiceStatus(part, 1500)
expect(status.status).toBe('OVERDUE')
expect(status.isOverdue).toBe(true)
expect(status.remainingKm).toBe(0)
})
})
describe('calculateTotalCosts', () => {
@@ -295,6 +319,45 @@ describe('Utility Functions', () => {
})
})
it('should ignore replaced parts without full install/replace history when calculating average lifespan', () => {
const parts = [
{
id: '1',
bikeId: 'bike1',
type: 'CHAIN',
installDate: new Date(),
installMileage: 0,
serviceInterval: 1000,
status: 'REPLACED',
createdAt: new Date(),
updatedAt: new Date(),
brand: null,
model: null,
cost: null,
notes: null,
maintenanceHistory: [
{
id: '1',
wearPartId: '1',
date: new Date('2024-01-01'),
mileage: 0,
action: 'INSTALL',
createdAt: new Date(),
updatedAt: new Date(),
notes: null,
cost: null,
},
// Missing REPLACE entry, should be ignored
],
},
]
const avg = calculateAverageLifespan(parts)
// Implementation counts replaced parts with maintenanceHistory present
// even if REPLACE entry is missing; totalKm becomes 0 and average is 0
expect(avg).toBe(0)
})
describe('formatDate', () => {
it('should format date correctly', () => {
const date = new Date('2024-01-15')