From cba770fc4bd455fd3c8ddddee7db0425ff498899 Mon Sep 17 00:00:00 2001 From: PolariTOON <36267812+PolariTOON@users.noreply.github.com> Date: Thu, 8 Dec 2022 15:06:43 +0100 Subject: [PATCH] test: Add tests for `formatLocallyDistanceToNow*` helpers --- react/I18n/format.spec.jsx | 48 +++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) diff --git a/react/I18n/format.spec.jsx b/react/I18n/format.spec.jsx index 311e1c7693..6f8296a9ad 100644 --- a/react/I18n/format.spec.jsx +++ b/react/I18n/format.spec.jsx @@ -1,4 +1,8 @@ -import { initFormat, formatLocallyDistanceToNow } from './format' +import { + initFormat, + formatLocallyDistanceToNow, + formatLocallyDistanceToNowStrict +} from './format' describe('initFormat', () => { beforeEach(() => { @@ -36,4 +40,46 @@ describe('formatLocallyDistanceToNow', () => { expect(result).toEqual('about 2 hours') }) + + it('should formatDistanceToNow with very high value', () => { + const date = Date.now() + 42 * 24 * 60 * 60 * 1000 + + const result = formatLocallyDistanceToNow(date) + + expect(result).toEqual('about 1 month') + }) +}) + +describe('formatLocallyDistanceToNowStrict', () => { + it('should formatDistanceToNowStrict with small value', () => { + const date = Date.now() + 29 * 1000 + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('29 seconds') + }) + + it('should formatDistanceToNowStrict with medium value', () => { + const date = Date.now() + 2671 * 1000 + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('45 minutes') + }) + + it('should formatDistanceToNowStrict with high value', () => { + const date = Date.now() + 5371 * 1000 + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('1 hour') + }) + + it('should formatDistanceToNowStrict with very high value', () => { + const date = Date.now() + 42 * 24 * 60 * 60 * 1000 + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('1 month') + }) })