|
| 1 | +import {formatDurationToShortTimeFormat} from '../formatDuration'; |
| 2 | +import i18n from '../i18n'; |
| 3 | + |
| 4 | +describe('formatDurationToShortTimeFormat', () => { |
| 5 | + // 1 - ms |
| 6 | + const timeWithMs = 123; |
| 7 | + const formattedTimeWithMs = i18n('ms', {seconds: 0, ms: 123}); |
| 8 | + |
| 9 | + // 2 - seconds and ms |
| 10 | + const timeWithSecondsAndMsInMs = 12345; |
| 11 | + const formattedTimeWithSecondsAndMs = i18n('secMs', {seconds: 12, ms: 345}); |
| 12 | + |
| 13 | + // 3 - minutes |
| 14 | + const timeWithMinutesInMs = 754567; |
| 15 | + const formattedTimeWithMinutes = i18n('minSec', {minutes: 12, seconds: 34}); |
| 16 | + |
| 17 | + // 4 - hours |
| 18 | + const timeWithHoursInMs = 9245678; |
| 19 | + const formattedTimeWithHours = i18n('hoursMin', {hours: 2, minutes: 34}); |
| 20 | + |
| 21 | + // 5 - days |
| 22 | + const timeWithDaysInMs = 439234123; |
| 23 | + const formattedTimeWithDays = i18n('daysHours', {days: 5, hours: 2}); |
| 24 | + |
| 25 | + // 6 - zero |
| 26 | + const formattedZero = i18n('ms', {seconds: 0, ms: 0}); |
| 27 | + |
| 28 | + it('should return ms on values less than second', () => { |
| 29 | + expect(formatDurationToShortTimeFormat(timeWithMs)).toEqual(formattedTimeWithMs); |
| 30 | + }); |
| 31 | + it('should return seconds and ms', () => { |
| 32 | + expect(formatDurationToShortTimeFormat(timeWithSecondsAndMsInMs)).toEqual( |
| 33 | + formattedTimeWithSecondsAndMs, |
| 34 | + ); |
| 35 | + }); |
| 36 | + it('should return minutes and seconds', () => { |
| 37 | + expect(formatDurationToShortTimeFormat(timeWithMinutesInMs)).toEqual( |
| 38 | + formattedTimeWithMinutes, |
| 39 | + ); |
| 40 | + }); |
| 41 | + it('should return hours and minutes', () => { |
| 42 | + expect(formatDurationToShortTimeFormat(timeWithHoursInMs)).toEqual(formattedTimeWithHours); |
| 43 | + }); |
| 44 | + it('should return days and hours', () => { |
| 45 | + expect(formatDurationToShortTimeFormat(timeWithDaysInMs)).toEqual(formattedTimeWithDays); |
| 46 | + }); |
| 47 | + it('should process zero values', () => { |
| 48 | + expect(formatDurationToShortTimeFormat(0)).toEqual(formattedZero); |
| 49 | + }); |
| 50 | +}); |
0 commit comments