@mui/x-date-pickers-pro 6.14.0 → 6.16.0
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/CHANGELOG.md +167 -0
- package/DateRangeCalendar/DateRangeCalendar.js +6 -2
- package/DateRangeCalendar/DateRangeCalendar.types.d.ts +1 -1
- package/DateRangePicker/DateRangePicker.js +6 -2
- package/DateRangePicker/DateRangePickerToolbar.js +1 -0
- package/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
- package/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
- package/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
- package/MultiInputDateRangeField/MultiInputDateRangeField.types.d.ts +1 -1
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
- package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.d.ts +1 -1
- package/MultiInputTimeRangeField/MultiInputTimeRangeField.types.d.ts +1 -1
- package/SingleInputDateRangeField/SingleInputDateRangeField.js +32 -4
- package/SingleInputDateRangeField/SingleInputDateRangeField.types.d.ts +3 -3
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +32 -4
- package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.d.ts +3 -3
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.js +29 -4
- package/SingleInputTimeRangeField/SingleInputTimeRangeField.types.d.ts +3 -3
- package/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
- package/index.js +1 -1
- package/internals/hooks/useEnrichedRangePickerFieldProps.d.ts +3 -3
- package/internals/hooks/useEnrichedRangePickerFieldProps.js +12 -3
- package/internals/hooks/useMultiInputRangeField/shared.d.ts +1 -0
- package/internals/hooks/useMultiInputRangeField/shared.js +9 -0
- package/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
- package/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
- package/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
- package/internals/models/dateRange.d.ts +3 -0
- package/internals/utils/releaseInfo.js +1 -1
- package/legacy/DateRangeCalendar/DateRangeCalendar.js +6 -2
- package/legacy/DateRangePicker/DateRangePicker.js +6 -2
- package/legacy/DateRangePicker/DateRangePickerToolbar.js +1 -0
- package/legacy/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
- package/legacy/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
- package/legacy/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
- package/legacy/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
- package/legacy/SingleInputDateRangeField/SingleInputDateRangeField.js +30 -3
- package/legacy/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +30 -3
- package/legacy/SingleInputTimeRangeField/SingleInputTimeRangeField.js +27 -3
- package/legacy/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
- package/legacy/index.js +1 -1
- package/legacy/internals/hooks/useEnrichedRangePickerFieldProps.js +14 -3
- package/legacy/internals/hooks/useMultiInputRangeField/shared.js +9 -0
- package/legacy/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
- package/legacy/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
- package/legacy/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
- package/legacy/internals/utils/releaseInfo.js +1 -1
- package/modern/DateRangeCalendar/DateRangeCalendar.js +6 -2
- package/modern/DateRangePicker/DateRangePicker.js +6 -2
- package/modern/DateRangePicker/DateRangePickerToolbar.js +1 -0
- package/modern/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
- package/modern/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
- package/modern/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
- package/modern/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
- package/modern/SingleInputDateRangeField/SingleInputDateRangeField.js +32 -4
- package/modern/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +32 -4
- package/modern/SingleInputTimeRangeField/SingleInputTimeRangeField.js +29 -4
- package/modern/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
- package/modern/index.js +1 -1
- package/modern/internals/hooks/useEnrichedRangePickerFieldProps.js +12 -3
- package/modern/internals/hooks/useMultiInputRangeField/shared.js +9 -0
- package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
- package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
- package/modern/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
- package/modern/internals/utils/releaseInfo.js +1 -1
- package/node/DateRangeCalendar/DateRangeCalendar.js +6 -2
- package/node/DateRangePicker/DateRangePicker.js +6 -2
- package/node/DateRangePicker/DateRangePickerToolbar.js +1 -0
- package/node/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
- package/node/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
- package/node/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
- package/node/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
- package/node/SingleInputDateRangeField/SingleInputDateRangeField.js +32 -4
- package/node/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +32 -4
- package/node/SingleInputTimeRangeField/SingleInputTimeRangeField.js +29 -4
- package/node/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
- package/node/index.js +1 -1
- package/node/internals/hooks/useEnrichedRangePickerFieldProps.js +12 -3
- package/node/internals/hooks/useMultiInputRangeField/shared.js +16 -0
- package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
- package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
- package/node/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
- package/node/internals/utils/releaseInfo.js +1 -1
- package/package.json +2 -2
- package/legacy/tests/describeRangeValidation/describeRangeValidation.js +0 -29
- package/legacy/tests/describeRangeValidation/describeRangeValidation.types.js +0 -1
- package/legacy/tests/describeRangeValidation/index.js +0 -1
- package/legacy/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -144
- package/legacy/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -291
- package/legacy/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -518
- package/modern/tests/describeRangeValidation/describeRangeValidation.js +0 -29
- package/modern/tests/describeRangeValidation/describeRangeValidation.types.js +0 -1
- package/modern/tests/describeRangeValidation/index.js +0 -1
- package/modern/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -145
- package/modern/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -285
- package/modern/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -520
- package/node/tests/describeRangeValidation/describeRangeValidation.js +0 -37
- package/node/tests/describeRangeValidation/describeRangeValidation.types.js +0 -5
- package/node/tests/describeRangeValidation/index.js +0 -12
- package/node/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -154
- package/node/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -294
- package/node/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -530
- package/tests/describeRangeValidation/describeRangeValidation.js +0 -29
- package/tests/describeRangeValidation/describeRangeValidation.types.js +0 -1
- package/tests/describeRangeValidation/index.js +0 -1
- package/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -145
- package/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -285
- package/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -520
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
2
|
-
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
3
|
-
const _excluded = ["defaultCalendarMonth"],
|
|
4
|
-
_excluded2 = ["defaultCalendarMonth"];
|
|
5
|
-
import * as React from 'react';
|
|
6
|
-
import { expect } from 'chai';
|
|
7
|
-
import { screen } from '@mui/monorepo/test/utils';
|
|
8
|
-
import { adapterToUse } from 'test/utils/pickers';
|
|
9
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
10
|
-
const isDisable = el => el.getAttribute('disabled') !== null;
|
|
11
|
-
const testDisabledDate = (day, expectedAnswer, isDesktop) => {
|
|
12
|
-
expect(screen.getAllByText(day).map(isDisable)).to.deep.equal(isDesktop ? expectedAnswer : expectedAnswer.slice(0, 1));
|
|
13
|
-
};
|
|
14
|
-
const testMonthSwitcherAreDisable = areDisable => {
|
|
15
|
-
const prevMonthElement = screen.getAllByLabelText('Previous month')[0];
|
|
16
|
-
const nbCalendars = screen.getAllByLabelText('Next month').length;
|
|
17
|
-
const nextMonthElement = screen.getAllByLabelText('Next month')[nbCalendars - 1];
|
|
18
|
-
// Test prev month
|
|
19
|
-
if (areDisable[0]) {
|
|
20
|
-
expect(prevMonthElement).to.have.attribute('disabled');
|
|
21
|
-
} else {
|
|
22
|
-
expect(prevMonthElement).not.to.have.attribute('disabled');
|
|
23
|
-
}
|
|
24
|
-
// Test next month
|
|
25
|
-
if (areDisable[1]) {
|
|
26
|
-
expect(nextMonthElement).to.have.attribute('disabled');
|
|
27
|
-
} else {
|
|
28
|
-
expect(nextMonthElement).not.to.have.attribute('disabled');
|
|
29
|
-
}
|
|
30
|
-
};
|
|
31
|
-
export function testDayViewRangeValidation(ElementToTest, getOptions) {
|
|
32
|
-
describe('validation in day view:', () => {
|
|
33
|
-
const {
|
|
34
|
-
componentFamily,
|
|
35
|
-
views,
|
|
36
|
-
variant = 'desktop'
|
|
37
|
-
} = getOptions();
|
|
38
|
-
if (!views.includes('day') || componentFamily === 'field') {
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
const isDesktop = variant === 'desktop';
|
|
42
|
-
const defaultProps = {
|
|
43
|
-
defaultCalendarMonth: adapterToUse.date(new Date(2018, 2, 12)),
|
|
44
|
-
open: true
|
|
45
|
-
};
|
|
46
|
-
it('should apply shouldDisableDate', function test() {
|
|
47
|
-
const {
|
|
48
|
-
render
|
|
49
|
-
} = getOptions();
|
|
50
|
-
render( /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, {
|
|
51
|
-
shouldDisableDate: date => adapterToUse.isAfter(date, adapterToUse.date(new Date(2018, 2, 10)))
|
|
52
|
-
})));
|
|
53
|
-
testDisabledDate('10', [false, true], isDesktop);
|
|
54
|
-
testDisabledDate('11', [true, true], isDesktop);
|
|
55
|
-
});
|
|
56
|
-
it('should apply disablePast', function test() {
|
|
57
|
-
const {
|
|
58
|
-
render,
|
|
59
|
-
clock
|
|
60
|
-
} = getOptions();
|
|
61
|
-
let now;
|
|
62
|
-
function WithFakeTimer(props) {
|
|
63
|
-
now = adapterToUse.date(new Date());
|
|
64
|
-
const otherProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
65
|
-
return /*#__PURE__*/_jsx(ElementToTest, _extends({
|
|
66
|
-
value: [now, null]
|
|
67
|
-
}, otherProps));
|
|
68
|
-
}
|
|
69
|
-
const {
|
|
70
|
-
setProps
|
|
71
|
-
} = render( /*#__PURE__*/_jsx(WithFakeTimer, _extends({}, defaultProps, {
|
|
72
|
-
disablePast: true
|
|
73
|
-
})));
|
|
74
|
-
const tomorrow = adapterToUse.addDays(now, 1);
|
|
75
|
-
const yesterday = adapterToUse.addDays(now, -1);
|
|
76
|
-
testDisabledDate(adapterToUse.format(now, 'dayOfMonth'), [false, false], isDesktop);
|
|
77
|
-
testDisabledDate(adapterToUse.format(tomorrow, 'dayOfMonth'), [false, false], isDesktop);
|
|
78
|
-
if (!adapterToUse.isSameMonth(yesterday, tomorrow)) {
|
|
79
|
-
setProps({
|
|
80
|
-
value: [yesterday, null]
|
|
81
|
-
});
|
|
82
|
-
clock.runToLast();
|
|
83
|
-
}
|
|
84
|
-
testDisabledDate(adapterToUse.format(yesterday, 'dayOfMonth'), [true, false], isDesktop);
|
|
85
|
-
});
|
|
86
|
-
it('should apply disableFuture', function test() {
|
|
87
|
-
const {
|
|
88
|
-
render,
|
|
89
|
-
clock
|
|
90
|
-
} = getOptions();
|
|
91
|
-
let now;
|
|
92
|
-
function WithFakeTimer(props) {
|
|
93
|
-
now = adapterToUse.date(new Date());
|
|
94
|
-
const otherProps = _objectWithoutPropertiesLoose(props, _excluded2);
|
|
95
|
-
return /*#__PURE__*/_jsx(ElementToTest, _extends({
|
|
96
|
-
value: [now, null]
|
|
97
|
-
}, otherProps));
|
|
98
|
-
}
|
|
99
|
-
const {
|
|
100
|
-
setProps
|
|
101
|
-
} = render( /*#__PURE__*/_jsx(WithFakeTimer, _extends({}, defaultProps, {
|
|
102
|
-
disableFuture: true
|
|
103
|
-
})));
|
|
104
|
-
const tomorrow = adapterToUse.addDays(now, 1);
|
|
105
|
-
const yesterday = adapterToUse.addDays(now, -1);
|
|
106
|
-
testDisabledDate(adapterToUse.format(now, 'dayOfMonth'), [false, true], isDesktop);
|
|
107
|
-
testDisabledDate(adapterToUse.format(tomorrow, 'dayOfMonth'), [true, true], isDesktop);
|
|
108
|
-
if (!adapterToUse.isSameMonth(yesterday, tomorrow)) {
|
|
109
|
-
setProps({
|
|
110
|
-
value: [yesterday, null]
|
|
111
|
-
});
|
|
112
|
-
clock.runToLast();
|
|
113
|
-
}
|
|
114
|
-
testDisabledDate(adapterToUse.format(yesterday, 'dayOfMonth'), [false, true], isDesktop);
|
|
115
|
-
});
|
|
116
|
-
it('should apply minDate', function test() {
|
|
117
|
-
const {
|
|
118
|
-
render
|
|
119
|
-
} = getOptions();
|
|
120
|
-
render( /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, {
|
|
121
|
-
defaultCalendarMonth: adapterToUse.date(new Date(2019, 5, 15)),
|
|
122
|
-
minDate: adapterToUse.date(new Date(2019, 5, 4))
|
|
123
|
-
})));
|
|
124
|
-
testDisabledDate('1', [true, false], isDesktop);
|
|
125
|
-
testDisabledDate('3', [true, false], isDesktop);
|
|
126
|
-
testDisabledDate('4', [false, false], isDesktop);
|
|
127
|
-
testDisabledDate('15', [false, false], isDesktop);
|
|
128
|
-
testMonthSwitcherAreDisable([true, false]);
|
|
129
|
-
});
|
|
130
|
-
it('should apply maxDate', function test() {
|
|
131
|
-
const {
|
|
132
|
-
render
|
|
133
|
-
} = getOptions();
|
|
134
|
-
render( /*#__PURE__*/_jsx(ElementToTest, _extends({}, defaultProps, {
|
|
135
|
-
defaultCalendarMonth: adapterToUse.date(new Date(2019, 5, 15)),
|
|
136
|
-
maxDate: adapterToUse.date(new Date(2019, 5, 4))
|
|
137
|
-
})));
|
|
138
|
-
testDisabledDate('1', [false, true], isDesktop);
|
|
139
|
-
testDisabledDate('4', [false, true], isDesktop);
|
|
140
|
-
testDisabledDate('5', [true, true], isDesktop);
|
|
141
|
-
testDisabledDate('15', [true, true], isDesktop);
|
|
142
|
-
testMonthSwitcherAreDisable([false, true]);
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
}
|
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import { spy } from 'sinon';
|
|
4
|
-
import { screen } from '@mui/monorepo/test/utils';
|
|
5
|
-
import { adapterToUse } from 'test/utils/pickers';
|
|
6
|
-
import { act } from '@mui/monorepo/test/utils/createRenderer';
|
|
7
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
8
|
-
const testInvalidStatus = (expectedAnswer, isSingleInput) => {
|
|
9
|
-
const answers = isSingleInput ? [expectedAnswer[0] || expectedAnswer[1]] : expectedAnswer;
|
|
10
|
-
const textBoxes = screen.getAllByRole('textbox');
|
|
11
|
-
answers.forEach((answer, index) => {
|
|
12
|
-
const textBox = textBoxes[index];
|
|
13
|
-
expect(textBox).to.have.attribute('aria-invalid', answer ? 'true' : 'false');
|
|
14
|
-
});
|
|
15
|
-
};
|
|
16
|
-
const dateParser = value => {
|
|
17
|
-
return value.map(date => date === null ? date : adapterToUse.date(new Date(...date)));
|
|
18
|
-
};
|
|
19
|
-
export const testTextFieldKeyboardRangeValidation = (ElementToTest, getOptions) => {
|
|
20
|
-
const {
|
|
21
|
-
componentFamily,
|
|
22
|
-
render,
|
|
23
|
-
isSingleInput,
|
|
24
|
-
withDate,
|
|
25
|
-
withTime,
|
|
26
|
-
inputValue
|
|
27
|
-
} = getOptions();
|
|
28
|
-
if (componentFamily !== 'field' || !inputValue) {
|
|
29
|
-
return;
|
|
30
|
-
}
|
|
31
|
-
describe('text field keyboard:', () => {
|
|
32
|
-
it('should not accept end date prior to start state', () => {
|
|
33
|
-
const onErrorMock = spy();
|
|
34
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
35
|
-
onError: onErrorMock
|
|
36
|
-
}));
|
|
37
|
-
expect(onErrorMock.callCount).to.equal(0);
|
|
38
|
-
act(() => {
|
|
39
|
-
dateParser([[2018, 0, 2, 12, 0, 0], [2018, 0, 1, 11, 0, 0]]).forEach((date, index) => {
|
|
40
|
-
inputValue(date, {
|
|
41
|
-
setEndDate: index === 1
|
|
42
|
-
});
|
|
43
|
-
});
|
|
44
|
-
});
|
|
45
|
-
expect(onErrorMock.callCount).to.equal(1);
|
|
46
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['invalidRange', 'invalidRange']);
|
|
47
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
48
|
-
});
|
|
49
|
-
it('should apply shouldDisableDate', function test() {
|
|
50
|
-
if (!withDate) {
|
|
51
|
-
return;
|
|
52
|
-
}
|
|
53
|
-
const onErrorMock = spy();
|
|
54
|
-
const {
|
|
55
|
-
setProps
|
|
56
|
-
} = render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
57
|
-
onError: onErrorMock,
|
|
58
|
-
shouldDisableDate: date => adapterToUse.isAfter(date, adapterToUse.date(new Date(2018, 2, 11)))
|
|
59
|
-
}));
|
|
60
|
-
act(() => {
|
|
61
|
-
dateParser([[2018, 2, 9], [2018, 2, 10]]).forEach((date, index) => {
|
|
62
|
-
inputValue(date, {
|
|
63
|
-
setEndDate: index === 1
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
});
|
|
67
|
-
expect(onErrorMock.callCount).to.equal(0);
|
|
68
|
-
testInvalidStatus([false, false], isSingleInput);
|
|
69
|
-
act(() => {
|
|
70
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 13)), {
|
|
71
|
-
setEndDate: true
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
expect(onErrorMock.callCount).to.equal(1);
|
|
75
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'shouldDisableDate']);
|
|
76
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
77
|
-
act(() => {
|
|
78
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 12)));
|
|
79
|
-
});
|
|
80
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
81
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['shouldDisableDate', 'shouldDisableDate']);
|
|
82
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
83
|
-
setProps({
|
|
84
|
-
shouldDisableDate: date => adapterToUse.isBefore(date, adapterToUse.date(new Date(2018, 2, 13)))
|
|
85
|
-
});
|
|
86
|
-
expect(onErrorMock.callCount).to.equal(3);
|
|
87
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['shouldDisableDate', null]);
|
|
88
|
-
testInvalidStatus([true, false], isSingleInput);
|
|
89
|
-
});
|
|
90
|
-
it('should apply disablePast', function test() {
|
|
91
|
-
const onErrorMock = spy();
|
|
92
|
-
const now = adapterToUse.date(new Date());
|
|
93
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
94
|
-
disablePast: true,
|
|
95
|
-
onError: onErrorMock
|
|
96
|
-
}));
|
|
97
|
-
let past = null;
|
|
98
|
-
if (withDate) {
|
|
99
|
-
past = adapterToUse.addDays(now, -1);
|
|
100
|
-
} else if (adapterToUse.isSameDay(adapterToUse.addHours(now, -1), now)) {
|
|
101
|
-
past = adapterToUse.addHours(now, -1);
|
|
102
|
-
}
|
|
103
|
-
if (past === null) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
act(() => {
|
|
107
|
-
inputValue(adapterToUse.date(past));
|
|
108
|
-
});
|
|
109
|
-
expect(onErrorMock.callCount).to.equal(1);
|
|
110
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['disablePast', null]);
|
|
111
|
-
testInvalidStatus([true, false], isSingleInput);
|
|
112
|
-
act(() => {
|
|
113
|
-
inputValue(adapterToUse.date(past), {
|
|
114
|
-
setEndDate: true
|
|
115
|
-
});
|
|
116
|
-
});
|
|
117
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
118
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['disablePast', 'disablePast']);
|
|
119
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
120
|
-
act(() => {
|
|
121
|
-
inputValue(adapterToUse.date(now));
|
|
122
|
-
});
|
|
123
|
-
expect(onErrorMock.callCount).to.equal(3);
|
|
124
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disablePast']);
|
|
125
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
126
|
-
});
|
|
127
|
-
it('should apply disableFuture', function test() {
|
|
128
|
-
const onErrorMock = spy();
|
|
129
|
-
const now = adapterToUse.date(new Date());
|
|
130
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
131
|
-
disableFuture: true,
|
|
132
|
-
onError: onErrorMock
|
|
133
|
-
}));
|
|
134
|
-
let future = null;
|
|
135
|
-
if (withDate) {
|
|
136
|
-
future = adapterToUse.addDays(now, 1);
|
|
137
|
-
} else if (adapterToUse.isSameDay(adapterToUse.addHours(now, 1), now)) {
|
|
138
|
-
future = adapterToUse.addHours(now, 1);
|
|
139
|
-
}
|
|
140
|
-
if (future === null) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
act(() => {
|
|
144
|
-
inputValue(adapterToUse.date(future), {
|
|
145
|
-
setEndDate: true
|
|
146
|
-
});
|
|
147
|
-
});
|
|
148
|
-
expect(onErrorMock.callCount).to.equal(1);
|
|
149
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disableFuture']);
|
|
150
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
151
|
-
act(() => {
|
|
152
|
-
inputValue(adapterToUse.date(future));
|
|
153
|
-
});
|
|
154
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
155
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['disableFuture', 'disableFuture']);
|
|
156
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
157
|
-
act(() => {
|
|
158
|
-
inputValue(adapterToUse.date(now));
|
|
159
|
-
});
|
|
160
|
-
expect(onErrorMock.callCount).to.equal(3);
|
|
161
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disableFuture']);
|
|
162
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
163
|
-
});
|
|
164
|
-
it('should apply minDate', function test() {
|
|
165
|
-
if (!withDate) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
const onErrorMock = spy();
|
|
169
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
170
|
-
onError: onErrorMock,
|
|
171
|
-
minDate: adapterToUse.date(new Date(2018, 2, 15))
|
|
172
|
-
}));
|
|
173
|
-
act(() => {
|
|
174
|
-
dateParser([[2018, 2, 9], [2018, 2, 10]]).forEach((date, index) => {
|
|
175
|
-
inputValue(date, {
|
|
176
|
-
setEndDate: index === 1
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
});
|
|
180
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
181
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', 'minDate']);
|
|
182
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
183
|
-
act(() => {
|
|
184
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 15)));
|
|
185
|
-
});
|
|
186
|
-
expect(onErrorMock.callCount).to.equal(3);
|
|
187
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'minDate']);
|
|
188
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
189
|
-
act(() => {
|
|
190
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 16)), {
|
|
191
|
-
setEndDate: true
|
|
192
|
-
});
|
|
193
|
-
});
|
|
194
|
-
expect(onErrorMock.callCount).to.equal(4);
|
|
195
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
|
|
196
|
-
testInvalidStatus([false, false], isSingleInput);
|
|
197
|
-
});
|
|
198
|
-
it('should apply maxDate', function test() {
|
|
199
|
-
if (!withDate) {
|
|
200
|
-
return;
|
|
201
|
-
}
|
|
202
|
-
const onErrorMock = spy();
|
|
203
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
204
|
-
onError: onErrorMock,
|
|
205
|
-
maxDate: adapterToUse.date(new Date(2018, 2, 15))
|
|
206
|
-
}));
|
|
207
|
-
act(() => {
|
|
208
|
-
dateParser([[2018, 2, 15], [2018, 2, 17]]).forEach((date, index) => {
|
|
209
|
-
inputValue(date, {
|
|
210
|
-
setEndDate: index === 1
|
|
211
|
-
});
|
|
212
|
-
});
|
|
213
|
-
});
|
|
214
|
-
expect(onErrorMock.callCount).to.equal(1);
|
|
215
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxDate']);
|
|
216
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
217
|
-
act(() => {
|
|
218
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 16)));
|
|
219
|
-
});
|
|
220
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
221
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['maxDate', 'maxDate']);
|
|
222
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
223
|
-
});
|
|
224
|
-
it('should apply minTime', function test() {
|
|
225
|
-
if (!withTime) {
|
|
226
|
-
return;
|
|
227
|
-
}
|
|
228
|
-
const onErrorMock = spy();
|
|
229
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
230
|
-
onError: onErrorMock,
|
|
231
|
-
minTime: adapterToUse.date(new Date(2018, 2, 10, 12, 0, 0))
|
|
232
|
-
}));
|
|
233
|
-
act(() => {
|
|
234
|
-
dateParser([[2018, 2, 10, 9, 0, 0], [2018, 2, 10, 10, 0, 0]]).forEach((date, index) => {
|
|
235
|
-
inputValue(date, {
|
|
236
|
-
setEndDate: index === 1
|
|
237
|
-
});
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
241
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', 'minTime']);
|
|
242
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
243
|
-
act(() => {
|
|
244
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 10, 12, 10, 0)), {
|
|
245
|
-
setEndDate: true
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
expect(onErrorMock.callCount).to.equal(3);
|
|
249
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', null]);
|
|
250
|
-
testInvalidStatus([true, false], isSingleInput);
|
|
251
|
-
act(() => {
|
|
252
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 10, 12, 5, 0)));
|
|
253
|
-
});
|
|
254
|
-
expect(onErrorMock.callCount).to.equal(4);
|
|
255
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
|
|
256
|
-
testInvalidStatus([false, false], isSingleInput);
|
|
257
|
-
});
|
|
258
|
-
it('should apply maxTime', function test() {
|
|
259
|
-
if (!withTime) {
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
const onErrorMock = spy();
|
|
263
|
-
render( /*#__PURE__*/_jsx(ElementToTest, {
|
|
264
|
-
onError: onErrorMock,
|
|
265
|
-
maxTime: adapterToUse.date(new Date(2018, 2, 10, 12, 0))
|
|
266
|
-
}));
|
|
267
|
-
act(() => {
|
|
268
|
-
dateParser([[2018, 2, 10, 9, 0, 0], [2018, 2, 10, 12, 15, 0]]).forEach((date, index) => {
|
|
269
|
-
inputValue(date, {
|
|
270
|
-
setEndDate: index === 1
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
expect(onErrorMock.callCount).to.equal(1);
|
|
275
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxTime']);
|
|
276
|
-
testInvalidStatus([false, true], isSingleInput);
|
|
277
|
-
act(() => {
|
|
278
|
-
inputValue(adapterToUse.date(new Date(2018, 2, 10, 12, 5, 0)));
|
|
279
|
-
});
|
|
280
|
-
expect(onErrorMock.callCount).to.equal(2);
|
|
281
|
-
expect(onErrorMock.lastCall.args[0]).to.deep.equal(['maxTime', 'maxTime']);
|
|
282
|
-
testInvalidStatus([true, true], isSingleInput);
|
|
283
|
-
});
|
|
284
|
-
});
|
|
285
|
-
};
|