@@ -248,22 +248,60 @@ describe('TimePicker', () => {
248248 expect ( clock2 ) . toHaveLength ( 1 ) ;
249249 } ) ;
250250
251- it ( 'opens Clock component when focusing on an input inside' , ( ) => {
252- const component = mount (
253- < TimePicker /> ,
254- ) ;
251+ describe ( 'handles opening Clock component when focusing on an input inside properly' , ( ) => {
252+ it ( 'opens Clock component when focusing on an input inside by default' , ( ) => {
253+ const component = mount (
254+ < TimePicker /> ,
255+ ) ;
255256
256- const clock = component . find ( 'Clock' ) ;
257- const input = component . find ( 'input[name^="hour"]' ) ;
257+ const clock = component . find ( 'Clock' ) ;
258+ const input = component . find ( 'input[name^="hour"]' ) ;
258259
259- expect ( clock ) . toHaveLength ( 0 ) ;
260+ expect ( clock ) . toHaveLength ( 0 ) ;
260261
261- input . simulate ( 'focus' ) ;
262- component . update ( ) ;
262+ input . simulate ( 'focus' ) ;
263+ component . update ( ) ;
263264
264- const clock2 = component . find ( 'Clock' ) ;
265+ const clock2 = component . find ( 'Clock' ) ;
265266
266- expect ( clock2 ) . toHaveLength ( 1 ) ;
267+ expect ( clock2 ) . toHaveLength ( 1 ) ;
268+ } ) ;
269+
270+ it ( 'opens Clock component when focusing on an input inside given openClockOnFocus = true' , ( ) => {
271+ const component = mount (
272+ < TimePicker openClockOnFocus /> ,
273+ ) ;
274+
275+ const clock = component . find ( 'Clock' ) ;
276+ const input = component . find ( 'input[name^="hour"]' ) ;
277+
278+ expect ( clock ) . toHaveLength ( 0 ) ;
279+
280+ input . simulate ( 'focus' ) ;
281+ component . update ( ) ;
282+
283+ const clock2 = component . find ( 'Clock' ) ;
284+
285+ expect ( clock2 ) . toHaveLength ( 1 ) ;
286+ } ) ;
287+
288+ it ( 'does not open Clock component when focusing on an input inside given openClockOnFocus = false' , ( ) => {
289+ const component = mount (
290+ < TimePicker openClockOnFocus = { false } /> ,
291+ ) ;
292+
293+ const clock = component . find ( 'Clock' ) ;
294+ const input = component . find ( 'input[name^="hour"]' ) ;
295+
296+ expect ( clock ) . toHaveLength ( 0 ) ;
297+
298+ input . simulate ( 'focus' ) ;
299+ component . update ( ) ;
300+
301+ const clock2 = component . find ( 'Clock' ) ;
302+
303+ expect ( clock2 ) . toHaveLength ( 0 ) ;
304+ } ) ;
267305 } ) ;
268306
269307 it ( 'closes Clock component when clicked outside' , ( ) => {
0 commit comments