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' ;
@@ -995,6 +995,27 @@ describe('NewPicker.Range', () => {
995995 expect ( onChange ) . toHaveBeenCalledWith ( expect . anything ( ) , [ '20200903' , '20200905' ] ) ;
996996 } ) ;
997997
998+ it ( 'blocks paste while mouse is down' , ( ) => {
999+ const { container } = render ( < Demo /> ) ;
1000+
1001+ const startInput = container . querySelectorAll < HTMLInputElement > ( 'input' ) [ 0 ] ;
1002+
1003+ // Simulate focus gained by mousedown, then paste before mouse up.
1004+ fireEvent . mouseDown ( startInput ) ;
1005+ fireEvent . focus ( startInput ) ;
1006+
1007+ const pasteEvent = createEvent . paste ( startInput , {
1008+ clipboardData : {
1009+ getData : ( ) => '20200903' ,
1010+ } ,
1011+ } ) ;
1012+ pasteEvent . preventDefault = jest . fn ( ) ;
1013+ fireEvent ( startInput , pasteEvent ) ;
1014+
1015+ // Guard in Input should prevent default while mouse is down
1016+ expect ( pasteEvent . preventDefault ) . toHaveBeenCalled ( ) ;
1017+ } ) ;
1018+
9981019 it ( 'click to change selection cell' , ( ) => {
9991020 const { container } = render ( < Demo /> ) ;
10001021
@@ -1010,6 +1031,38 @@ describe('NewPicker.Range', () => {
10101031 expect ( startInput . selectionEnd ) . toEqual ( 6 ) ;
10111032 } ) ;
10121033
1034+ it ( 'blocks key input while mouse is down' , ( ) => {
1035+ const { container } = render ( < Demo /> ) ;
1036+
1037+ const startInput = container . querySelectorAll < HTMLInputElement > ( 'input' ) [ 0 ] ;
1038+
1039+ // Simulate focus gained by mousedown, then key input before mouse up.
1040+ fireEvent . mouseDown ( startInput ) ;
1041+ fireEvent . focus ( startInput ) ;
1042+
1043+ const keyDownEvent = createEvent . keyDown ( startInput , {
1044+ key : '1' ,
1045+ } ) ;
1046+ keyDownEvent . preventDefault = jest . fn ( ) ;
1047+ fireEvent ( startInput , keyDownEvent ) ;
1048+
1049+ // Guard in Input should prevent default while mouse is down
1050+ expect ( keyDownEvent . preventDefault ) . toHaveBeenCalled ( ) ;
1051+ } ) ;
1052+
1053+ it ( 'focus by mousedown defers selection sync to mouseUp' , ( ) => {
1054+ const { container } = render ( < Demo /> ) ;
1055+
1056+ const startInput = container . querySelectorAll < HTMLInputElement > ( 'input' ) [ 0 ] ;
1057+
1058+ fireEvent . mouseDown ( startInput ) ;
1059+ fireEvent . focus ( startInput ) ;
1060+
1061+ fireEvent . mouseUp ( startInput ) ;
1062+ expect ( startInput . selectionStart ) . toBeDefined ( ) ;
1063+ expect ( startInput . selectionEnd ) . toBeDefined ( ) ;
1064+ } ) ;
1065+
10131066 it ( 'blur to reset back text' , async ( ) => {
10141067 const { container } = render ( < Demo /> ) ;
10151068
0 commit comments