diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-26 12:10:05 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-26 12:10:05 +0300 |
commit | 6f22c85c38b7a896178879172f4c0f82353308f8 (patch) | |
tree | 7b03dd7282e3b05f9ee8c78c50f52bec97bfc450 /spec/frontend/lib | |
parent | 8759459c84757589002830279dfe3872ffc852bd (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/frontend/lib')
-rw-r--r-- | spec/frontend/lib/utils/datetime/timeago_utility_spec.js | 27 |
1 files changed, 25 insertions, 2 deletions
diff --git a/spec/frontend/lib/utils/datetime/timeago_utility_spec.js b/spec/frontend/lib/utils/datetime/timeago_utility_spec.js index c13d55f978e..74ce8175357 100644 --- a/spec/frontend/lib/utils/datetime/timeago_utility_spec.js +++ b/spec/frontend/lib/utils/datetime/timeago_utility_spec.js @@ -1,3 +1,4 @@ +import { DATE_ONLY_FORMAT } from '~/lib/utils/datetime/constants'; import { getTimeago, localTimeAgo, timeFor, duration } from '~/lib/utils/datetime/timeago_utility'; import { s__ } from '~/locale'; import '~/commons/bootstrap'; @@ -24,15 +25,37 @@ describe('TimeAgo utils', () => { window.gon = { time_display_relative: false }; }); - it.each([ + const defaultFormatExpectations = [ [new Date().toISOString(), 'Jul 6, 2020, 12:00 AM'], [new Date(), 'Jul 6, 2020, 12:00 AM'], [new Date().getTime(), 'Jul 6, 2020, 12:00 AM'], // Slightly different behaviour when `null` is passed :see_no_evil` [null, 'Jan 1, 1970, 12:00 AM'], - ])('formats date `%p` as `%p`', (date, result) => { + ]; + + it.each(defaultFormatExpectations)('formats date `%p` as `%p`', (date, result) => { expect(getTimeago().format(date)).toEqual(result); }); + + describe('with unknown format', () => { + it.each(defaultFormatExpectations)( + 'uses default format and formats date `%p` as `%p`', + (date, result) => { + expect(getTimeago('non_existent').format(date)).toEqual(result); + }, + ); + }); + + describe('with DATE_ONLY_FORMAT', () => { + it.each([ + [new Date().toISOString(), 'Jul 6, 2020'], + [new Date(), 'Jul 6, 2020'], + [new Date().getTime(), 'Jul 6, 2020'], + [null, 'Jan 1, 1970'], + ])('formats date `%p` as `%p`', (date, result) => { + expect(getTimeago(DATE_ONLY_FORMAT).format(date)).toEqual(result); + }); + }); }); }); |