@@ -2,13 +2,13 @@ import React from 'react';
22import MockDate from 'mockdate' ;
33import { act } from 'react-dom/test-utils' ;
44import KeyCode from 'rc-util/lib/KeyCode' ;
5+ import type { Wrapper } from './util/commonUtil' ;
56import {
67 mount ,
78 getMoment ,
89 isSame ,
910 MomentPicker ,
1011 MomentPickerPanel ,
11- Wrapper ,
1212 MomentRangePicker ,
1313} from './util/commonUtil' ;
1414
@@ -396,10 +396,7 @@ describe('Picker.Keyboard', () => {
396396 jest . runAllTimers ( ) ;
397397 } ) ;
398398 expect (
399- wrapper
400- . find ( '.rc-picker-input' )
401- . last ( )
402- . hasClass ( 'rc-picker-input-active' ) ,
399+ wrapper . find ( '.rc-picker-input' ) . last ( ) . hasClass ( 'rc-picker-input-active' ) ,
403400 ) . toBeTruthy ( ) ;
404401 onCalendarChange . mockReset ( ) ;
405402
@@ -436,12 +433,7 @@ describe('Picker.Keyboard', () => {
436433 . first ( )
437434 . simulate ( 'change' , { target : { value : '2000-01-01' } } ) ;
438435 wrapper . keyDown ( KeyCode . ESC ) ;
439- expect (
440- wrapper
441- . find ( 'input' )
442- . first ( )
443- . props ( ) . value ,
444- ) . toEqual ( '' ) ;
436+ expect ( wrapper . find ( 'input' ) . first ( ) . props ( ) . value ) . toEqual ( '' ) ;
445437 } ) ;
446438
447439 it ( 'move based on current date on first keyboard event' , ( ) => {
@@ -523,15 +515,56 @@ describe('Picker.Keyboard', () => {
523515
524516 wrapper . find ( '.rc-picker-panel' ) . simulate ( 'focus' ) ;
525517
526- // 9-10 is disabled
518+ // 9-02、9-04、9-10 is disabled
519+ wrapper . keyDown ( KeyCode . LEFT ) ;
520+ wrapper . keyDown ( KeyCode . RIGHT ) ;
527521 wrapper . keyDown ( KeyCode . DOWN ) ;
528- expect ( isSame ( onSelect . mock . calls [ 0 ] [ 0 ] , '1990-09-10' ) ) . toBeTruthy ( ) ;
529- expect ( onChange ) . not . toHaveBeenCalled ( ) ;
522+ expect ( onSelect ) . not . toHaveBeenCalled ( ) ;
530523
531- // 9-17 is enabled
524+ // 7-27、8-27 is enabled
525+ wrapper . keyDown ( KeyCode . UP ) ;
526+ expect ( isSame ( onSelect . mock . calls [ 0 ] [ 0 ] , '1990-08-27' ) ) . toBeTruthy ( ) ;
527+ onSelect . mockReset ( ) ;
528+ wrapper . keyDown ( KeyCode . PAGE_UP ) ;
529+ expect ( isSame ( onSelect . mock . calls [ 0 ] [ 0 ] , '1990-07-27' ) ) . toBeTruthy ( ) ;
530+ onSelect . mockReset ( ) ;
531+ wrapper . keyDown ( KeyCode . PAGE_DOWN ) ;
532+ expect ( isSame ( onSelect . mock . calls [ 0 ] [ 0 ] , '1990-08-27' ) ) . toBeTruthy ( ) ;
533+ } ) ;
534+
535+ it ( 'month panel' , ( ) => {
536+ const onChange = jest . fn ( ) ;
537+ const onSelect = jest . fn ( ) ;
538+ const now = new Date ( ) ;
539+ const wrapper = mount (
540+ < MomentPickerPanel
541+ picker = "month"
542+ onSelect = { onSelect }
543+ onChange = { onChange }
544+ disabledDate = { date => date . month ( ) < now . getMonth ( ) }
545+ /> ,
546+ ) ;
547+
548+ wrapper . find ( '.rc-picker-panel' ) . simulate ( 'focus' ) ;
549+
550+ // PAGE_UP and PAGE_DOWN do not trigger the select
551+ wrapper . keyDown ( KeyCode . PAGE_UP ) ;
552+ wrapper . keyDown ( KeyCode . PAGE_DOWN ) ;
553+ expect ( onSelect ) . not . toHaveBeenCalled ( ) ;
554+
555+ // The disabled date is before August
556+ wrapper . keyDown ( KeyCode . LEFT ) ;
557+ wrapper . keyDown ( KeyCode . UP ) ;
558+ expect ( onSelect ) . not . toHaveBeenCalled ( ) ;
559+
560+ // August and subsequent dates are enable
561+ wrapper . keyDown ( KeyCode . RIGHT ) ;
562+ expect ( isSame ( onSelect . mock . calls [ 0 ] [ 0 ] , '1990-10-03' ) ) . toBeTruthy ( ) ;
563+ onSelect . mockReset ( ) ;
564+ wrapper . keyDown ( KeyCode . LEFT ) ;
565+ onSelect . mockReset ( ) ;
532566 wrapper . keyDown ( KeyCode . DOWN ) ;
533- expect ( isSame ( onSelect . mock . calls [ 1 ] [ 0 ] , '1990-09-17' ) ) . toBeTruthy ( ) ;
534- expect ( isSame ( onChange . mock . calls [ 0 ] [ 0 ] , '1990-09-17' ) ) . toBeTruthy ( ) ;
567+ expect ( isSame ( onSelect . mock . calls [ 0 ] [ 0 ] , '1990-12-03' ) ) . toBeTruthy ( ) ;
535568 } ) ;
536569 } ) ;
537570} ) ;
0 commit comments