1
|
|
|
jest.autoMockOff(); |
|
|
|
|
2
|
|
|
|
3
|
|
|
import DateHelper from "../index"; |
4
|
|
|
import MockDate from "mockdate"; |
5
|
|
|
|
6
|
|
|
MockDate.set("2016-01-01T00:00:00+00:00", 0); |
7
|
|
|
|
8
|
|
|
const equals = (actual, expected) => expect(actual).toBe(expected); |
9
|
|
|
|
10
|
|
|
test("Test leadingZero", () => { |
11
|
|
|
equals("00", DateHelper.leadingZero(0)); |
12
|
|
|
equals("00", DateHelper.leadingZero("00")); |
13
|
|
|
equals("00", DateHelper.leadingZero("000")); |
14
|
|
|
equals("01", DateHelper.leadingZero("1")); |
15
|
|
|
}); |
16
|
|
|
|
17
|
|
|
test("Test beautifySeconds", () => { |
18
|
|
|
// key is number of seconds. First position is without seconds, second is with seconds |
19
|
|
|
const hash = { |
20
|
|
|
59: ["", "59s"], |
21
|
|
|
60: ["01m", "01m00s"], |
22
|
|
|
61: ["01m", "01m01s"], |
23
|
|
|
3900: ["1h05m", "1h05m00s"] |
24
|
|
|
}; |
25
|
|
|
|
26
|
|
|
Object.keys(hash).map(function (seconds) { |
27
|
|
|
equals(hash[seconds][0], DateHelper.beautifySeconds(seconds, false)); |
28
|
|
|
equals(hash[seconds][1], DateHelper.beautifySeconds(seconds, true)); |
29
|
|
|
}); |
30
|
|
|
}); |
31
|
|
|
|
32
|
|
|
test("Test beautifyMinutes", () => { |
33
|
|
|
const hash = { |
34
|
|
|
59: ["59m", "59m00s"], |
35
|
|
|
60: ["1h00m", "1h00m00s"], |
36
|
|
|
61: ["1h01m", "1h01m00s"], |
37
|
|
|
3900: ["65h00m", "65h00m00s"], |
38
|
|
|
3905: ["65h05m", "65h05m00s"] |
39
|
|
|
}; |
40
|
|
|
|
41
|
|
|
Object.keys(hash).map(function (minutes) { |
42
|
|
|
equals(hash[minutes][0], DateHelper.beautifyMinutes(minutes, false)); |
43
|
|
|
equals(hash[minutes][1], DateHelper.beautifyMinutes(minutes, true)); |
44
|
|
|
}); |
45
|
|
|
}); |
46
|
|
|
|
47
|
|
|
test("Test fromBeutyToSeconds", () => { |
48
|
|
|
const hash = { |
49
|
|
|
"1s": 1, |
50
|
|
|
"01s": 1, |
51
|
|
|
"59s": 59, |
52
|
|
|
"60s": 60, |
53
|
|
|
"1m": 60, |
54
|
|
|
"1m01s": 61, |
55
|
|
|
"1m1s": 61, |
56
|
|
|
"01m01s": 61, |
57
|
|
|
"1h": 3600, |
58
|
|
|
"1h0m1s": 3601 |
59
|
|
|
}; |
60
|
|
|
|
61
|
|
|
Object.keys(hash).map(function (strTime) { |
62
|
|
|
equals(hash[strTime], DateHelper.fromBeutyToSeconds(strTime)); |
63
|
|
|
}); |
64
|
|
|
}); |
65
|
|
|
|
66
|
|
|
test("Test daysBetween", () => { |
67
|
|
|
const testData = [{ |
68
|
|
|
dates: ["2016-01-01", "2016-01-01"], |
69
|
|
|
expected: 0 |
70
|
|
|
}, { |
71
|
|
|
dates: ["2016-01-01", "2016-01-02"], |
72
|
|
|
expected: 1 |
73
|
|
|
}, { |
74
|
|
|
dates: ["2016-02-28", "2016-03-01"], |
75
|
|
|
expected: 2 |
76
|
|
|
}, { |
77
|
|
|
dates: ["2017-02-28", "2017-03-01"], |
78
|
|
|
expected: 1 |
79
|
|
|
}, { |
80
|
|
|
dates: ["2016-01-01", "2015-01-01"], |
81
|
|
|
expected: 365 |
82
|
|
|
}]; |
83
|
|
|
|
84
|
|
|
testData.map(function (data) { |
85
|
|
|
equals(DateHelper.daysBetween(data.dates[0], data.dates[1]), data.expected); |
86
|
|
|
}); |
87
|
|
|
}); |
88
|
|
|
|
89
|
|
|
test("Test curdate", () => { |
90
|
|
|
equals(DateHelper.curdate(), "2016-01-01"); |
91
|
|
|
}); |
92
|
|
|
|
93
|
|
|
// test("Test firstDayOfTheMonth", () => { |
94
|
|
|
// // @todo ?? |
95
|
|
|
// equals(DateHelper.firstDayOfTheMonth(), "2016-01-01"); |
96
|
|
|
// }); |
97
|
|
|
|
98
|
|
|
// test("Test lastDayOfTheMonth", () => { |
99
|
|
|
// // @todo ?? |
100
|
|
|
// // equals(DateHelper.lastDayOfTheMonth(), "2016-01-31"); |
101
|
|
|
// equals(DateHelper.lastDayOfTheMonth(2), "2016-02-29"); |
102
|
|
|
// equals(DateHelper.lastDayOfTheMonth(2, 2017), "2017-02-28"); |
103
|
|
|
// }); |
104
|
|
|
|
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.