-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
133 lines (100 loc) · 3 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
import test from 'ava';
import epochAgo from './es/index';
// Irregular cases
test('future date', t => {
const actual = epochAgo(Date.now() + 60000);
const expected = 'just now';
t.is(actual, expected,
'should return just now');
});
test('date in string format', t => {
const actual = epochAgo(String(Date.now() - 6.048e+8 * 2));
const expected = '2 weeks ago';
t.is(actual, expected,
'should return expected output');
});
// Regular cases
test('right now', t => {
const actual = epochAgo(Date.now());
const expected = 'just now';
t.is(actual, expected,
'should return just now');
});
test('just under under one minute', t => {
const actual = epochAgo(Date.now() - 59999);
const expected = 'just now';
t.is(actual, expected,
'should return just now');
});
test('exactly one minute', t => {
const actual = epochAgo(Date.now() - 60000);
const expected = 'a minute ago';
t.is(actual, expected,
'should return once minutes');
});
test('exactly two minutes', t => {
const actual = epochAgo(Date.now() - 60000 * 2);
const expected = '2 minutes ago';
t.is(actual, expected,
'should return other minutes');
});
test('should return hours one', t => {
const actual = epochAgo(Date.now() - 3.6e+6);
const expected = 'an hour ago';
t.is(actual, expected,
'should return once hours');
});
test('should return hours other', t => {
const actual = epochAgo(Date.now() - 3.6e+6 * 2);
const expected = '2 hours ago';
t.is(actual, expected,
'should return other hours');
});
test('should return days one', t => {
const actual = epochAgo(Date.now() - 8.64e+7);
const expected = '1 day ago';
t.is(actual, expected,
'should return once days');
});
test('should return days other', t => {
const actual = epochAgo(Date.now() - 8.64e+7 * 2);
const expected = '2 days ago';
t.is(actual, expected,
'should return other days');
});
test('should return weeks one', t => {
const actual = epochAgo(Date.now() - 6.048e+8);
const expected = '1 week ago';
t.is(actual, expected,
'should return once weeks');
});
test('should return weeks other', t => {
const actual = epochAgo(Date.now() - 6.048e+8 * 2);
const expected = '2 weeks ago';
t.is(actual, expected,
'should return other weeks');
});
test('should return months one', t => {
const actual = epochAgo(Date.now() - 2.628e+9);
const expected = '1 month ago';
t.is(actual, expected,
'should return once months');
});
test('should return months other', t => {
const actual = epochAgo(Date.now() - 2.628e+9 * 2);
const expected = '2 months ago';
t.is(actual, expected,
'should return other months');
});
test('should return years one', t => {
const actual = epochAgo(Date.now() - 3.154e+10);
const expected = '1 year ago';
t.is(actual, expected,
'should return once years');
});
test('should return years other', t => {
const actual = epochAgo(Date.now() - 3.154e+10 * 2);
const expected = '2 years ago';
t.is(actual, expected,
'should return other years');
});