@@ -151,4 +151,107 @@ describe('<MobileDateTimeRangePicker /> - Describes', () => {
151
151
return newValue ;
152
152
} ,
153
153
} ) ) ;
154
+
155
+ describeValue < PickerRangeValue , 'picker' > ( MobileDateTimeRangePicker , ( ) => ( {
156
+ render,
157
+ componentFamily : 'picker' ,
158
+ type : 'date-time-range' ,
159
+ variant : 'mobile' ,
160
+ initialFocus : 'start' ,
161
+ clock,
162
+ values : [
163
+ // initial start and end dates
164
+ [ adapterToUse . date ( '2018-01-01T11:30:00' ) , adapterToUse . date ( '2018-01-04T11:45:00' ) ] ,
165
+ // start and end dates after `setNewValue`
166
+ [ adapterToUse . date ( '2018-01-02T12:35:00' ) , adapterToUse . date ( '2018-01-05T12:50:00' ) ] ,
167
+ ] ,
168
+ emptyValue : [ null , null ] ,
169
+ assertRenderedValue : ( expectedValues : any [ ] ) => {
170
+ const hasMeridiem = adapterToUse . is12HourCycleInCurrentLocale ( ) ;
171
+ const expectedPlaceholder = hasMeridiem ? 'MM/DD/YYYY hh:mm aa' : 'MM/DD/YYYY hh:mm' ;
172
+
173
+ const startSectionsContainer = getFieldSectionsContainer ( 0 ) ;
174
+ const expectedStartValueStr = expectedValues [ 0 ]
175
+ ? adapterToUse . format (
176
+ expectedValues [ 0 ] ,
177
+ hasMeridiem ? 'keyboardDateTime12h' : 'keyboardDateTime24h' ,
178
+ )
179
+ : expectedPlaceholder ;
180
+ expectFieldValueV7 ( startSectionsContainer , expectedStartValueStr ) ;
181
+
182
+ const endSectionsContainer = getFieldSectionsContainer ( 1 ) ;
183
+ const expectedEndValueStr = expectedValues [ 1 ]
184
+ ? adapterToUse . format (
185
+ expectedValues [ 1 ] ,
186
+ hasMeridiem ? 'keyboardDateTime12h' : 'keyboardDateTime24h' ,
187
+ )
188
+ : expectedPlaceholder ;
189
+ expectFieldValueV7 ( endSectionsContainer , expectedEndValueStr ) ;
190
+ } ,
191
+ setNewValue : (
192
+ value ,
193
+ { isOpened, applySameValue, setEndDate = false , selectSection, pressKey } ,
194
+ ) => {
195
+ let newValue : PickerNonNullableRangeValue ;
196
+ if ( applySameValue ) {
197
+ newValue = value ;
198
+ } else if ( setEndDate ) {
199
+ newValue = [
200
+ value [ 0 ] ,
201
+ adapterToUse . addMinutes ( adapterToUse . addHours ( adapterToUse . addDays ( value [ 1 ] , 1 ) , 1 ) , 5 ) ,
202
+ ] ;
203
+ } else {
204
+ newValue = [
205
+ adapterToUse . addMinutes ( adapterToUse . addHours ( adapterToUse . addDays ( value [ 0 ] , 1 ) , 1 ) , 5 ) ,
206
+ value [ 1 ] ,
207
+ ] ;
208
+ }
209
+ if ( isOpened ) {
210
+ fireEvent . click (
211
+ screen . getByRole ( 'gridcell' , {
212
+ name : adapterToUse . getDate ( newValue [ setEndDate ? 1 : 0 ] ) . toString ( ) ,
213
+ } ) ,
214
+ ) ;
215
+ const hasMeridiem = adapterToUse . is12HourCycleInCurrentLocale ( ) ;
216
+ const hours = adapterToUse . format (
217
+ newValue [ setEndDate ? 1 : 0 ] ,
218
+ hasMeridiem ? 'hours12h' : 'hours24h' ,
219
+ ) ;
220
+ const hoursNumber = adapterToUse . getHours ( newValue [ setEndDate ? 1 : 0 ] ) ;
221
+ fireEvent . click ( screen . getByRole ( 'option' , { name : `${ parseInt ( hours , 10 ) } hours` } ) ) ;
222
+ fireEvent . click (
223
+ screen . getByRole ( 'option' , {
224
+ name : `${ adapterToUse . getMinutes ( newValue [ setEndDate ? 1 : 0 ] ) } minutes` ,
225
+ } ) ,
226
+ ) ;
227
+ if ( hasMeridiem ) {
228
+ // meridiem is an extra view on `DesktopDateTimeRangePicker`
229
+ // we need to click it to finish selection
230
+ fireEvent . click ( screen . getByRole ( 'option' , { name : hoursNumber >= 12 ? 'PM' : 'AM' } ) ) ;
231
+ }
232
+ } else {
233
+ selectSection ( 'day' ) ;
234
+ pressKey ( undefined , 'ArrowUp' ) ;
235
+
236
+ selectSection ( 'hours' ) ;
237
+ pressKey ( undefined , 'ArrowUp' ) ;
238
+
239
+ selectSection ( 'minutes' ) ;
240
+ pressKey ( undefined , 'PageUp' ) ; // increment by 5 minutes
241
+
242
+ const hasMeridiem = adapterToUse . is12HourCycleInCurrentLocale ( ) ;
243
+ if ( hasMeridiem ) {
244
+ selectSection ( 'meridiem' ) ;
245
+ const previousHours = adapterToUse . getHours ( value [ setEndDate ? 1 : 0 ] ) ;
246
+ const newHours = adapterToUse . getHours ( newValue [ setEndDate ? 1 : 0 ] ) ;
247
+ // update meridiem section if it changed
248
+ if ( ( previousHours < 12 && newHours >= 12 ) || ( previousHours >= 12 && newHours < 12 ) ) {
249
+ pressKey ( undefined , 'ArrowUp' ) ;
250
+ }
251
+ }
252
+ }
253
+
254
+ return newValue ;
255
+ } ,
256
+ } ) ) ;
154
257
} ) ;
0 commit comments