@@ -51,8 +51,6 @@ describe('BaseInput', () => {
5151 const onBlur = jest . fn ( ) ;
5252 const onFocus = jest . fn ( ) ;
5353
54- const user = userEvent . setup ( ) ;
55-
5654 const Demo : FC = ( ) => {
5755 const [ value , setValue ] = useState < string > ( '' ) ;
5856
@@ -97,33 +95,27 @@ describe('BaseInput', () => {
9795 expect ( inputEl ! . value ) . toBe ( '' ) ;
9896 } ) ;
9997
100- // it('By focus and Space', async () => {
101- // const { container } = render(<Demo />);
102-
103- // const inputEl = container.querySelector('input');
104- // await user.click(inputEl!);
105-
106- // await user.type(inputEl!, 'some text');
107- // expect(inputEl!.value).toBe('some text');
98+ it . each ( [ '[Space]' , '[Enter]' ] ) ( 'By focus and %s' , async ( key ) => {
99+ const user = userEvent . setup ( ) ;
100+ const { container } = render ( < Demo /> ) ;
108101
109- // await user.tab();
110- // await user.keyboard('[Space]');
111- // expect(inputEl!.value).toBe('');
112- // });
102+ const inputEl = container . querySelector ( 'input' ) ;
103+ await user . click ( inputEl ! ) ;
113104
114- // it('By focus and Enter', async () => {
115- // const { container } = render(<Demo /> );
105+ await user . type ( inputEl ! , 'some text' ) ;
106+ expect ( inputEl ! . value ) . toBe ( 'some text' ) ;
116107
117- // const inputEl = container.querySelector('input');
118- // await user.click(inputEl!);
108+ await user . tab ( ) ;
119109
120- // await user.type(inputEl!, 'some text');
121- // expect(inputEl!.value).toBe('some text');
110+ const clearIcon = container . querySelector < HTMLButtonElement > (
111+ '.rc-input-clear-icon' ,
112+ ) ! ;
113+ expect ( document . activeElement ) . toBe ( clearIcon ) ;
114+ expect ( clearIcon . tabIndex ) . toBe ( 0 ) ;
122115
123- // await user.tab();
124- // await user.keyboard('[Enter]');
125- // expect(inputEl!.value).toBe('');
126- // });
116+ await user . keyboard ( key ) ;
117+ expect ( inputEl ! . value ) . toBe ( '' ) ;
118+ } ) ;
127119 } ) ;
128120
129121 it ( 'should display clearIcon correctly' , ( ) => {
0 commit comments