Skip to content

Commit db7315a

Browse files
committed
Test viewDate in separate file
I think the tests are leaking and it's causing tests to fail, in the current test file the tests has to be in a certain order - otherwise they will fail. One solution is to put them in separate files (like in this commit), but of course the optimal solution would be to fix the leakage.
1 parent 405f4e8 commit db7315a

File tree

2 files changed

+70
-49
lines changed

2 files changed

+70
-49
lines changed

test/tests.spec.js

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,53 +1175,4 @@ describe('Datetime', () => {
11751175
});
11761176

11771177
});
1178-
1179-
describe('with viewDate', () => {
1180-
it('date value', () => {
1181-
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
1182-
strDate = moment(date).format('MMMM YYYY'),
1183-
component = utils.createDatetime({ viewDate: date });
1184-
expect(utils.getViewDateValue(component)).toEqual(strDate);
1185-
});
1186-
1187-
it('moment value', () => {
1188-
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
1189-
mDate = moment(date),
1190-
strDate = mDate.format('MMMM YYYY'),
1191-
component = utils.createDatetime({ viewDate: mDate });
1192-
expect(utils.getViewDateValue(component)).toEqual(strDate);
1193-
});
1194-
1195-
it('string value', () => {
1196-
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
1197-
mDate = moment(date),
1198-
strDate = mDate.format('L') + ' ' + mDate.format('LT'),
1199-
expectedStrDate = mDate.format('MMMM YYYY'),
1200-
component = utils.createDatetime({ viewDate: strDate });
1201-
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate);
1202-
});
1203-
1204-
it('UTC value from UTC string', () => {
1205-
const date = new Date(2000, 0, 15, 2, 2, 2, 2),
1206-
momentDateUTC = moment.utc(date),
1207-
strDateUTC = momentDateUTC.format('L') + ' ' + momentDateUTC.format('LT'),
1208-
expectedStrDate = momentDateUTC.format('MMMM YYYY'),
1209-
component = utils.createDatetime({ viewDate: strDateUTC, utc: true });
1210-
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate);
1211-
});
1212-
1213-
it('invalid string value', () => {
1214-
const strDate = 'invalid string',
1215-
expectedStrDate = moment().format('MMMM YYYY'),
1216-
component = utils.createDatetime({ viewDate: strDate });
1217-
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate);
1218-
});
1219-
1220-
it('invalid moment object', () => {
1221-
const mDate = moment(null),
1222-
expectedStrDate = moment().format('MMMM YYYY'),
1223-
component = utils.createDatetime({ viewDate: mDate });
1224-
expect(utils.getViewDateValue(component)).toEqual(expectedStrDate);
1225-
});
1226-
});
12271178
});

test/viewDate.spec.js

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/* global it, describe, expect */
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+
});

0 commit comments

Comments
 (0)