@@ -6,8 +6,12 @@ import { act } from '@mui/internal-test-utils/createRenderer';
6
6
import { describeSkipIf , testSkipIf } from 'test/utils/skipIf' ;
7
7
import { DescribeRangeValidationTestSuite } from './describeRangeValidation.types' ;
8
8
9
- const testInvalidStatus = ( expectedAnswer : boolean [ ] , isSingleInput ?: boolean ) => {
10
- const answers = isSingleInput ? [ expectedAnswer [ 0 ] || expectedAnswer [ 1 ] ] : expectedAnswer ;
9
+ const testInvalidStatus = (
10
+ expectedAnswer : boolean [ ] ,
11
+ fieldType : 'single-input' | 'multi-input' | 'no-input' ,
12
+ ) => {
13
+ const answers =
14
+ fieldType === 'multi-input' ? expectedAnswer : [ expectedAnswer [ 0 ] || expectedAnswer [ 1 ] ] ;
11
15
12
16
const fieldInputRoots = getAllFieldInputRoot ( ) ;
13
17
answers . forEach ( ( answer , index ) => {
@@ -21,7 +25,7 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
21
25
ElementToTest ,
22
26
getOptions ,
23
27
) => {
24
- const { componentFamily, render, isSingleInput , withDate, withTime, setValue } = getOptions ( ) ;
28
+ const { componentFamily, render, fieldType , withDate, withTime, setValue } = getOptions ( ) ;
25
29
26
30
describeSkipIf ( componentFamily !== 'field' || ! setValue ) ( 'text field keyboard:' , ( ) => {
27
31
// eslint-disable-next-line @typescript-eslint/no-shadow
@@ -42,7 +46,7 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
42
46
} ) ;
43
47
expect ( onErrorMock . callCount ) . to . equal ( 1 ) ;
44
48
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'invalidRange' , 'invalidRange' ] ) ;
45
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
49
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
46
50
} ) ;
47
51
48
52
testSkipIf ( ! withDate ) ( 'should apply shouldDisableDate' , ( ) => {
@@ -62,15 +66,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
62
66
} ) ;
63
67
64
68
expect ( onErrorMock . callCount ) . to . equal ( 0 ) ;
65
- testInvalidStatus ( [ false , false ] , isSingleInput ) ;
69
+ testInvalidStatus ( [ false , false ] , fieldType ) ;
66
70
67
71
act ( ( ) => {
68
72
setValue ( adapterToUse . date ( '2018-03-13' ) , { setEndDate : true } ) ;
69
73
} ) ;
70
74
71
75
expect ( onErrorMock . callCount ) . to . equal ( 1 ) ;
72
76
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'shouldDisableDate' ] ) ;
73
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
77
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
74
78
75
79
act ( ( ) => {
76
80
setValue ( adapterToUse . date ( '2018-03-12' ) ) ;
@@ -81,15 +85,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
81
85
'shouldDisableDate' ,
82
86
'shouldDisableDate' ,
83
87
] ) ;
84
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
88
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
85
89
86
90
setProps ( {
87
91
shouldDisableDate : ( date ) => adapterToUse . isBefore ( date , adapterToUse . date ( '2018-03-13' ) ) ,
88
92
} ) ;
89
93
90
94
expect ( onErrorMock . callCount ) . to . equal ( 3 ) ;
91
95
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'shouldDisableDate' , null ] ) ;
92
- testInvalidStatus ( [ true , false ] , isSingleInput ) ;
96
+ testInvalidStatus ( [ true , false ] , fieldType ) ;
93
97
} ) ;
94
98
95
99
it ( 'should apply disablePast' , ( ) => {
@@ -114,22 +118,22 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
114
118
115
119
expect ( onErrorMock . callCount ) . to . equal ( 1 ) ;
116
120
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'disablePast' , null ] ) ;
117
- testInvalidStatus ( [ true , false ] , isSingleInput ) ;
121
+ testInvalidStatus ( [ true , false ] , fieldType ) ;
118
122
119
123
act ( ( ) => {
120
124
setValue ( past , { setEndDate : true } ) ;
121
125
} ) ;
122
126
123
127
expect ( onErrorMock . callCount ) . to . equal ( 2 ) ;
124
128
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'disablePast' , 'disablePast' ] ) ;
125
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
129
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
126
130
127
131
act ( ( ) => {
128
132
setValue ( now ) ;
129
133
} ) ;
130
134
expect ( onErrorMock . callCount ) . to . equal ( 3 ) ;
131
135
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'disablePast' ] ) ;
132
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
136
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
133
137
} ) ;
134
138
135
139
it ( 'should apply disableFuture' , ( ) => {
@@ -155,23 +159,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
155
159
156
160
expect ( onErrorMock . callCount ) . to . equal ( 1 ) ;
157
161
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'disableFuture' ] ) ;
158
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
162
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
159
163
160
164
act ( ( ) => {
161
165
setValue ( future ) ;
162
166
} ) ;
163
167
164
168
expect ( onErrorMock . callCount ) . to . equal ( 2 ) ;
165
169
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'disableFuture' , 'disableFuture' ] ) ;
166
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
170
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
167
171
168
172
act ( ( ) => {
169
173
setValue ( now ) ;
170
174
} ) ;
171
175
172
176
expect ( onErrorMock . callCount ) . to . equal ( 3 ) ;
173
177
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'disableFuture' ] ) ;
174
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
178
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
175
179
} ) ;
176
180
177
181
testSkipIf ( ! withDate ) ( 'should apply minDate' , ( ) => {
@@ -188,23 +192,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
188
192
189
193
expect ( onErrorMock . callCount ) . to . equal ( 2 ) ;
190
194
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'minDate' , 'minDate' ] ) ;
191
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
195
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
192
196
193
197
act ( ( ) => {
194
198
setValue ( adapterToUse . date ( '2018-03-15' ) ) ;
195
199
} ) ;
196
200
197
201
expect ( onErrorMock . callCount ) . to . equal ( 3 ) ;
198
202
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'minDate' ] ) ;
199
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
203
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
200
204
201
205
act ( ( ) => {
202
206
setValue ( adapterToUse . date ( '2018-03-16' ) , { setEndDate : true } ) ;
203
207
} ) ;
204
208
205
209
expect ( onErrorMock . callCount ) . to . equal ( 4 ) ;
206
210
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , null ] ) ;
207
- testInvalidStatus ( [ false , false ] , isSingleInput ) ;
211
+ testInvalidStatus ( [ false , false ] , fieldType ) ;
208
212
} ) ;
209
213
210
214
testSkipIf ( ! withDate ) ( 'should apply maxDate' , ( ) => {
@@ -221,15 +225,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
221
225
222
226
expect ( onErrorMock . callCount ) . to . equal ( 1 ) ;
223
227
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'maxDate' ] ) ;
224
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
228
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
225
229
226
230
act ( ( ) => {
227
231
setValue ( adapterToUse . date ( '2018-03-16' ) ) ;
228
232
} ) ;
229
233
230
234
expect ( onErrorMock . callCount ) . to . equal ( 2 ) ;
231
235
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'maxDate' , 'maxDate' ] ) ;
232
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
236
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
233
237
} ) ;
234
238
235
239
testSkipIf ( ! withTime ) ( 'should apply minTime' , ( ) => {
@@ -249,23 +253,23 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
249
253
250
254
expect ( onErrorMock . callCount ) . to . equal ( 2 ) ;
251
255
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'minTime' , 'minTime' ] ) ;
252
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
256
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
253
257
254
258
act ( ( ) => {
255
259
setValue ( adapterToUse . date ( '2018-03-10T12:10:00' ) , { setEndDate : true } ) ;
256
260
} ) ;
257
261
258
262
expect ( onErrorMock . callCount ) . to . equal ( 3 ) ;
259
263
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'minTime' , null ] ) ;
260
- testInvalidStatus ( [ true , false ] , isSingleInput ) ;
264
+ testInvalidStatus ( [ true , false ] , fieldType ) ;
261
265
262
266
act ( ( ) => {
263
267
setValue ( adapterToUse . date ( '2018-03-10T12:05:00' ) ) ;
264
268
} ) ;
265
269
266
270
expect ( onErrorMock . callCount ) . to . equal ( 4 ) ;
267
271
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , null ] ) ;
268
- testInvalidStatus ( [ false , false ] , isSingleInput ) ;
272
+ testInvalidStatus ( [ false , false ] , fieldType ) ;
269
273
} ) ;
270
274
271
275
testSkipIf ( ! withTime ) ( 'should apply maxTime' , ( ) => {
@@ -285,15 +289,15 @@ export const testTextFieldKeyboardRangeValidation: DescribeRangeValidationTestSu
285
289
286
290
expect ( onErrorMock . callCount ) . to . equal ( 1 ) ;
287
291
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ null , 'maxTime' ] ) ;
288
- testInvalidStatus ( [ false , true ] , isSingleInput ) ;
292
+ testInvalidStatus ( [ false , true ] , fieldType ) ;
289
293
290
294
act ( ( ) => {
291
295
setValue ( adapterToUse . date ( '2018-03-10T12:05:00' ) ) ;
292
296
} ) ;
293
297
294
298
expect ( onErrorMock . callCount ) . to . equal ( 2 ) ;
295
299
expect ( onErrorMock . lastCall . args [ 0 ] ) . to . deep . equal ( [ 'maxTime' , 'maxTime' ] ) ;
296
- testInvalidStatus ( [ true , true ] , isSingleInput ) ;
300
+ testInvalidStatus ( [ true , true ] , fieldType ) ;
297
301
} ) ;
298
302
} ) ;
299
303
} ;
0 commit comments