]>
Commit | Line | Data |
---|---|---|
1 | import { readableTime } from './readable_time'; | |
2 | ||
3 | describe('readableTime', () => { | |
4 | ||
5 | test('it shows negative time as 0', () => { | |
6 | ||
7 | const response = readableTime(-1000); | |
8 | ||
9 | expect(response.count).toBe(0); | |
10 | expect(response.label).toContain('seconds'); | |
11 | }); | |
12 | ||
13 | test('uses seconds as the smallest unit', () => { | |
14 | ||
15 | const response = readableTime(10); | |
16 | ||
17 | expect(response.count).toBe(0); | |
18 | expect(response.label).toContain('seconds'); | |
19 | }); | |
20 | ||
21 | test('correctly divides miliseconds into seconds', () => { | |
22 | ||
23 | const response = readableTime(4000); | |
24 | ||
25 | expect(response.count).toBe(4); | |
26 | }); | |
27 | ||
28 | test('uses seconds if the time is < 1 minute', () => { | |
29 | ||
30 | const response = readableTime(59 * 1000); | |
31 | ||
32 | expect(response.label).toContain('seconds'); | |
33 | }); | |
34 | ||
35 | test('correctly divides miliseconds into minutes', () => { | |
36 | ||
37 | const response = readableTime(2 * 60 * 1000); | |
38 | ||
39 | expect(response.count).toBe(2); | |
40 | }); | |
41 | ||
42 | test('uses minutes if the time is < 1 hour', () => { | |
43 | ||
44 | const response = readableTime(59 * 60 * 1000); | |
45 | ||
46 | expect(response.label).toContain('minutes'); | |
47 | }); | |
48 | ||
49 | test('correctly divides miliseconds into hours', () => { | |
50 | ||
51 | const response = readableTime(2 * 60 * 60 * 1000); | |
52 | ||
53 | expect(response.count).toBe(2); | |
54 | }); | |
55 | ||
56 | test('uses hours if the time is < 1 days', () => { | |
57 | ||
58 | const response = readableTime(23 * 60 * 60 * 1000); | |
59 | ||
60 | expect(response.label).toContain('hours'); | |
61 | }); | |
62 | ||
63 | test('correctly divides miliseconds into days', () => { | |
64 | ||
65 | const response = readableTime(2 * 24 * 60 * 60 * 1000); | |
66 | ||
67 | expect(response.count).toBe(2); | |
68 | }); | |
69 | ||
70 | test('uses days if the time is >= 1 day', () => { | |
71 | ||
72 | const response = readableTime(364 * 24 * 60 * 60 * 1000); | |
73 | ||
74 | expect(response.label).toContain('days'); | |
75 | }); | |
76 | ||
77 | test('uses days as the maximum unit', () => { | |
78 | ||
79 | const response = readableTime(Number.MAX_VALUE); | |
80 | ||
81 | expect(response.label).toContain('days'); | |
82 | }); | |
83 | }); |