From 7d29bfb3f00ac20364741af404d5601851b558b3 Mon Sep 17 00:00:00 2001 From: Manuel Rauber Date: Sun, 16 Jul 2023 11:45:04 +0200 Subject: [PATCH] test: time.utils --- src/app/services/time.utils.spec.ts | 71 ++++++++++++++++++++++------- 1 file changed, 54 insertions(+), 17 deletions(-) diff --git a/src/app/services/time.utils.spec.ts b/src/app/services/time.utils.spec.ts index fc01338..03fdf62 100644 --- a/src/app/services/time.utils.spec.ts +++ b/src/app/services/time.utils.spec.ts @@ -87,31 +87,68 @@ describe('Time Utils', () => { describe('calculateTimeEntryGroupDuration', () => { it('calculates correct duration with 1 item', () => { - const result = calculateTimeEntryGroupDuration([ - { - duration: Duration.fromObject({ minutes: 40 }), - } as TimeEntryGroup, - ]); + const result = calculateTimeEntryGroupDuration( + [ + { + duration: Duration.fromObject({ minutes: 40 }), + } as TimeEntryGroup, + ], + Duration.fromMillis(0), + ); expect(result.minutes).toEqual(40); }); - it('calculates correct duration with 3 item', () => { - const result = calculateTimeEntryGroupDuration([ - { - duration: Duration.fromObject({ hours: 1, minutes: 40 }), - } as TimeEntryGroup, - { - duration: Duration.fromObject({ hours: 3, minutes: 40 }), - } as TimeEntryGroup, - { - duration: Duration.fromObject({ minutes: 40 }), - } as TimeEntryGroup, - ]); + it('calculates correct duration with 3 items', () => { + const result = calculateTimeEntryGroupDuration( + [ + { + duration: Duration.fromObject({ hours: 1, minutes: 40 }), + } as TimeEntryGroup, + { + duration: Duration.fromObject({ hours: 3, minutes: 40 }), + } as TimeEntryGroup, + { + duration: Duration.fromObject({ minutes: 40 }), + } as TimeEntryGroup, + ], + Duration.fromMillis(0), + ); expect(result.minutes).toEqual(40 * 3); expect(result.hours).toEqual(4); }); + + it('calculates correct duration with a day off and no other days', () => { + const result = calculateTimeEntryGroupDuration( + [ + { + isADayOff: true, + } as TimeEntryGroup, + ], + Duration.fromObject({ hours: 7, minutes: 30 }), + ); + + expect(result.minutes).toEqual(-30); + expect(result.hours).toEqual(-7); + }); + + it('calculates correct duration with a day off and a normal working day', () => { + const result = calculateTimeEntryGroupDuration( + [ + { + isADayOff: true, + } as TimeEntryGroup, + { + duration: Duration.fromObject({ hours: 7, minutes: 30 }), + } as TimeEntryGroup, + ], + Duration.fromObject({ hours: 7, minutes: 30 }), + ); + + expect(result.minutes).toEqual(0); + expect(result.hours).toEqual(0); + }); }); describe('calculateRemainingAndOvertime', () => {