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