]>
git.r.bdr.sh - rbdr/forum/blob - src/utils/readable_time.test.js
5d8ba271e9daa03e2e1db6339b05350d4116b38e
1 import { readableTime
} from './readable_time';
3 describe('readableTime', () => {
5 test('it shows negative time as 0', () => {
7 const response
= readableTime(-1000);
9 expect(response
.count
).toBe(0);
10 expect(response
.label
).toContain('seconds');
13 test('uses seconds as the smallest unit', () => {
15 const response
= readableTime(10);
17 expect(response
.count
).toBe(0);
18 expect(response
.label
).toContain('seconds');
21 test('correctly divides miliseconds into seconds', () => {
23 const response
= readableTime(4000);
25 expect(response
.count
).toBe(4);
28 test('uses seconds if the time is < 1 minute', () => {
30 const response
= readableTime(59 * 1000);
32 expect(response
.label
).toContain('seconds');
35 test('correctly divides miliseconds into minutes', () => {
37 const response
= readableTime(2 * 60 * 1000);
39 expect(response
.count
).toBe(2);
42 test('uses minutes if the time is < 1 hour', () => {
44 const response
= readableTime(59 * 60 * 1000);
46 expect(response
.label
).toContain('minutes');
49 test('correctly divides miliseconds into hours', () => {
51 const response
= readableTime(2 * 60 * 60 * 1000);
53 expect(response
.count
).toBe(2);
56 test('uses hours if the time is < 1 days', () => {
58 const response
= readableTime(23 * 60 * 60 * 1000);
60 expect(response
.label
).toContain('hours');
63 test('correctly divides miliseconds into days', () => {
65 const response
= readableTime(2 * 24 * 60 * 60 * 1000);
67 expect(response
.count
).toBe(2);
70 test('uses days if the time is >= 1 day', () => {
72 const response
= readableTime(364 * 24 * 60 * 60 * 1000);
74 expect(response
.label
).toContain('days');
77 test('uses days as the maximum unit', () => {
79 const response
= readableTime(Number
.MAX_VALUE
);
81 expect(response
.label
).toContain('days');