1+ import { KeyCode } from '@rc-component/util' ;
12import React from 'react' ;
2- import KeyCode from '@rc-component/util/lib/KeyCode' ;
3- import { render , fireEvent } from './util/wrapper' ;
43import InputNumber from '../src' ;
4+ import { fireEvent , render } from './util/wrapper' ;
55
66describe ( 'InputNumber.Cursor' , ( ) => {
77 function cursorInput ( input : HTMLInputElement , pos ?: number ) {
8-
98 if ( pos !== undefined ) {
109 input . setSelectionRange ( pos , pos ) ;
1110 }
@@ -17,12 +16,12 @@ describe('InputNumber.Cursor', () => {
1716 changeValue : string ,
1817 cursorPos : number ,
1918 which ?: number ,
20- key ?: number | string ,
19+ key ?: number | string ,
2120 ) {
22- fireEvent . focus ( input )
23- fireEvent . keyDown ( input , { which, keyCode :which , key} )
24- fireEvent . change ( input , { target : { value : changeValue , selectionStart : 1 } } )
25- fireEvent . keyUp ( input , { which, keyCode :which , key} )
21+ fireEvent . focus ( input ) ;
22+ fireEvent . keyDown ( input , { which, keyCode : which , key } ) ;
23+ fireEvent . change ( input , { target : { value : changeValue , selectionStart : 1 } } ) ;
24+ fireEvent . keyUp ( input , { which, keyCode : which , key } ) ;
2625 }
2726
2827 // https://github.com/react-component/input-number/issues/235
@@ -42,12 +41,14 @@ describe('InputNumber.Cursor', () => {
4241 describe ( 'pre-pend string' , ( ) => {
4342 it ( 'quick typing' , ( ) => {
4443 // `$ ` => `9$ ` => `$ 9`
45- const { container } = render ( < InputNumber defaultValue = "$ " formatter = { ( val ) => `$ ${ val } ` } /> ) ;
44+ const { container } = render (
45+ < InputNumber defaultValue = "$ " formatter = { ( val ) => `$ ${ val } ` } /> ,
46+ ) ;
4647 const input = container . querySelector ( 'input' ) ;
47- fireEvent . focus ( input )
48+ fireEvent . focus ( input ) ;
4849 cursorInput ( input , 0 ) ;
49- changeOnPos ( input , '9$ ' , 1 , KeyCode . NUM_ONE , '1' ) ;
50- expect ( cursorInput ( input , 3 ) ) . toEqual ( 3 ) ;
50+ changeOnPos ( input , '9$ ' , 1 , KeyCode . NUM_ONE , '1' ) ;
51+ expect ( cursorInput ( input , 3 ) ) . toEqual ( 3 ) ;
5152 } ) ;
5253
5354 describe ( '[LEGACY]' , ( ) => {
@@ -70,50 +71,55 @@ describe('InputNumber.Cursor', () => {
7071
7172 const { container } = render ( < Demo /> ) ;
7273 const input = container . querySelector ( 'input' ) ;
73- fireEvent . focus ( input )
74+ fireEvent . focus ( input ) ;
7475 for ( let i = 0 ; i < prependValue . length ; i += 1 ) {
75- fireEvent . keyDown ( input , { which : KeyCode . ONE , keyCode : KeyCode . ONE } )
76+ fireEvent . keyDown ( input , { which : KeyCode . ONE , keyCode : KeyCode . ONE } ) ;
7677 }
7778
7879 const finalValue = prependValue + initValue ;
7980 cursorInput ( input , prependValue . length ) ;
80- fireEvent . change ( input , { target : { value : finalValue } } ) ;
81+ fireEvent . change ( input , { target : { value : finalValue } } ) ;
8182
8283 return input ;
8384 } ;
8485
8586 it ( 'should fix caret position on case 1' , ( ) => {
8687 // '$ 1'
8788 const input = setUpCursorTest ( '' , '1' ) ;
88- expect ( cursorInput ( input , 3 ) ) . toEqual ( 3 ) ;
89+ expect ( cursorInput ( input , 3 ) ) . toEqual ( 3 ) ;
8990 } ) ;
9091
9192 it ( 'should fix caret position on case 2' , ( ) => {
9293 // '$ 111'
9394 const input = setUpCursorTest ( '' , '111' ) ;
94- expect ( cursorInput ( input , 5 ) ) . toEqual ( 5 ) ;
95+ expect ( cursorInput ( input , 5 ) ) . toEqual ( 5 ) ;
9596 } ) ;
9697
9798 it ( 'should fix caret position on case 3' , ( ) => {
9899 // '$ 111'
99100 const input = setUpCursorTest ( '1' , '11' ) ;
100- expect ( cursorInput ( input , 4 ) ) . toEqual ( 4 ) ;
101+ expect ( cursorInput ( input , 4 ) ) . toEqual ( 4 ) ;
101102 } ) ;
102103
103104 it ( 'should fix caret position on case 4' , ( ) => {
104105 // '$ 123,456'
105106 const input = setUpCursorTest ( '456' , '123' ) ;
106- expect ( cursorInput ( input , 6 ) ) . toEqual ( 6 ) ;
107+ expect ( cursorInput ( input , 6 ) ) . toEqual ( 6 ) ;
107108 } ) ;
108109 } ) ;
109110 } ) ;
110111
111112 describe ( 'append string' , ( ) => {
112113 it ( 'position caret before appended characters' , ( ) => {
113- const { container } = render ( < InputNumber formatter = { ( value ) => `${ value } %` } parser = { ( value ) => value . replace ( '%' , '' ) } /> ) ;
114+ const { container } = render (
115+ < InputNumber
116+ formatter = { ( value ) => `${ value } %` }
117+ parser = { ( value ) => value . replace ( '%' , '' ) }
118+ /> ,
119+ ) ;
114120 const input = container . querySelector ( 'input' ) ;
115121 fireEvent . focus ( input ) ;
116- fireEvent . change ( input , { target : { value : '5' } } ) ;
122+ fireEvent . change ( input , { target : { value : '5' } } ) ;
117123 expect ( cursorInput ( input ) ) . toEqual ( 1 ) ;
118124 } ) ;
119125 } ) ;
0 commit comments