From 9dc93a4519d9d5d7be48ff274127136236a3adb3 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Tue, 20 Apr 2021 23:50:22 +0000 Subject: Add latest changes from gitlab-org/gitlab@13-11-stable-ee --- spec/frontend/lib/utils/datetime_utility_spec.js | 80 +++++++----------------- 1 file changed, 24 insertions(+), 56 deletions(-) (limited to 'spec/frontend/lib/utils/datetime_utility_spec.js') diff --git a/spec/frontend/lib/utils/datetime_utility_spec.js b/spec/frontend/lib/utils/datetime_utility_spec.js index 2df0cb00f9a..6180cd8e94d 100644 --- a/spec/frontend/lib/utils/datetime_utility_spec.js +++ b/spec/frontend/lib/utils/datetime_utility_spec.js @@ -178,6 +178,30 @@ describe('timeIntervalInWords', () => { }); }); +describe('humanizeTimeInterval', () => { + it.each` + intervalInSeconds | expected + ${0} | ${'0 seconds'} + ${1} | ${'1 second'} + ${1.48} | ${'1.5 seconds'} + ${2} | ${'2 seconds'} + ${60} | ${'1 minute'} + ${91} | ${'1.5 minutes'} + ${120} | ${'2 minutes'} + ${3600} | ${'1 hour'} + ${5401} | ${'1.5 hours'} + ${7200} | ${'2 hours'} + ${86400} | ${'1 day'} + ${129601} | ${'1.5 days'} + ${172800} | ${'2 days'} + `( + 'returns "$expected" when the time interval is $intervalInSeconds seconds', + ({ intervalInSeconds, expected }) => { + expect(datetimeUtility.humanizeTimeInterval(intervalInSeconds)).toBe(expected); + }, + ); +}); + describe('dateInWords', () => { const date = new Date('07/01/2016'); @@ -966,62 +990,6 @@ describe('format24HourTimeStringFromInt', () => { }); }); -describe('getOverlapDateInPeriods', () => { - const start = new Date(2021, 0, 11); - const end = new Date(2021, 0, 13); - - describe('when date periods overlap', () => { - const givenPeriodLeft = new Date(2021, 0, 11); - const givenPeriodRight = new Date(2021, 0, 14); - - it('returns an overlap object that contains the amount of days overlapping, the amount of hours overlapping, start date of overlap and end date of overlap', () => { - expect( - datetimeUtility.getOverlapDateInPeriods( - { start, end }, - { start: givenPeriodLeft, end: givenPeriodRight }, - ), - ).toEqual({ - daysOverlap: 2, - hoursOverlap: 48, - overlapStartDate: givenPeriodLeft.getTime(), - overlapEndDate: end.getTime(), - }); - }); - }); - - describe('when date periods do not overlap', () => { - const givenPeriodLeft = new Date(2021, 0, 9); - const givenPeriodRight = new Date(2021, 0, 10); - - it('returns an overlap object that contains a 0 value for days overlapping', () => { - expect( - datetimeUtility.getOverlapDateInPeriods( - { start, end }, - { start: givenPeriodLeft, end: givenPeriodRight }, - ), - ).toEqual({ daysOverlap: 0 }); - }); - }); - - describe('when date periods contain an invalid Date', () => { - const startInvalid = new Date(NaN); - const endInvalid = new Date(NaN); - const error = __('Invalid period'); - - it('throws an exception when the left period contains an invalid date', () => { - expect(() => - datetimeUtility.getOverlapDateInPeriods({ start, end }, { start: startInvalid, end }), - ).toThrow(error); - }); - - it('throws an exception when the right period contains an invalid date', () => { - expect(() => - datetimeUtility.getOverlapDateInPeriods({ start, end }, { start, end: endInvalid }), - ).toThrow(error); - }); - }); -}); - describe('isToday', () => { const today = new Date(); it.each` -- cgit v1.2.1