From 0490f12c65d1f43c88e83974d0792fed45ab751f Mon Sep 17 00:00:00 2001 From: PolariTOON <36267812+PolariTOON@users.noreply.github.com> Date: Wed, 21 Dec 2022 11:45:11 +0100 Subject: [PATCH] test: Add tests for `formatLocallyDistanceToNowStrict` --- react/I18n/format.spec.jsx | 40 +++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/react/I18n/format.spec.jsx b/react/I18n/format.spec.jsx index 7fed59c4ab..dae8b9f31d 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(() => { @@ -45,3 +49,37 @@ describe('formatLocallyDistanceToNow', () => { expect(result).toEqual('about 1 month') }) }) + +describe('formatLocallyDistanceToNowStrict', () => { + it('should formatDistanceToNowStrict with small value', () => { + const date = Date.now() + 29 * 1000 // 29s + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('29 seconds') + }) + + it('should formatDistanceToNowStrict with medium value', () => { + const date = Date.now() + (44 * 60 + 31) * 1000 // 44min 31s + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('44 minutes') + }) + + it('should formatDistanceToNowStrict with high value', () => { + const date = Date.now() + (89 * 60 + 31) * 1000 // 89min 31s + + 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 // 42d + + const result = formatLocallyDistanceToNowStrict(date) + + expect(result).toEqual('1 month') + }) +})