+import { readableTime } from './readable_time';
+
+describe('readableTime', () => {
+
+ test('it shows negative time as 0', () => {
+
+ const response = readableTime(-1000);
+
+ expect(response.count).toBe(0);
+ expect(response.label).toContain('seconds');
+ });
+
+ test('uses seconds as the smallest unit', () => {
+
+ const response = readableTime(10);
+
+ expect(response.count).toBe(0);
+ expect(response.label).toContain('seconds');
+ });
+
+ test('correctly divides miliseconds into seconds', () => {
+
+ const response = readableTime(4000);
+
+ expect(response.count).toBe(4);
+ });
+
+ test('uses seconds if the time is < 1 minute', () => {
+
+ const response = readableTime(59 * 1000);
+
+ expect(response.label).toContain('seconds');
+ });
+
+ test('correctly divides miliseconds into minutes', () => {
+
+ const response = readableTime(2 * 60 * 1000);
+
+ expect(response.count).toBe(2);
+ });
+
+ test('uses minutes if the time is < 1 hour', () => {
+
+ const response = readableTime(59 * 60 * 1000);
+
+ expect(response.label).toContain('minutes');
+ });
+
+ test('correctly divides miliseconds into hours', () => {
+
+ const response = readableTime(2 * 60 * 60 * 1000);
+
+ expect(response.count).toBe(2);
+ });
+
+ test('uses hours if the time is < 1 days', () => {
+
+ const response = readableTime(23 * 60 * 60 * 1000);
+
+ expect(response.label).toContain('hours');
+ });
+
+ test('correctly divides miliseconds into days', () => {
+
+ const response = readableTime(2 * 24 * 60 * 60 * 1000);
+
+ expect(response.count).toBe(2);
+ });
+
+ test('uses days if the time is >= 1 day', () => {
+
+ const response = readableTime(364 * 24 * 60 * 60 * 1000);
+
+ expect(response.label).toContain('days');
+ });
+
+ test('uses days as the maximum unit', () => {
+
+ const response = readableTime(Number.MAX_VALUE);
+
+ expect(response.label).toContain('days');
+ });
+});