1 import { readableTime } from './readable_time';
3 describe('readableTime', () => {
4 test('it shows negative time as 0', () => {
5 const response = readableTime(-1000);
7 expect(response.count).toBe(0);
8 expect(response.label).toContain('seconds');
11 test('uses seconds as the smallest unit', () => {
12 const response = readableTime(10);
14 expect(response.count).toBe(0);
15 expect(response.label).toContain('seconds');
18 test('correctly divides miliseconds into seconds', () => {
19 const response = readableTime(4000);
21 expect(response.count).toBe(4);
24 test('uses seconds if the time is < 1 minute', () => {
25 const response = readableTime(59 * 1000);
27 expect(response.label).toContain('seconds');
30 test('correctly divides miliseconds into minutes', () => {
31 const response = readableTime(2 * 60 * 1000);
33 expect(response.count).toBe(2);
36 test('uses minutes if the time is < 1 hour', () => {
37 const response = readableTime(59 * 60 * 1000);
39 expect(response.label).toContain('minutes');
42 test('correctly divides miliseconds into hours', () => {
43 const response = readableTime(2 * 60 * 60 * 1000);
45 expect(response.count).toBe(2);
48 test('uses hours if the time is < 1 days', () => {
49 const response = readableTime(23 * 60 * 60 * 1000);
51 expect(response.label).toContain('hours');
54 test('correctly divides miliseconds into days', () => {
55 const response = readableTime(2 * 24 * 60 * 60 * 1000);
57 expect(response.count).toBe(2);
60 test('uses days if the time is >= 1 day', () => {
61 const response = readableTime(364 * 24 * 60 * 60 * 1000);
63 expect(response.label).toContain('days');
66 test('uses days as the maximum unit', () => {
67 const response = readableTime(Number.MAX_VALUE);
69 expect(response.label).toContain('days');