11// In theory, all RangePicker test cases should be paired with SinglePicker
2- import { act , fireEvent , render } from '@testing-library/react' ;
2+ import { act , createEvent , fireEvent , render } from '@testing-library/react' ;
33import dayjs , { type Dayjs } from 'dayjs' ;
44import 'dayjs/locale/ar' ;
55import { spyElementPrototype } from '@rc-component/util/lib/test/domHook' ;
@@ -996,32 +996,24 @@ describe('NewPicker.Range', () => {
996996 } ) ;
997997
998998 it ( 'blocks paste while mouse is down' , ( ) => {
999- const onChange = jest . fn ( ) ;
1000- const { container } = render ( < Demo onChange = { onChange } /> ) ;
999+ const { container } = render ( < Demo /> ) ;
10011000
10021001 const startInput = container . querySelectorAll < HTMLInputElement > ( 'input' ) [ 0 ] ;
10031002
10041003 // Simulate focus gained by mousedown, then paste before mouse up.
10051004 fireEvent . mouseDown ( startInput ) ;
10061005 fireEvent . focus ( startInput ) ;
10071006
1008- fireEvent . paste ( startInput , {
1007+ const pasteEvent = createEvent . paste ( startInput , {
10091008 clipboardData : {
10101009 getData : ( ) => '20200903' ,
10111010 } ,
10121011 } ) ;
1012+ pasteEvent . preventDefault = jest . fn ( ) ;
1013+ fireEvent ( startInput , pasteEvent ) ;
10131014
1014- // Guard in Input should prevent paste from taking effect
1015- expect ( onChange ) . not . toHaveBeenCalled ( ) ;
1016-
1017- // After mouse up, normal paste works again
1018- fireEvent . mouseUp ( startInput ) ;
1019- fireEvent . paste ( startInput , {
1020- clipboardData : {
1021- getData : ( ) => '20200903' ,
1022- } ,
1023- } ) ;
1024- expect ( onChange ) . toHaveBeenCalled ( ) ;
1015+ // Guard in Input should prevent default while mouse is down
1016+ expect ( pasteEvent . preventDefault ) . toHaveBeenCalled ( ) ;
10251017 } ) ;
10261018
10271019 it ( 'click to change selection cell' , ( ) => {
@@ -1048,19 +1040,14 @@ describe('NewPicker.Range', () => {
10481040 fireEvent . mouseDown ( startInput ) ;
10491041 fireEvent . focus ( startInput ) ;
10501042
1051- fireEvent . keyDown ( startInput , {
1043+ const keyDownEvent = createEvent . keyDown ( startInput , {
10521044 key : '1' ,
10531045 } ) ;
1046+ keyDownEvent . preventDefault = jest . fn ( ) ;
1047+ fireEvent ( startInput , keyDownEvent ) ;
10541048
1055- // Guard in Input should prevent any value change before mouse up
1056- expect ( startInput ) . toHaveValue ( 'YYYYMMDD' ) ;
1057-
1058- // After mouse up, key input should be allowed and update value
1059- fireEvent . mouseUp ( startInput ) ;
1060- fireEvent . keyDown ( startInput , {
1061- key : '1' ,
1062- } ) ;
1063- expect ( startInput ) . not . toHaveValue ( 'YYYYMMDD' ) ;
1049+ // Guard in Input should prevent default while mouse is down
1050+ expect ( keyDownEvent . preventDefault ) . toHaveBeenCalled ( ) ;
10641051 } ) ;
10651052
10661053 it ( 'focus by mousedown defers selection sync to mouseUp' , ( ) => {
0 commit comments