aboutsummaryrefslogtreecommitdiffstats
path: root/packages/instant/test/util/time.test.ts
blob: 7165761deb5063ad28117d8797e82fc671a170fc (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { timeUtil } from '../../src/util/time';

describe('assetDataUtil', () => {
    describe('secondsToHumanDescription', () => {
        const numsToResults: {
            [aNumber: number]: string;
        } = {
            1: '1 second',
            59: '59 seconds',
            60: '1 minute',
            119: '1 minute 59 seconds',
            120: '2 minutes',
            121: '2 minutes 1 second',
            122: '2 minutes 2 seconds',
        };

        const nums = Object.keys(numsToResults);
        nums.forEach(aNum => {
            const numInt = parseInt(aNum, 10);
            it(`should work for ${aNum} seconds`, () => {
                const expectedResult = numsToResults[numInt];
                expect(timeUtil.secondsToHumanDescription(numInt)).toEqual(expectedResult);
            });
        });
    });
    describe('secondsToStopwatchTime', () => {
        const numsToResults: {
            [aNumber: number]: string;
        } = {
            1: '00:01',
            59: '00:59',
            60: '01:00',
            119: '01:59',
            120: '02:00',
            121: '02:01',
            2701: '45:01',
        };

        const nums = Object.keys(numsToResults);
        nums.forEach(aNum => {
            const numInt = parseInt(aNum, 10);
            it(`should work for ${aNum} seconds`, () => {
                const expectedResult = numsToResults[numInt];
                expect(timeUtil.secondsToStopwatchTime(numInt)).toEqual(expectedResult);
            });
        });
    });
});