summaryrefslogtreecommitdiff
path: root/spec/frontend/lib/utils/datetime_utility_spec.js
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-04-20 23:50:22 +0000
commit9dc93a4519d9d5d7be48ff274127136236a3adb3 (patch)
tree70467ae3692a0e35e5ea56bcb803eb512a10bedb /spec/frontend/lib/utils/datetime_utility_spec.js
parent4b0f34b6d759d6299322b3a54453e930c6121ff0 (diff)
downloadgitlab-ce-9dc93a4519d9d5d7be48ff274127136236a3adb3.tar.gz
Add latest changes from gitlab-org/gitlab@13-11-stable-eev13.11.0-rc43
Diffstat (limited to 'spec/frontend/lib/utils/datetime_utility_spec.js')
-rw-r--r--spec/frontend/lib/utils/datetime_utility_spec.js80
1 files changed, 24 insertions, 56 deletions
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`