commit | author | age
|
db7315
|
1 |
/* global it, describe, expect */ |
SE |
2 |
|
|
3 |
import React from 'react'; // eslint-disable-line no-unused-vars |
|
4 |
import moment from 'moment'; |
|
5 |
import utils from './testUtils'; |
|
6 |
import Enzyme from 'enzyme'; |
|
7 |
import Adapter from 'enzyme-adapter-react-15'; |
|
8 |
|
|
9 |
Enzyme.configure({adapter: new Adapter()}); |
|
10 |
|
|
11 |
describe('with viewDate', () => { |
|
12 |
it('date value', () => { |
|
13 |
const date = new Date(2000, 0, 15, 2, 2, 2, 2), |
|
14 |
strDate = moment(date).format('MMMM YYYY'), |
|
15 |
component = utils.createDatetime({viewDate: date}); |
|
16 |
expect(utils.getViewDateValue(component)).toEqual(strDate); |
|
17 |
}); |
|
18 |
|
|
19 |
it('moment value', () => { |
|
20 |
const date = new Date(2000, 0, 15, 2, 2, 2, 2), |
|
21 |
mDate = moment(date), |
|
22 |
strDate = mDate.format('MMMM YYYY'), |
|
23 |
component = utils.createDatetime({viewDate: mDate}); |
|
24 |
expect(utils.getViewDateValue(component)).toEqual(strDate); |
|
25 |
}); |
|
26 |
|
|
27 |
it('string value', () => { |
|
28 |
const date = new Date(2000, 0, 15, 2, 2, 2, 2), |
|
29 |
mDate = moment(date), |
|
30 |
strDate = mDate.format('L') + ' ' + mDate.format('LT'), |
|
31 |
expectedStrDate = mDate.format('MMMM YYYY'), |
|
32 |
component = utils.createDatetime({viewDate: strDate}); |
|
33 |
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); |
|
34 |
}); |
|
35 |
|
|
36 |
it('UTC value from UTC string', () => { |
|
37 |
const date = new Date(2000, 0, 15, 2, 2, 2, 2), |
|
38 |
momentDateUTC = moment.utc(date), |
|
39 |
strDateUTC = momentDateUTC.format('L') + ' ' + momentDateUTC.format('LT'), |
|
40 |
expectedStrDate = momentDateUTC.format('MMMM YYYY'), |
|
41 |
component = utils.createDatetime({viewDate: strDateUTC, utc: true}); |
|
42 |
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); |
|
43 |
}); |
|
44 |
|
|
45 |
it('invalid string value', () => { |
|
46 |
const strDate = 'invalid string', |
|
47 |
expectedStrDate = moment().format('MMMM YYYY'), |
|
48 |
component = utils.createDatetime({viewDate: strDate}); |
|
49 |
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); |
|
50 |
}); |
|
51 |
|
|
52 |
it('invalid moment object', () => { |
|
53 |
const mDate = moment(null), |
|
54 |
expectedStrDate = moment().format('MMMM YYYY'), |
|
55 |
component = utils.createDatetime({viewDate: mDate}); |
|
56 |
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate); |
|
57 |
}); |
|
58 |
|
|
59 |
it('viewDate -> picker should change the initial month (viewMode=months)', () => { |
|
60 |
const preDate = new Date(2000, 0, 15, 2, 2, 2, 2), |
|
61 |
strPreDate = moment(preDate).format('MMMM YYYY'), |
|
62 |
component = utils.createDatetime({viewDate: preDate}); |
|
63 |
expect(utils.getViewDateValue(component)).toEqual(strPreDate); |
|
64 |
|
|
65 |
const postDate = new Date(2010, 0, 15, 2, 2, 2, 2), |
|
66 |
strPostDate = moment(postDate).format('MMMM YYYY'); |
|
67 |
component.setProps({viewDate: postDate}); |
|
68 |
expect(utils.getViewDateValue(component)).toEqual(strPostDate); |
|
69 |
}); |
|
70 |
}); |