@docsvision/material-ui-pickers 3.2.0-beta.24 → 3.2.0-beta.26
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.size-snapshot.json +11 -11
- package/9db1cba1a61cb58db53f38425bbd1f95.7z +0 -0
- package/build/DatePicker/DatePicker.d.ts +2 -2
- package/build/DatePicker/DatePicker.js +1 -1
- package/build/DateTimePicker/DateTimePicker.js +1 -1
- package/build/Picker/Picker.js +1 -1
- package/build/TimePicker/TimePicker.js +1 -1
- package/build/_helpers/text-field-helper.d.ts +1 -1
- package/build/_shared/KeyboardDateInput.js +1 -1
- package/build/_shared/ModalDialog.d.ts +2 -2
- package/build/_shared/PureDateInput.js +1 -1
- package/build/_shared/ToolbarButton.d.ts +2 -2
- package/build/_shared/hooks/useKeyboardPickerState.js +2 -2
- package/build/constants/prop-types.js +2 -2
- package/build/dist/material-ui-pickers.esm.js +12 -12
- package/build/dist/material-ui-pickers.esm.js.map +1 -1
- package/build/dist/material-ui-pickers.js +62 -62
- package/build/dist/material-ui-pickers.js.map +1 -1
- package/build/dist/material-ui-pickers.umd.js +5790 -4511
- package/build/dist/material-ui-pickers.umd.min.js +1 -1
- package/build/package.json +1 -1
- package/build/views/Calendar/Calendar.js +2 -2
- package/build/views/Clock/Clock.d.ts +1 -1
- package/build/views/Clock/ClockPointer.d.ts +1 -1
- package/package.json +1 -1
- package/src/DatePicker/DatePicker.tsx +91 -0
- package/src/DatePicker/DatePickerToolbar.tsx +75 -0
- package/src/DatePicker/index.ts +7 -0
- package/src/DateTimePicker/DateTimePicker.tsx +72 -0
- package/src/DateTimePicker/DateTimePickerTabs.tsx +86 -0
- package/src/DateTimePicker/DateTimePickerToolbar.tsx +123 -0
- package/src/DateTimePicker/index.ts +7 -0
- package/src/MuiPickersUtilsProvider.tsx +39 -0
- package/src/Picker/Picker.tsx +275 -0
- package/src/Picker/WrappedKeyboardPicker.tsx +136 -0
- package/src/Picker/WrappedPurePicker.tsx +128 -0
- package/src/Rifm/Rifm.ts +213 -0
- package/src/TimePicker/TimePicker.tsx +67 -0
- package/src/TimePicker/TimePickerToolbar.tsx +180 -0
- package/src/TimePicker/index.tsx +7 -0
- package/src/__tests__/DatePicker/Calendar.test.tsx +51 -0
- package/src/__tests__/DatePicker/Month.test.tsx +36 -0
- package/src/__tests__/DatePicker/MonthSelection.test.tsx +37 -0
- package/src/__tests__/MuiPickersUtilsProvider.test.tsx +21 -0
- package/src/__tests__/TimePicker/Clock.test.tsx +68 -0
- package/src/__tests__/_helpers/date-utils.test.tsx +197 -0
- package/src/__tests__/_helpers/text-field-helper.test.tsx +34 -0
- package/src/__tests__/_shared/ModalDialog.test.tsx +109 -0
- package/src/__tests__/e2e/DatePicker.test.tsx +233 -0
- package/src/__tests__/e2e/DatePickerProps.test.tsx +18 -0
- package/src/__tests__/e2e/DatePickerRoot.test.tsx +154 -0
- package/src/__tests__/e2e/DateTimePicker.test.tsx +86 -0
- package/src/__tests__/e2e/DateTimePickerRoot.test.tsx +72 -0
- package/src/__tests__/e2e/KeyboardDatePicker.test.tsx +140 -0
- package/src/__tests__/e2e/KeyboardDateTimePicker.test.tsx +48 -0
- package/src/__tests__/e2e/Theme.test.tsx +30 -0
- package/src/__tests__/e2e/TimePicker.test.tsx +121 -0
- package/src/__tests__/e2e/commands.tsx +8 -0
- package/src/__tests__/setup.js +26 -0
- package/src/__tests__/test-utils.tsx +45 -0
- package/src/__tests__/tsconfig.json +5 -0
- package/src/_helpers/date-utils.ts +92 -0
- package/src/_helpers/text-field-helper.ts +239 -0
- package/src/_helpers/time-utils.ts +83 -0
- package/src/_helpers/utils.ts +8 -0
- package/src/_shared/KeyboardDateInput.tsx +161 -0
- package/src/_shared/ModalDialog.tsx +114 -0
- package/src/_shared/PickerToolbar.tsx +52 -0
- package/src/_shared/PureDateInput.tsx +45 -0
- package/src/_shared/ToolbarButton.tsx +63 -0
- package/src/_shared/ToolbarText.tsx +49 -0
- package/src/_shared/WithUtils.tsx +19 -0
- package/src/_shared/hooks/useIsLandscape.tsx +27 -0
- package/src/_shared/hooks/useKeyDown.ts +34 -0
- package/src/_shared/hooks/useKeyboardPickerState.ts +72 -0
- package/src/_shared/hooks/useOpenState.ts +22 -0
- package/src/_shared/hooks/usePickerState.ts +134 -0
- package/src/_shared/hooks/useUtils.ts +20 -0
- package/src/_shared/hooks/useViews.tsx +31 -0
- package/src/_shared/icons/ArrowLeftIcon.tsx +11 -0
- package/src/_shared/icons/ArrowRightIcon.tsx +11 -0
- package/src/_shared/icons/DateRangeIcon.tsx +11 -0
- package/src/_shared/icons/KeyboardIcon.tsx +11 -0
- package/src/_shared/icons/TimeIcon.tsx +12 -0
- package/src/constants/ClockType.ts +11 -0
- package/src/constants/dimensions.ts +5 -0
- package/src/constants/prop-types.ts +37 -0
- package/src/index.ts +48 -0
- package/src/typings/BasePicker.tsx +60 -0
- package/src/typings/date.ts +3 -0
- package/src/typings/extendMui.ts +10 -0
- package/src/typings/overrides.ts +44 -0
- package/src/views/Calendar/Calendar.tsx +361 -0
- package/src/views/Calendar/CalendarHeader.tsx +141 -0
- package/src/views/Calendar/Day.tsx +97 -0
- package/src/views/Calendar/DayWrapper.tsx +33 -0
- package/src/views/Calendar/SlideTransition.tsx +100 -0
- package/src/views/Clock/Clock.tsx +172 -0
- package/src/views/Clock/ClockNumber.tsx +91 -0
- package/src/views/Clock/ClockNumbers.tsx +76 -0
- package/src/views/Clock/ClockPointer.tsx +104 -0
- package/src/views/Clock/ClockView.tsx +105 -0
- package/src/views/Month/Month.tsx +76 -0
- package/src/views/Month/MonthView.tsx +94 -0
- package/src/views/Year/Year.tsx +77 -0
- package/src/views/Year/YearView.tsx +91 -0
- package/src/wrappers/InlineWrapper.tsx +80 -0
- package/src/wrappers/ModalWrapper.tsx +113 -0
- package/src/wrappers/StaticWrapper.tsx +22 -0
- package/src/wrappers/Wrapper.tsx +75 -0
- package/coverage/clover.xml +0 -601
- package/coverage/coverage-final.json +0 -22
- package/coverage/lcov-report/base.css +0 -224
- package/coverage/lcov-report/block-navigation.js +0 -79
- package/coverage/lcov-report/index.html +0 -201
- package/coverage/lcov-report/prettify.css +0 -1
- package/coverage/lcov-report/prettify.js +0 -2
- package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
- package/coverage/lcov-report/sorter.js +0 -170
- package/coverage/lcov-report/src/MuiPickersUtilsProvider.tsx.html +0 -186
- package/coverage/lcov-report/src/_helpers/date-utils.ts.html +0 -345
- package/coverage/lcov-report/src/_helpers/index.html +0 -123
- package/coverage/lcov-report/src/_helpers/time-utils.ts.html +0 -318
- package/coverage/lcov-report/src/_helpers/utils.ts.html +0 -93
- package/coverage/lcov-report/src/_shared/ModalDialog.tsx.html +0 -411
- package/coverage/lcov-report/src/_shared/WithUtils.tsx.html +0 -126
- package/coverage/lcov-report/src/_shared/hooks/index.html +0 -110
- package/coverage/lcov-report/src/_shared/hooks/useKeyDown.ts.html +0 -171
- package/coverage/lcov-report/src/_shared/hooks/useUtils.ts.html +0 -129
- package/coverage/lcov-report/src/_shared/icons/ArrowLeftIcon.tsx.html +0 -102
- package/coverage/lcov-report/src/_shared/icons/ArrowRightIcon.tsx.html +0 -102
- package/coverage/lcov-report/src/_shared/icons/index.html +0 -110
- package/coverage/lcov-report/src/_shared/index.html +0 -110
- package/coverage/lcov-report/src/constants/ClockType.ts.html +0 -102
- package/coverage/lcov-report/src/constants/dimensions.ts.html +0 -84
- package/coverage/lcov-report/src/constants/index.html +0 -110
- package/coverage/lcov-report/src/index.html +0 -97
- package/coverage/lcov-report/src/views/Calendar/Calendar.tsx.html +0 -1152
- package/coverage/lcov-report/src/views/Calendar/CalendarHeader.tsx.html +0 -492
- package/coverage/lcov-report/src/views/Calendar/Day.tsx.html +0 -360
- package/coverage/lcov-report/src/views/Calendar/DayWrapper.tsx.html +0 -168
- package/coverage/lcov-report/src/views/Calendar/SlideTransition.tsx.html +0 -369
- package/coverage/lcov-report/src/views/Calendar/index.html +0 -149
- package/coverage/lcov-report/src/views/Clock/Clock.tsx.html +0 -585
- package/coverage/lcov-report/src/views/Clock/ClockPointer.tsx.html +0 -381
- package/coverage/lcov-report/src/views/Clock/index.html +0 -110
- package/coverage/lcov-report/src/views/Month/Month.tsx.html +0 -297
- package/coverage/lcov-report/src/views/Month/MonthView.tsx.html +0 -351
- package/coverage/lcov-report/src/views/Month/index.html +0 -110
- package/coverage/lcov.info +0 -1094
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactWrapper } from 'enzyme';
|
|
3
|
+
import { clickOKButton } from './commands';
|
|
4
|
+
import { mount, utilsToUse } from '../test-utils';
|
|
5
|
+
import { DatePicker, DatePickerProps } from '../../DatePicker';
|
|
6
|
+
|
|
7
|
+
describe('e2e - DatePicker', () => {
|
|
8
|
+
let component: ReactWrapper<DatePickerProps>;
|
|
9
|
+
const onChangeMock = jest.fn();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
jest.clearAllMocks();
|
|
13
|
+
component = mount(
|
|
14
|
+
<DatePicker
|
|
15
|
+
open
|
|
16
|
+
autoOk
|
|
17
|
+
openTo="date"
|
|
18
|
+
animateYearScrolling={false}
|
|
19
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
20
|
+
onChange={onChangeMock}
|
|
21
|
+
/>
|
|
22
|
+
);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('Should renders', () => {
|
|
26
|
+
expect(component).toBeTruthy();
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('Should render proper count of days', () => {
|
|
30
|
+
expect(component.find('Day').length).toBe(35);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it('Should dispatch onChange on day click', () => {
|
|
34
|
+
component
|
|
35
|
+
.find('Day button')
|
|
36
|
+
.at(2)
|
|
37
|
+
.simulate('click');
|
|
38
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it('Should render year selection', () => {
|
|
42
|
+
component
|
|
43
|
+
.find('ToolbarButton')
|
|
44
|
+
.first()
|
|
45
|
+
.simulate('click');
|
|
46
|
+
|
|
47
|
+
expect(component.find('Year').length).toBe(201);
|
|
48
|
+
|
|
49
|
+
component
|
|
50
|
+
.find('Year')
|
|
51
|
+
.at(1)
|
|
52
|
+
.simulate('click');
|
|
53
|
+
|
|
54
|
+
clickOKButton(component);
|
|
55
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
56
|
+
});
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
describe('e2e -- DatePicker views year', () => {
|
|
60
|
+
const onChangeMock = jest.fn();
|
|
61
|
+
const onYearChangeMock = jest.fn();
|
|
62
|
+
|
|
63
|
+
let component: ReactWrapper<DatePickerProps>;
|
|
64
|
+
|
|
65
|
+
beforeEach(() => {
|
|
66
|
+
component = mount(
|
|
67
|
+
<DatePicker
|
|
68
|
+
open
|
|
69
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
70
|
+
onChange={onChangeMock}
|
|
71
|
+
onYearChange={onYearChangeMock}
|
|
72
|
+
views={['year']}
|
|
73
|
+
/>
|
|
74
|
+
);
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
it('Should render year selection and select year', () => {
|
|
78
|
+
expect(component.find('Year').length).toBe(201);
|
|
79
|
+
|
|
80
|
+
component
|
|
81
|
+
.find('Year')
|
|
82
|
+
.at(1)
|
|
83
|
+
.simulate('click');
|
|
84
|
+
|
|
85
|
+
clickOKButton(component);
|
|
86
|
+
expect(onYearChangeMock).toHaveBeenCalled();
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe('e2e -- DatePicker views year and month', () => {
|
|
91
|
+
const onChangeMock = jest.fn();
|
|
92
|
+
const onMonthChangeMock = jest.fn();
|
|
93
|
+
|
|
94
|
+
let component: ReactWrapper<DatePickerProps>;
|
|
95
|
+
|
|
96
|
+
beforeEach(() => {
|
|
97
|
+
component = mount(
|
|
98
|
+
<DatePicker
|
|
99
|
+
open
|
|
100
|
+
autoOk
|
|
101
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
102
|
+
onChange={onChangeMock}
|
|
103
|
+
onMonthChange={onMonthChangeMock}
|
|
104
|
+
openTo="month"
|
|
105
|
+
views={['year', 'month']}
|
|
106
|
+
/>
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
|
|
110
|
+
it('Should select month', () => {
|
|
111
|
+
expect(component.find('Month').length).toBe(12);
|
|
112
|
+
component
|
|
113
|
+
.find('Month')
|
|
114
|
+
.first()
|
|
115
|
+
.simulate('click');
|
|
116
|
+
|
|
117
|
+
expect(onMonthChangeMock).toHaveBeenCalled();
|
|
118
|
+
});
|
|
119
|
+
|
|
120
|
+
it('Should switch to year selection and back to month', () => {
|
|
121
|
+
component
|
|
122
|
+
.find('ToolbarButton')
|
|
123
|
+
.first()
|
|
124
|
+
.simulate('click');
|
|
125
|
+
|
|
126
|
+
const year = component.find('Year');
|
|
127
|
+
expect(component.find('Year').length).toBe(201);
|
|
128
|
+
|
|
129
|
+
year.first().simulate('click');
|
|
130
|
+
expect(component.find('Month').length).toBe(12);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
|
|
134
|
+
describe('e2e -- DatePicker views year and month open from year', () => {
|
|
135
|
+
const onChangeMock = jest.fn();
|
|
136
|
+
let component: ReactWrapper<DatePickerProps>;
|
|
137
|
+
|
|
138
|
+
beforeEach(() => {
|
|
139
|
+
component = mount(
|
|
140
|
+
<DatePicker
|
|
141
|
+
open
|
|
142
|
+
autoOk
|
|
143
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
144
|
+
onChange={onChangeMock}
|
|
145
|
+
views={['year', 'month']}
|
|
146
|
+
openTo="year"
|
|
147
|
+
/>
|
|
148
|
+
);
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
it('Should render year selection', () => {
|
|
152
|
+
expect(component.find('Year').length).toBe(201);
|
|
153
|
+
});
|
|
154
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactWrapper } from 'enzyme';
|
|
3
|
+
import { mount, utilsToUse } from '../test-utils';
|
|
4
|
+
import { DateTimePicker, DateTimePickerProps } from '../../DateTimePicker/DateTimePicker';
|
|
5
|
+
|
|
6
|
+
const format = process.env.UTILS === 'moment' ? 'MM/DD/YYYY HH:mm' : 'MM/dd/yyyy hh:mm';
|
|
7
|
+
|
|
8
|
+
describe('e2e - DateTimePicker', () => {
|
|
9
|
+
let component: ReactWrapper<DateTimePickerProps>;
|
|
10
|
+
|
|
11
|
+
const onCloseMock = jest.fn();
|
|
12
|
+
const onChangeMock = jest.fn();
|
|
13
|
+
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
component = mount(
|
|
16
|
+
<DateTimePicker
|
|
17
|
+
clearable
|
|
18
|
+
format={format}
|
|
19
|
+
onClose={onCloseMock}
|
|
20
|
+
onChange={onChangeMock}
|
|
21
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
22
|
+
/>
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Should renders', () => {
|
|
27
|
+
expect(component).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('Should open modal with picker on click', () => {
|
|
31
|
+
component.find('input').simulate('click');
|
|
32
|
+
expect(component.find('WithStyles(ForwardRef(Dialog))').prop('open')).toBeTruthy();
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('Should update state when passing new value from outside', () => {
|
|
36
|
+
component.setProps({ value: '2018-01-01T00:00:00.000Z' });
|
|
37
|
+
component.update(); // make additional react tick to update text field
|
|
38
|
+
|
|
39
|
+
const expectedString = utilsToUse.format(utilsToUse.date('2018-01-01T00:00:00.000Z'), format);
|
|
40
|
+
expect(component.find('input').props().value).toBe(expectedString);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it('Should change internal state on update', () => {
|
|
44
|
+
component.find('input').simulate('click');
|
|
45
|
+
component
|
|
46
|
+
.find('Day button')
|
|
47
|
+
.at(3)
|
|
48
|
+
.simulate('click');
|
|
49
|
+
|
|
50
|
+
expect(
|
|
51
|
+
component
|
|
52
|
+
.find('ToolbarButton')
|
|
53
|
+
.at(0)
|
|
54
|
+
.text()
|
|
55
|
+
).toBe('2018');
|
|
56
|
+
// expect(component.find('ToolbarButton').at(1).text()).toBe('Jan 3');
|
|
57
|
+
});
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
describe('e2e -- Controlling open state', () => {
|
|
61
|
+
let component: ReactWrapper<DateTimePickerProps>;
|
|
62
|
+
const onCloseMock = jest.fn();
|
|
63
|
+
|
|
64
|
+
beforeEach(() => {
|
|
65
|
+
component = mount(
|
|
66
|
+
<DateTimePicker
|
|
67
|
+
open
|
|
68
|
+
onClose={onCloseMock}
|
|
69
|
+
onChange={jest.fn()}
|
|
70
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
71
|
+
/>
|
|
72
|
+
);
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
it('Should be opened', () => {
|
|
76
|
+
expect(component.find('WithStyles(ForwardRef(Dialog))').prop('open')).toBeTruthy();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('Should close', () => {
|
|
80
|
+
component
|
|
81
|
+
.find('ForwardRef(DialogActions) button')
|
|
82
|
+
.at(0)
|
|
83
|
+
.simulate('click');
|
|
84
|
+
expect(onCloseMock).toHaveBeenCalled();
|
|
85
|
+
});
|
|
86
|
+
});
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactWrapper } from 'enzyme';
|
|
3
|
+
import { clickOKButton } from './commands';
|
|
4
|
+
import { mount, utilsToUse, toHaveBeenCalledExceptMoment } from '../test-utils';
|
|
5
|
+
import { DateTimePicker, DateTimePickerProps } from '../../DateTimePicker/DateTimePicker';
|
|
6
|
+
|
|
7
|
+
describe('e2e - DateTimePicker', () => {
|
|
8
|
+
let component: ReactWrapper<DateTimePickerProps>;
|
|
9
|
+
const onChangeMock = jest.fn();
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
jest.clearAllMocks();
|
|
13
|
+
component = mount(
|
|
14
|
+
<DateTimePicker
|
|
15
|
+
open
|
|
16
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
17
|
+
onChange={onChangeMock}
|
|
18
|
+
openTo="hours"
|
|
19
|
+
leftArrowIcon="keyboard_arrow_left"
|
|
20
|
+
rightArrowIcon="keyboard_arrow_right"
|
|
21
|
+
dateRangeIcon="date_range"
|
|
22
|
+
timeIcon="access_time"
|
|
23
|
+
/>
|
|
24
|
+
);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('Should renders', () => {
|
|
28
|
+
expect(component).toBeTruthy();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('Should display year view', () => {
|
|
32
|
+
component
|
|
33
|
+
.find('ToolbarButton')
|
|
34
|
+
.first()
|
|
35
|
+
.simulate('click');
|
|
36
|
+
|
|
37
|
+
expect(component.find('Year').length).toBe(201);
|
|
38
|
+
component
|
|
39
|
+
.find('Year')
|
|
40
|
+
.at(1)
|
|
41
|
+
.simulate('click');
|
|
42
|
+
|
|
43
|
+
clickOKButton(component);
|
|
44
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('Should render hour view', () => {
|
|
48
|
+
component
|
|
49
|
+
.find('ToolbarButton')
|
|
50
|
+
.at(2)
|
|
51
|
+
.simulate('click');
|
|
52
|
+
expect(component.find('TimePickerView').props().type).toBe('hours');
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
it('Should render minutes view', () => {
|
|
56
|
+
component
|
|
57
|
+
.find('ToolbarButton')
|
|
58
|
+
.at(3)
|
|
59
|
+
.simulate('click');
|
|
60
|
+
expect(component.find('TimePickerView').props().type).toBe('minutes');
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('Should change meridiem', () => {
|
|
64
|
+
component
|
|
65
|
+
.find('ToolbarButton')
|
|
66
|
+
.at(5)
|
|
67
|
+
.simulate('click');
|
|
68
|
+
|
|
69
|
+
clickOKButton(component);
|
|
70
|
+
toHaveBeenCalledExceptMoment(onChangeMock, [utilsToUse.date('2018-01-01T12:00:00.000Z')]);
|
|
71
|
+
});
|
|
72
|
+
});
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import addDays from 'date-fns/addDays';
|
|
3
|
+
import { ReactWrapper } from 'enzyme';
|
|
4
|
+
import { mount } from '../test-utils';
|
|
5
|
+
import { KeyboardDatePicker, KeyboardDatePickerProps } from '../../DatePicker/DatePicker';
|
|
6
|
+
|
|
7
|
+
describe('e2e -- DatePicker keyboard input', () => {
|
|
8
|
+
const onChangeMock = jest.fn();
|
|
9
|
+
let component: ReactWrapper<KeyboardDatePickerProps>;
|
|
10
|
+
|
|
11
|
+
beforeEach(() => {
|
|
12
|
+
component = mount(
|
|
13
|
+
<KeyboardDatePicker
|
|
14
|
+
label="Masked input"
|
|
15
|
+
placeholder="10/10/2018"
|
|
16
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
17
|
+
value={new Date('2018-01-01T00:00:00.000Z')}
|
|
18
|
+
onChange={onChangeMock}
|
|
19
|
+
InputAdornmentProps={{
|
|
20
|
+
disableTypography: true,
|
|
21
|
+
}}
|
|
22
|
+
InputLabelProps={{
|
|
23
|
+
htmlFor: 'your-id',
|
|
24
|
+
}}
|
|
25
|
+
/>
|
|
26
|
+
);
|
|
27
|
+
});
|
|
28
|
+
|
|
29
|
+
it('Should properly set value on change keyboard', () => {
|
|
30
|
+
const e = { target: { value: '10/11/2018' } };
|
|
31
|
+
|
|
32
|
+
component.find('input').simulate('change', e);
|
|
33
|
+
expect(component.find('input').prop('value')).toBe('10/11/2018');
|
|
34
|
+
|
|
35
|
+
component.find('input').simulate('blur');
|
|
36
|
+
expect(onChangeMock).toBeCalled();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
describe('e2e -- KeyboardDatePicker validation errors', () => {
|
|
41
|
+
it('Should render error message if date is unparseable', () => {
|
|
42
|
+
const component = mount(
|
|
43
|
+
<KeyboardDatePicker
|
|
44
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
45
|
+
value={new Date(NaN)}
|
|
46
|
+
onChange={jest.fn()}
|
|
47
|
+
/>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe('Invalid Date Format');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
it('Should render error message if date is after disableFuture', () => {
|
|
54
|
+
const component = mount(
|
|
55
|
+
<KeyboardDatePicker
|
|
56
|
+
onChange={jest.fn()}
|
|
57
|
+
disableFuture
|
|
58
|
+
value={addDays(new Date(), 2)}
|
|
59
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
60
|
+
/>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe(
|
|
64
|
+
'Date should not be after maximal date'
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
it('Should render error message if date is before disablePast', () => {
|
|
69
|
+
const component = mount(
|
|
70
|
+
<KeyboardDatePicker
|
|
71
|
+
onChange={jest.fn()}
|
|
72
|
+
disablePast
|
|
73
|
+
value={addDays(new Date(), -2)}
|
|
74
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
75
|
+
/>
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe(
|
|
79
|
+
'Date should not be before minimal date'
|
|
80
|
+
);
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
it('Should not render error message if date is after maxDate without strict comparison', () => {
|
|
84
|
+
const component = mount(
|
|
85
|
+
<KeyboardDatePicker
|
|
86
|
+
onChange={jest.fn()}
|
|
87
|
+
maxDate={new Date('2018-01-01T00:00:00.000Z')}
|
|
88
|
+
value={new Date('2018-01-01T01:00:00.000Z')}
|
|
89
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
90
|
+
/>
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe('');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('Should render error message if date is after maxDate with strict comparison', () => {
|
|
97
|
+
const component = mount(
|
|
98
|
+
<KeyboardDatePicker
|
|
99
|
+
onChange={jest.fn()}
|
|
100
|
+
maxDate={new Date('2018-01-01T00:00:00.000Z')}
|
|
101
|
+
value={new Date('2018-01-01T01:00:00.000Z')}
|
|
102
|
+
strictCompareDates
|
|
103
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
104
|
+
/>
|
|
105
|
+
);
|
|
106
|
+
|
|
107
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe(
|
|
108
|
+
'Date should not be after maximal date'
|
|
109
|
+
);
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
it('Should not render error message if date is after minDate without strict comparison', () => {
|
|
113
|
+
const component = mount(
|
|
114
|
+
<KeyboardDatePicker
|
|
115
|
+
onChange={jest.fn()}
|
|
116
|
+
minDate={new Date('2018-01-01T01:00:00.000Z')}
|
|
117
|
+
value={new Date('2018-01-01T00:00:00.000Z')}
|
|
118
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
119
|
+
/>
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe('');
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
it('Should render error message if date is after minDate with strict comparison', () => {
|
|
126
|
+
const component = mount(
|
|
127
|
+
<KeyboardDatePicker
|
|
128
|
+
onChange={jest.fn()}
|
|
129
|
+
minDate={new Date('2018-01-01T01:00:00.000Z')}
|
|
130
|
+
value={new Date('2018-01-01T00:00:00.000Z')}
|
|
131
|
+
strictCompareDates
|
|
132
|
+
format={process.env.UTILS === 'moment' ? 'DD/MM/YYYY' : 'dd/MM/yyyy'}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
|
|
136
|
+
expect(component.find('ForwardRef(TextField)').prop('helperText')).toBe(
|
|
137
|
+
'Date should not be before minimal date'
|
|
138
|
+
);
|
|
139
|
+
});
|
|
140
|
+
});
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactWrapper } from 'enzyme';
|
|
3
|
+
import { mount, utilsToUse } from '../test-utils';
|
|
4
|
+
import {
|
|
5
|
+
KeyboardDateTimePicker,
|
|
6
|
+
KeyboardDateTimePickerProps,
|
|
7
|
+
} from '../../DateTimePicker/DateTimePicker';
|
|
8
|
+
|
|
9
|
+
const format = process.env.UTILS === 'moment' ? 'MM/DD/YYYY HH:mm' : 'MM/dd/yyyy hh:mm';
|
|
10
|
+
|
|
11
|
+
describe('e2e - KeyboardDateTimePicker (inline)', () => {
|
|
12
|
+
let component: ReactWrapper<KeyboardDateTimePickerProps>;
|
|
13
|
+
const onChangeMock = jest.fn();
|
|
14
|
+
const onCloseMock = jest.fn();
|
|
15
|
+
const onOpenMock = jest.fn();
|
|
16
|
+
|
|
17
|
+
beforeEach(() => {
|
|
18
|
+
jest.clearAllMocks();
|
|
19
|
+
component = mount(
|
|
20
|
+
<KeyboardDateTimePicker
|
|
21
|
+
autoOk
|
|
22
|
+
variant="inline"
|
|
23
|
+
inputVariant="outlined"
|
|
24
|
+
onChange={onChangeMock}
|
|
25
|
+
onClose={onCloseMock}
|
|
26
|
+
onOpen={onOpenMock}
|
|
27
|
+
format={format}
|
|
28
|
+
KeyboardButtonProps={{ id: 'keyboard-button' }}
|
|
29
|
+
value={utilsToUse.date('2018-01-01T00:00:00.000Z')}
|
|
30
|
+
/>
|
|
31
|
+
);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it('Should renders', () => {
|
|
35
|
+
expect(component).toBeTruthy();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('Should open modal with picker on click', () => {
|
|
39
|
+
component.find('button#keyboard-button').simulate('click');
|
|
40
|
+
expect(component.find('WithStyles(ForwardRef(Popover))').props().open).toBeTruthy();
|
|
41
|
+
expect(onOpenMock).toHaveBeenCalled();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('Should apply keyboard input', () => {
|
|
45
|
+
component.find('input').simulate('change', { target: { value: '02/01/2018 10:00' } });
|
|
46
|
+
expect(onChangeMock).toHaveBeenCalled();
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { mount } from '../test-utils';
|
|
3
|
+
import { DatePicker } from '../../DatePicker';
|
|
4
|
+
import { createMuiTheme } from '@material-ui/core';
|
|
5
|
+
import { ThemeProvider } from '@material-ui/styles';
|
|
6
|
+
import { DateTimePicker } from '../../DateTimePicker/DateTimePicker';
|
|
7
|
+
|
|
8
|
+
const theme = createMuiTheme({
|
|
9
|
+
palette: {
|
|
10
|
+
type: 'dark',
|
|
11
|
+
},
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('Should renders without crash in dark theme', () => {
|
|
15
|
+
const component = mount(
|
|
16
|
+
<ThemeProvider theme={theme}>
|
|
17
|
+
<DateTimePicker open openTo="hours" value={null} onChange={jest.fn()} />
|
|
18
|
+
</ThemeProvider>
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
expect(component).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
test('Should render component with different orientation', () => {
|
|
25
|
+
const component = mount(
|
|
26
|
+
<DatePicker open orientation="landscape" value={null} onChange={jest.fn()} />
|
|
27
|
+
);
|
|
28
|
+
|
|
29
|
+
expect(component).toBeTruthy();
|
|
30
|
+
});
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { ReactWrapper } from 'enzyme';
|
|
3
|
+
import { clickOKButton } from './commands';
|
|
4
|
+
import { TimePicker, TimePickerProps } from '../../TimePicker/TimePicker';
|
|
5
|
+
import { mount, utilsToUse, toHaveBeenCalledExceptMoment } from '../test-utils';
|
|
6
|
+
|
|
7
|
+
const fakeTouchEvent = {
|
|
8
|
+
buttons: 1,
|
|
9
|
+
nativeEvent: {
|
|
10
|
+
offsetX: 20,
|
|
11
|
+
offsetY: 15,
|
|
12
|
+
},
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
describe('e2e - TimePicker', () => {
|
|
16
|
+
let component: ReactWrapper<TimePickerProps>;
|
|
17
|
+
const onChangeMock = jest.fn();
|
|
18
|
+
|
|
19
|
+
beforeEach(() => {
|
|
20
|
+
jest.clearAllMocks();
|
|
21
|
+
component = mount(
|
|
22
|
+
<TimePicker open value={utilsToUse.date('2018-01-01T00:00:00.000')} onChange={onChangeMock} />
|
|
23
|
+
);
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
it('Should renders', () => {
|
|
27
|
+
expect(component).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it('Should submit onChange on moving', () => {
|
|
31
|
+
component.find('Clock div[role="menu"]').simulate('mouseMove', fakeTouchEvent);
|
|
32
|
+
component.find('Clock div[role="menu"]').simulate('mouseUp', fakeTouchEvent);
|
|
33
|
+
|
|
34
|
+
expect(
|
|
35
|
+
component
|
|
36
|
+
.find('WithStyles(ToolbarButton)')
|
|
37
|
+
.at(0)
|
|
38
|
+
.text()
|
|
39
|
+
).toBe('11');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('Should change minutes (touch)', () => {
|
|
43
|
+
component
|
|
44
|
+
.find('WithStyles(ToolbarButton)')
|
|
45
|
+
.at(1)
|
|
46
|
+
.simulate('click');
|
|
47
|
+
|
|
48
|
+
component.find('Clock div[role="menu"]').simulate('touchMove', {
|
|
49
|
+
buttons: 1,
|
|
50
|
+
changedTouches: [
|
|
51
|
+
{
|
|
52
|
+
clientX: 20,
|
|
53
|
+
clientY: 15,
|
|
54
|
+
},
|
|
55
|
+
],
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
expect(
|
|
59
|
+
component
|
|
60
|
+
.find('WithStyles(ToolbarButton)')
|
|
61
|
+
.at(1)
|
|
62
|
+
.text()
|
|
63
|
+
).toBe('53');
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it('Should change meridiem mode', () => {
|
|
67
|
+
component
|
|
68
|
+
.find('WithStyles(ToolbarButton)')
|
|
69
|
+
.at(3)
|
|
70
|
+
.simulate('click');
|
|
71
|
+
|
|
72
|
+
clickOKButton(component);
|
|
73
|
+
toHaveBeenCalledExceptMoment(onChangeMock, [utilsToUse.date('2018-01-01T12:00:00.000')]);
|
|
74
|
+
});
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
describe('e2e - TimePicker with seconds', () => {
|
|
78
|
+
let component: ReactWrapper<TimePickerProps>;
|
|
79
|
+
const onChangeMock = jest.fn();
|
|
80
|
+
|
|
81
|
+
beforeEach(() => {
|
|
82
|
+
jest.clearAllMocks();
|
|
83
|
+
component = mount(
|
|
84
|
+
<TimePicker
|
|
85
|
+
open
|
|
86
|
+
views={['hours', 'minutes', 'seconds']}
|
|
87
|
+
value={utilsToUse.date('2018-01-01T00:00:12.000')}
|
|
88
|
+
onChange={onChangeMock}
|
|
89
|
+
/>
|
|
90
|
+
);
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('Should show seconds number', () => {
|
|
94
|
+
expect(
|
|
95
|
+
component
|
|
96
|
+
.find('WithStyles(ToolbarButton)')
|
|
97
|
+
.at(2)
|
|
98
|
+
.text()
|
|
99
|
+
).toBe('12');
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it('Should change seconds', () => {
|
|
103
|
+
component
|
|
104
|
+
.find('WithStyles(ToolbarButton)')
|
|
105
|
+
.at(2)
|
|
106
|
+
.simulate('click');
|
|
107
|
+
|
|
108
|
+
component.find('Clock div[role="menu"]').simulate('touchMove', {
|
|
109
|
+
buttons: 1,
|
|
110
|
+
changedTouches: [
|
|
111
|
+
{
|
|
112
|
+
clientX: 20,
|
|
113
|
+
clientY: 15,
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
clickOKButton(component);
|
|
119
|
+
toHaveBeenCalledExceptMoment(onChangeMock, [utilsToUse.date('2018-01-01T00:00:53.000')]);
|
|
120
|
+
});
|
|
121
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const Enzyme = require('enzyme');
|
|
2
|
+
const EnzymeAdapter = require('enzyme-adapter-react-16');
|
|
3
|
+
|
|
4
|
+
// Setup enzyme's react adapter
|
|
5
|
+
Enzyme.configure({ adapter: new EnzymeAdapter() });
|
|
6
|
+
|
|
7
|
+
// Convert any console error into a thrown error
|
|
8
|
+
const error = console.error;
|
|
9
|
+
console.error = (...args) => {
|
|
10
|
+
error.apply(console, args);
|
|
11
|
+
if (args[0] instanceof Error) {
|
|
12
|
+
throw args[0];
|
|
13
|
+
} else {
|
|
14
|
+
// combine multi args into a string
|
|
15
|
+
const message = args
|
|
16
|
+
.map(value => {
|
|
17
|
+
if (typeof value === 'object') {
|
|
18
|
+
return JSON.stringify(value);
|
|
19
|
+
} else {
|
|
20
|
+
return value;
|
|
21
|
+
}
|
|
22
|
+
})
|
|
23
|
+
.join(' ');
|
|
24
|
+
throw new Error(message);
|
|
25
|
+
}
|
|
26
|
+
};
|