-
Notifications
You must be signed in to change notification settings - Fork 3k
/
interface.spec.js
81 lines (71 loc) Β· 2.55 KB
/
interface.spec.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
import {parseDate, xdateToData, toMarkingFormat} from './interface';
import XDate from 'xdate';
describe('interface', () => {
describe('parseDate()', () => {
it('should return undefined if date is undefined', () => {
const date = parseDate();
expect(date).toBe(undefined);
});
it('should return undefined if date is null', () => {
const date = parseDate(null);
expect(date).toBe(undefined);
});
it('should accept UTC timestamp as argument', () => {
const date = parseDate(1479832134398);
expect(date.getTime()).toEqual(1479832134398);
expect(date.getTimezoneOffset()).toEqual(0);
});
it('should accept dateString as argument', () => {
const date = parseDate('2012-03-16');
expect(date.toString('yyyy-MM-dd')).toEqual('2012-03-16');
expect(date.getTimezoneOffset()).toEqual(0);
});
it('should expect object with UTC timestamp as argument', () => {
const date = parseDate({timestamp: 1479832134398});
expect(date.getTime()).toEqual(1479832134398);
expect(date.getTimezoneOffset()).toEqual(0);
});
it('should accept XDate as argument', () => {
const testDate = XDate('2016-11-22 00:00:00+3');
expect(testDate.toISOString()).toEqual('2016-11-21T21:00:00Z');
const time = 1479772800000;
expect(XDate(time, true).toISOString()).toEqual('2016-11-22T00:00:00Z');
});
it('should accept Date as argument', () => {
const testDate = new Date(2015, 5, 5, 12, 0);
const date = parseDate(testDate);
expect(date.toString('yyyy-MM-dd')).toEqual('2015-06-05');
});
it('should accept data as argument', () => {
const testDate = {
year: 2015,
month: 5,
day: 6
};
const date = parseDate(testDate);
expect(date.toString('yyyy-MM-dd')).toEqual('2015-05-06');
});
});
describe('xdateToData()', () => {
it('should convert xdate to data', () => {
const time = 1479772800000;
const testDate = XDate(time, true);
expect(testDate.toISOString()).toEqual('2016-11-22T00:00:00Z');
const data = xdateToData(testDate);
expect(data).toEqual({
year: 2016,
month: 11,
day: 22,
timestamp: 1479772800000,
dateString: '2016-11-22'
});
});
});
describe('toMarkingFormat()', () => {
it('should convert date to yyyy-MM-dd format string', () => {
const time = 1479772800000;
const testDate = XDate(time);
expect(toMarkingFormat(testDate)).toEqual(testDate.toString('yyyy-MM-dd'));
});
});
});