@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.
Files changed (108) hide show
  1. package/CHANGELOG.md +167 -0
  2. package/DateRangeCalendar/DateRangeCalendar.js +6 -2
  3. package/DateRangeCalendar/DateRangeCalendar.types.d.ts +1 -1
  4. package/DateRangePicker/DateRangePicker.js +6 -2
  5. package/DateRangePicker/DateRangePickerToolbar.js +1 -0
  6. package/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
  7. package/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
  8. package/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
  9. package/MultiInputDateRangeField/MultiInputDateRangeField.types.d.ts +1 -1
  10. package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
  11. package/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.types.d.ts +1 -1
  12. package/MultiInputTimeRangeField/MultiInputTimeRangeField.types.d.ts +1 -1
  13. package/SingleInputDateRangeField/SingleInputDateRangeField.js +32 -4
  14. package/SingleInputDateRangeField/SingleInputDateRangeField.types.d.ts +3 -3
  15. package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +32 -4
  16. package/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.types.d.ts +3 -3
  17. package/SingleInputTimeRangeField/SingleInputTimeRangeField.js +29 -4
  18. package/SingleInputTimeRangeField/SingleInputTimeRangeField.types.d.ts +3 -3
  19. package/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
  20. package/index.js +1 -1
  21. package/internals/hooks/useEnrichedRangePickerFieldProps.d.ts +3 -3
  22. package/internals/hooks/useEnrichedRangePickerFieldProps.js +12 -3
  23. package/internals/hooks/useMultiInputRangeField/shared.d.ts +1 -0
  24. package/internals/hooks/useMultiInputRangeField/shared.js +9 -0
  25. package/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
  26. package/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
  27. package/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
  28. package/internals/models/dateRange.d.ts +3 -0
  29. package/internals/utils/releaseInfo.js +1 -1
  30. package/legacy/DateRangeCalendar/DateRangeCalendar.js +6 -2
  31. package/legacy/DateRangePicker/DateRangePicker.js +6 -2
  32. package/legacy/DateRangePicker/DateRangePickerToolbar.js +1 -0
  33. package/legacy/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
  34. package/legacy/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
  35. package/legacy/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
  36. package/legacy/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
  37. package/legacy/SingleInputDateRangeField/SingleInputDateRangeField.js +30 -3
  38. package/legacy/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +30 -3
  39. package/legacy/SingleInputTimeRangeField/SingleInputTimeRangeField.js +27 -3
  40. package/legacy/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
  41. package/legacy/index.js +1 -1
  42. package/legacy/internals/hooks/useEnrichedRangePickerFieldProps.js +14 -3
  43. package/legacy/internals/hooks/useMultiInputRangeField/shared.js +9 -0
  44. package/legacy/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
  45. package/legacy/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
  46. package/legacy/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
  47. package/legacy/internals/utils/releaseInfo.js +1 -1
  48. package/modern/DateRangeCalendar/DateRangeCalendar.js +6 -2
  49. package/modern/DateRangePicker/DateRangePicker.js +6 -2
  50. package/modern/DateRangePicker/DateRangePickerToolbar.js +1 -0
  51. package/modern/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
  52. package/modern/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
  53. package/modern/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
  54. package/modern/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
  55. package/modern/SingleInputDateRangeField/SingleInputDateRangeField.js +32 -4
  56. package/modern/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +32 -4
  57. package/modern/SingleInputTimeRangeField/SingleInputTimeRangeField.js +29 -4
  58. package/modern/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
  59. package/modern/index.js +1 -1
  60. package/modern/internals/hooks/useEnrichedRangePickerFieldProps.js +12 -3
  61. package/modern/internals/hooks/useMultiInputRangeField/shared.js +9 -0
  62. package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
  63. package/modern/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
  64. package/modern/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
  65. package/modern/internals/utils/releaseInfo.js +1 -1
  66. package/node/DateRangeCalendar/DateRangeCalendar.js +6 -2
  67. package/node/DateRangePicker/DateRangePicker.js +6 -2
  68. package/node/DateRangePicker/DateRangePickerToolbar.js +1 -0
  69. package/node/DesktopDateRangePicker/DesktopDateRangePicker.js +6 -2
  70. package/node/MobileDateRangePicker/MobileDateRangePicker.js +6 -2
  71. package/node/MultiInputDateRangeField/MultiInputDateRangeField.js +3 -0
  72. package/node/MultiInputDateTimeRangeField/MultiInputDateTimeRangeField.js +3 -0
  73. package/node/SingleInputDateRangeField/SingleInputDateRangeField.js +32 -4
  74. package/node/SingleInputDateTimeRangeField/SingleInputDateTimeRangeField.js +32 -4
  75. package/node/SingleInputTimeRangeField/SingleInputTimeRangeField.js +29 -4
  76. package/node/StaticDateRangePicker/StaticDateRangePicker.js +6 -2
  77. package/node/index.js +1 -1
  78. package/node/internals/hooks/useEnrichedRangePickerFieldProps.js +12 -3
  79. package/node/internals/hooks/useMultiInputRangeField/shared.js +16 -0
  80. package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateRangeField.js +5 -2
  81. package/node/internals/hooks/useMultiInputRangeField/useMultiInputDateTimeRangeField.js +5 -2
  82. package/node/internals/hooks/useMultiInputRangeField/useMultiInputTimeRangeField.js +5 -2
  83. package/node/internals/utils/releaseInfo.js +1 -1
  84. package/package.json +2 -2
  85. package/legacy/tests/describeRangeValidation/describeRangeValidation.js +0 -29
  86. package/legacy/tests/describeRangeValidation/describeRangeValidation.types.js +0 -1
  87. package/legacy/tests/describeRangeValidation/index.js +0 -1
  88. package/legacy/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -144
  89. package/legacy/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -291
  90. package/legacy/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -518
  91. package/modern/tests/describeRangeValidation/describeRangeValidation.js +0 -29
  92. package/modern/tests/describeRangeValidation/describeRangeValidation.types.js +0 -1
  93. package/modern/tests/describeRangeValidation/index.js +0 -1
  94. package/modern/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -145
  95. package/modern/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -285
  96. package/modern/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -520
  97. package/node/tests/describeRangeValidation/describeRangeValidation.js +0 -37
  98. package/node/tests/describeRangeValidation/describeRangeValidation.types.js +0 -5
  99. package/node/tests/describeRangeValidation/index.js +0 -12
  100. package/node/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -154
  101. package/node/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -294
  102. package/node/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -530
  103. package/tests/describeRangeValidation/describeRangeValidation.js +0 -29
  104. package/tests/describeRangeValidation/describeRangeValidation.types.js +0 -1
  105. package/tests/describeRangeValidation/index.js +0 -1
  106. package/tests/describeRangeValidation/testDayViewRangeValidation.js +0 -145
  107. package/tests/describeRangeValidation/testTextFieldKeyboardRangeValidation.js +0 -285
  108. package/tests/describeRangeValidation/testTextFieldRangeValidation.js +0 -520
@@ -1,530 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.testTextFieldRangeValidation = void 0;
8
- var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
9
- var React = _interopRequireWildcard(require("react"));
10
- var _chai = require("chai");
11
- var _sinon = require("sinon");
12
- var _utils = require("@mui/monorepo/test/utils");
13
- var _pickers = require("test/utils/pickers");
14
- var _jsxRuntime = require("react/jsx-runtime");
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
- const testInvalidStatus = (expectedAnswer, isSingleInput) => {
18
- const answers = isSingleInput ? [expectedAnswer[0] || expectedAnswer[1]] : expectedAnswer;
19
- const textBoxes = _utils.screen.getAllByRole('textbox');
20
- answers.forEach((answer, index) => {
21
- const textBox = textBoxes[index];
22
- (0, _chai.expect)(textBox).to.have.attribute('aria-invalid', answer ? 'true' : 'false');
23
- });
24
- };
25
- const dateParser = value => {
26
- return value.map(date => date === null ? date : _pickers.adapterToUse.date(new Date(...date)));
27
- };
28
- const testTextFieldRangeValidation = (ElementToTest, getOptions) => {
29
- const {
30
- componentFamily,
31
- render,
32
- isSingleInput,
33
- withDate,
34
- withTime
35
- } = getOptions();
36
- if (!['picker', 'field'].includes(componentFamily)) {
37
- return;
38
- }
39
- describe('text field:', () => {
40
- it('should accept single day range', () => {
41
- const onErrorMock = (0, _sinon.spy)();
42
- render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
43
- onError: onErrorMock,
44
- value: dateParser([[2018, 0, 1, 10, 15, 0], [2018, 0, 1, 10, 15, 0]])
45
- }));
46
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
47
- testInvalidStatus([false, false], isSingleInput);
48
- });
49
- it('should not accept end date prior to start state', () => {
50
- const onErrorMock = (0, _sinon.spy)();
51
- render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
52
- onError: onErrorMock,
53
- value: dateParser([[2018, 0, 2], [2018, 0, 1]])
54
- }));
55
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
56
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['invalidRange', 'invalidRange']);
57
- testInvalidStatus([true, true], isSingleInput);
58
- });
59
- it('should apply shouldDisableDate', function test() {
60
- if (!withDate) {
61
- return;
62
- }
63
- const onErrorMock = (0, _sinon.spy)();
64
- const {
65
- setProps
66
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
67
- onError: onErrorMock,
68
- value: dateParser([[2018, 2, 9], [2018, 2, 10]]),
69
- shouldDisableDate: date => _pickers.adapterToUse.isAfter(date, _pickers.adapterToUse.date(new Date(2018, 2, 10)))
70
- }));
71
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
72
- testInvalidStatus([false, false], isSingleInput);
73
- setProps({
74
- value: dateParser([[2018, 2, 9], [2018, 2, 13]])
75
- });
76
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
77
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'shouldDisableDate']);
78
- testInvalidStatus([false, true], isSingleInput);
79
- setProps({
80
- value: dateParser([[2018, 2, 12], [2018, 2, 13]])
81
- });
82
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
83
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['shouldDisableDate', 'shouldDisableDate']);
84
- testInvalidStatus([true, true], isSingleInput);
85
- setProps({
86
- value: dateParser([[2018, 2, 12], [2018, 2, 13]]),
87
- shouldDisableDate: date => _pickers.adapterToUse.isBefore(date, _pickers.adapterToUse.date(new Date(2018, 2, 13)))
88
- });
89
- (0, _chai.expect)(onErrorMock.callCount).to.equal(3);
90
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['shouldDisableDate', null]);
91
- testInvalidStatus([true, false], isSingleInput);
92
- });
93
- it('should apply shouldDisableDate specifically on end date', function test() {
94
- if (!withDate) {
95
- return;
96
- }
97
- const onErrorMock = (0, _sinon.spy)();
98
- const {
99
- setProps
100
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
101
- onError: onErrorMock,
102
- value: dateParser([[2018, 2, 9], [2018, 2, 10]]),
103
- shouldDisableDate: (date, position) => position === 'end' ? _pickers.adapterToUse.isAfter(date, _pickers.adapterToUse.date(new Date(2018, 2, 10))) : false
104
- }));
105
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
106
- testInvalidStatus([false, false], isSingleInput);
107
- setProps({
108
- value: dateParser([[2018, 2, 9], [2018, 2, 13]])
109
- });
110
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
111
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'shouldDisableDate']);
112
- testInvalidStatus([false, true], isSingleInput);
113
- setProps({
114
- value: dateParser([[2018, 2, 12], [2018, 2, 13]])
115
- });
116
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
117
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'shouldDisableDate']);
118
- testInvalidStatus([false, true], isSingleInput);
119
- setProps({
120
- value: dateParser([[2018, 2, 12], [2018, 2, 13]]),
121
- shouldDisableDate: (date, position) => position === 'end' ? _pickers.adapterToUse.isBefore(date, _pickers.adapterToUse.date(new Date(2018, 2, 13))) : false
122
- });
123
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
124
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
125
- testInvalidStatus([false, false], isSingleInput);
126
- });
127
- it('should apply shouldDisableDate specifically on start date', function test() {
128
- if (!withDate) {
129
- return;
130
- }
131
- const onErrorMock = (0, _sinon.spy)();
132
- const {
133
- setProps
134
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
135
- onError: onErrorMock,
136
- value: dateParser([[2018, 2, 9], [2018, 2, 10]]),
137
- shouldDisableDate: (date, position) => position === 'start' ? _pickers.adapterToUse.isAfter(date, _pickers.adapterToUse.date(new Date(2018, 2, 10))) : false
138
- }));
139
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
140
- testInvalidStatus([false, false], isSingleInput);
141
- setProps({
142
- value: dateParser([[2018, 2, 9], [2018, 2, 13]])
143
- });
144
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
145
- testInvalidStatus([false, false], isSingleInput);
146
- setProps({
147
- value: dateParser([[2018, 2, 12], [2018, 2, 13]])
148
- });
149
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
150
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['shouldDisableDate', null]);
151
- testInvalidStatus([true, false], isSingleInput);
152
- setProps({
153
- shouldDisableDate: (date, position) => position === 'start' ? _pickers.adapterToUse.isBefore(date, _pickers.adapterToUse.date(new Date(2018, 2, 13))) : false
154
- });
155
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
156
- testInvalidStatus([true, false], isSingleInput);
157
- });
158
- it('should apply disablePast', function test() {
159
- const onErrorMock = (0, _sinon.spy)();
160
- let now;
161
- function WithFakeTimer(props) {
162
- now = _pickers.adapterToUse.date(new Date());
163
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, (0, _extends2.default)({
164
- value: [now, now]
165
- }, props));
166
- }
167
- const {
168
- setProps
169
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(WithFakeTimer, {
170
- disablePast: true,
171
- onError: onErrorMock
172
- }));
173
- let past = null;
174
- if (withDate) {
175
- past = _pickers.adapterToUse.addDays(now, -1);
176
- } else if (_pickers.adapterToUse.isSameDay(_pickers.adapterToUse.addHours(now, -1), now)) {
177
- past = _pickers.adapterToUse.addHours(now, -1);
178
- }
179
- if (past === null) {
180
- return;
181
- }
182
- setProps({
183
- value: [past, now]
184
- });
185
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
186
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['disablePast', null]);
187
- testInvalidStatus([true, false], isSingleInput);
188
- setProps({
189
- value: [past, past]
190
- });
191
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
192
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['disablePast', 'disablePast']);
193
- testInvalidStatus([true, true], isSingleInput);
194
- });
195
- it('should apply disableFuture', function test() {
196
- const onErrorMock = (0, _sinon.spy)();
197
- let now;
198
- function WithFakeTimer(props) {
199
- now = _pickers.adapterToUse.date(new Date());
200
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, (0, _extends2.default)({
201
- value: [now, now]
202
- }, props));
203
- }
204
- const {
205
- setProps
206
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(WithFakeTimer, {
207
- disableFuture: true,
208
- onError: onErrorMock
209
- }));
210
- let future = null;
211
- if (withDate) {
212
- future = _pickers.adapterToUse.addDays(now, 1);
213
- } else if (_pickers.adapterToUse.isSameDay(_pickers.adapterToUse.addHours(now, 1), now)) {
214
- future = _pickers.adapterToUse.addHours(now, 1);
215
- }
216
- if (future === null) {
217
- return;
218
- }
219
- setProps({
220
- value: [now, future]
221
- });
222
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
223
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'disableFuture']);
224
- testInvalidStatus([false, true], isSingleInput);
225
- setProps({
226
- value: [future, future]
227
- });
228
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
229
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['disableFuture', 'disableFuture']);
230
- testInvalidStatus([true, true], isSingleInput);
231
- });
232
- it('should apply minDate', function test() {
233
- if (!withDate) {
234
- return;
235
- }
236
- const onErrorMock = (0, _sinon.spy)();
237
- const {
238
- setProps
239
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
240
- onError: onErrorMock,
241
- value: dateParser([[2018, 2, 9], [2018, 2, 10]]),
242
- minDate: _pickers.adapterToUse.date(new Date(2018, 2, 15))
243
- }));
244
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
245
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', 'minDate']);
246
- testInvalidStatus([true, true], isSingleInput);
247
- setProps({
248
- value: dateParser([[2018, 2, 9], [2018, 2, 15]])
249
- });
250
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
251
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', null]);
252
- testInvalidStatus([true, false], isSingleInput);
253
- setProps({
254
- value: dateParser([[2018, 2, 16], [2018, 2, 17]])
255
- });
256
- (0, _chai.expect)(onErrorMock.callCount).to.equal(3);
257
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
258
- testInvalidStatus([false, false], isSingleInput);
259
- });
260
- it('should apply minDate when only first field is filled', function test() {
261
- if (!withDate) {
262
- return;
263
- }
264
- const onErrorMock = (0, _sinon.spy)();
265
- const {
266
- setProps
267
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
268
- onError: onErrorMock,
269
- value: dateParser([[2018, 2, 9], null]),
270
- minDate: _pickers.adapterToUse.date(new Date(2018, 2, 11))
271
- }));
272
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
273
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', null]);
274
- testInvalidStatus([true, false], isSingleInput);
275
- setProps({
276
- value: dateParser([[2018, 2, 16], null])
277
- });
278
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
279
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
280
- testInvalidStatus([false, false], isSingleInput);
281
- });
282
- it('should apply minDate when only second field is filled', function test() {
283
- if (!withDate) {
284
- return;
285
- }
286
- const onErrorMock = (0, _sinon.spy)();
287
- const {
288
- setProps
289
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
290
- onError: onErrorMock,
291
- value: dateParser([null, [2018, 2, 9]]),
292
- minDate: _pickers.adapterToUse.date(new Date(2018, 2, 15))
293
- }));
294
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
295
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'minDate']);
296
- testInvalidStatus([false, true], isSingleInput);
297
- setProps({
298
- value: dateParser([null, [2018, 2, 16]])
299
- });
300
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
301
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
302
- testInvalidStatus([false, false], isSingleInput);
303
- });
304
- it('should apply maxDate', function test() {
305
- if (!withDate) {
306
- return;
307
- }
308
- const onErrorMock = (0, _sinon.spy)();
309
- const {
310
- setProps
311
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
312
- onError: onErrorMock,
313
- value: dateParser([[2018, 2, 9], [2018, 2, 10]]),
314
- maxDate: _pickers.adapterToUse.date(new Date(2018, 2, 15))
315
- }));
316
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
317
- testInvalidStatus([false, false], isSingleInput);
318
- setProps({
319
- value: dateParser([[2018, 2, 15], [2018, 2, 17]])
320
- });
321
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
322
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxDate']);
323
- testInvalidStatus([false, true], isSingleInput);
324
- setProps({
325
- value: dateParser([[2018, 2, 16], [2018, 2, 17]])
326
- });
327
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
328
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['maxDate', 'maxDate']);
329
- testInvalidStatus([true, true], isSingleInput);
330
- });
331
- it('should apply minTime', function test() {
332
- if (!withTime) {
333
- return;
334
- }
335
- const onErrorMock = (0, _sinon.spy)();
336
- const {
337
- setProps
338
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
339
- onError: onErrorMock,
340
- value: dateParser([[2018, 2, 10, 9, 0, 0], [2018, 2, 10, 10, 0, 0]]),
341
- minTime: _pickers.adapterToUse.date(new Date(2018, 2, 10, 12, 0))
342
- }));
343
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
344
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', 'minTime']);
345
- testInvalidStatus([true, true], isSingleInput);
346
- setProps({
347
- value: dateParser([[2018, 2, 10, 9, 0, 0], [2018, 2, 10, 12, 5, 0]])
348
- });
349
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
350
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', null]);
351
- testInvalidStatus([true, false], isSingleInput);
352
- setProps({
353
- value: dateParser([[2018, 2, 10, 12, 15, 0], [2018, 2, 10, 18, 0, 0]])
354
- });
355
- (0, _chai.expect)(onErrorMock.callCount).to.equal(3);
356
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
357
- testInvalidStatus([false, false], isSingleInput);
358
- });
359
- it('should ignore date when applying minTime', function test() {
360
- if (!withTime) {
361
- return;
362
- }
363
- const onErrorMock = (0, _sinon.spy)();
364
- const {
365
- setProps
366
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
367
- onError: onErrorMock,
368
- value: dateParser([[2018, 2, 5, 9, 0, 0], [2018, 2, 15, 10, 0, 0]]),
369
- minTime: _pickers.adapterToUse.date(new Date(2018, 2, 10, 12, 0))
370
- }));
371
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
372
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', 'minTime']);
373
- testInvalidStatus([true, true], isSingleInput);
374
- setProps({
375
- value: dateParser([[2018, 2, 5, 15, 0, 0], [2018, 2, 15, 16, 5, 0]])
376
- });
377
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
378
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
379
- testInvalidStatus([false, false], isSingleInput);
380
- });
381
- it('should apply minTime when only first field is filled', function test() {
382
- if (!withTime) {
383
- return;
384
- }
385
- const onErrorMock = (0, _sinon.spy)();
386
- const {
387
- setProps
388
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
389
- onError: onErrorMock,
390
- value: dateParser([[2018, 1, 1, 15], null]),
391
- minTime: _pickers.adapterToUse.date(new Date(2018, 1, 1, 12))
392
- }));
393
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
394
- testInvalidStatus([false, false], isSingleInput);
395
- setProps({
396
- value: dateParser([[2018, 1, 1, 5], null])
397
- });
398
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
399
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minTime', null]);
400
- testInvalidStatus([true, false], isSingleInput);
401
- });
402
- it('should apply minTime when only second field is filled', function test() {
403
- if (!withTime) {
404
- return;
405
- }
406
- const onErrorMock = (0, _sinon.spy)();
407
- const {
408
- setProps
409
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
410
- onError: onErrorMock,
411
- value: dateParser([null, [2018, 1, 1, 15]]),
412
- minTime: _pickers.adapterToUse.date(new Date(2018, 1, 1, 12))
413
- }));
414
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
415
- testInvalidStatus([false, false], isSingleInput);
416
- setProps({
417
- value: dateParser([null, [2018, 1, 1, 5]])
418
- });
419
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
420
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'minTime']);
421
- testInvalidStatus([false, true], isSingleInput);
422
- });
423
- it('should apply maxTime', function test() {
424
- if (!withTime) {
425
- return;
426
- }
427
- const onErrorMock = (0, _sinon.spy)();
428
- const {
429
- setProps
430
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
431
- onError: onErrorMock,
432
- value: dateParser([[2018, 2, 10, 9, 0, 0], [2018, 2, 10, 10, 0, 0]]),
433
- maxTime: _pickers.adapterToUse.date(new Date(2018, 2, 10, 12, 0))
434
- }));
435
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
436
- testInvalidStatus([false, false], isSingleInput);
437
- setProps({
438
- value: dateParser([[2018, 2, 10, 9, 0, 0], [2018, 2, 10, 12, 5, 0]])
439
- });
440
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
441
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxTime']);
442
- testInvalidStatus([false, true], isSingleInput);
443
- setProps({
444
- value: dateParser([[2018, 2, 10, 12, 15, 0], [2018, 2, 10, 18, 0, 0]])
445
- });
446
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
447
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['maxTime', 'maxTime']);
448
- testInvalidStatus([true, true], isSingleInput);
449
- });
450
- it('should ignore date when applying maxTime', function test() {
451
- if (!withTime) {
452
- return;
453
- }
454
- const onErrorMock = (0, _sinon.spy)();
455
- const {
456
- setProps
457
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
458
- onError: onErrorMock,
459
- value: dateParser([[2018, 2, 5, 9, 0, 0], [2018, 2, 15, 10, 0, 0]]),
460
- maxTime: _pickers.adapterToUse.date(new Date(2018, 2, 10, 12, 0))
461
- }));
462
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
463
- testInvalidStatus([false, false], isSingleInput);
464
- setProps({
465
- value: dateParser([[2018, 2, 5, 15, 0, 0], [2018, 2, 15, 16, 5, 0]])
466
- });
467
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
468
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['maxTime', 'maxTime']);
469
- testInvalidStatus([true, true], isSingleInput);
470
- });
471
- it('should apply maxDateTime', function test() {
472
- if (!withDate || !withTime) {
473
- // prop only available on DateTime pickers
474
- return;
475
- }
476
- const onErrorMock = (0, _sinon.spy)();
477
- const {
478
- setProps
479
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
480
- onError: onErrorMock,
481
- value: dateParser([[2018, 2, 1, 9, 0, 0], [2018, 2, 2, 12, 0, 0]]),
482
- maxDateTime: _pickers.adapterToUse.date(new Date(2018, 2, 2, 13, 0))
483
- }));
484
- (0, _chai.expect)(onErrorMock.callCount).to.equal(0);
485
- testInvalidStatus([false, false], isSingleInput);
486
- setProps({
487
- maxDateTime: _pickers.adapterToUse.date(new Date(2018, 2, 2, 8, 0))
488
- });
489
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
490
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, 'maxTime']);
491
- testInvalidStatus([false, true], isSingleInput);
492
- setProps({
493
- maxDateTime: _pickers.adapterToUse.date(new Date(2018, 2, 1, 5, 0))
494
- });
495
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
496
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['maxTime', 'maxDate']);
497
- testInvalidStatus([true, true], isSingleInput);
498
- });
499
- it('should apply minDateTime', function test() {
500
- if (!withDate || !withTime) {
501
- // prop only available on DateTime pickers
502
- return;
503
- }
504
- const onErrorMock = (0, _sinon.spy)();
505
- const {
506
- setProps
507
- } = render( /*#__PURE__*/(0, _jsxRuntime.jsx)(ElementToTest, {
508
- onError: onErrorMock,
509
- value: dateParser([[2018, 2, 1, 9, 0, 0], [2018, 2, 2, 12, 0, 0]]),
510
- minDateTime: _pickers.adapterToUse.date(new Date(2018, 2, 2, 13, 0))
511
- }));
512
- (0, _chai.expect)(onErrorMock.callCount).to.equal(1);
513
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', 'minTime']);
514
- testInvalidStatus([true, true], isSingleInput);
515
- setProps({
516
- minDateTime: _pickers.adapterToUse.date(new Date(2018, 2, 2, 8, 0))
517
- });
518
- (0, _chai.expect)(onErrorMock.callCount).to.equal(2);
519
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal(['minDate', null]);
520
- testInvalidStatus([true, false], isSingleInput);
521
- setProps({
522
- minDateTime: _pickers.adapterToUse.date(new Date(2018, 2, 1, 5, 0))
523
- });
524
- (0, _chai.expect)(onErrorMock.callCount).to.equal(3);
525
- (0, _chai.expect)(onErrorMock.lastCall.args[0]).to.deep.equal([null, null]);
526
- testInvalidStatus([false, false], isSingleInput);
527
- });
528
- });
529
- };
530
- exports.testTextFieldRangeValidation = testTextFieldRangeValidation;
@@ -1,29 +0,0 @@
1
- import _extends from "@babel/runtime/helpers/esm/extends";
2
- /* eslint-env mocha */
3
-
4
- import createDescribe from '@mui/monorepo/test/utils/createDescribe';
5
- import { testDayViewRangeValidation } from './testDayViewRangeValidation';
6
- import { testTextFieldRangeValidation } from './testTextFieldRangeValidation';
7
- import { testTextFieldKeyboardRangeValidation } from './testTextFieldKeyboardRangeValidation';
8
- const TEST_SUITES = [testDayViewRangeValidation, testTextFieldRangeValidation, testTextFieldKeyboardRangeValidation];
9
- function innerDescribeRangeValidation(ElementToTest, getOptions) {
10
- const {
11
- after: runAfterHook = () => {},
12
- views
13
- } = getOptions();
14
- after(runAfterHook);
15
- function getTestOptions() {
16
- return _extends({}, getOptions(), {
17
- withDate: views.includes('year') || views.includes('month') || views.includes('day'),
18
- withTime: views.includes('hours') || views.includes('minutes') || views.includes('seconds')
19
- });
20
- }
21
- TEST_SUITES.forEach(testSuite => {
22
- testSuite(ElementToTest, getTestOptions);
23
- });
24
- }
25
-
26
- /**
27
- * Tests various aspects of the range picker validation.
28
- */
29
- export const describeRangeValidation = createDescribe('Range pickers validation API', innerDescribeRangeValidation);
@@ -1 +0,0 @@
1
- export { describeRangeValidation } from './describeRangeValidation';