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