@@ -2,10 +2,9 @@ import { mount } from 'enzyme';
2
2
import KeyCode from 'rc-util/lib/KeyCode' ;
3
3
import { act } from 'react-dom/test-utils' ;
4
4
import React from 'react' ;
5
- import type { OptionListProps , RefOptionListProps } from '../src/OptionList' ;
5
+ import type { RefOptionListProps } from '../src/OptionList' ;
6
6
import OptionList from '../src/OptionList' ;
7
7
import { injectRunAllTimers } from './utils/common' ;
8
- import type { OptionsType } from '../src/interface' ;
9
8
import { fillFieldNames , flattenOptions } from '../src/utils/valueUtil' ;
10
9
import SelectContext from '../src/SelectContext' ;
11
10
import { BaseSelectContext } from '../src/hooks/useBaseProps' ;
@@ -299,4 +298,23 @@ describe('OptionList', () => {
299
298
) ;
300
299
expect ( wrapper . find ( '.rc-select-item-option' ) . first ( ) . prop ( 'title' ) ) . toBe ( undefined ) ;
301
300
} ) ;
301
+
302
+ it ( 'params to scrollIntoView should be object when key is pressed' , ( ) => {
303
+ const listRef = React . createRef < RefOptionListProps > ( ) ;
304
+ const options = Array . from ( { length : 20 } ) . map ( ( v , i ) => ( { value : i , label : i } ) ) ;
305
+ const mockScroll = jest . fn ( ) ;
306
+ const wrapper = mount (
307
+ generateList ( {
308
+ options,
309
+ ref : listRef ,
310
+ } ) ,
311
+ ) ;
312
+ const vList = wrapper . find ( 'List' ) . getElement ( ) as any ;
313
+ // override the ref to test the parameters passed to the scrollIntoView method
314
+ vList . ref . current = { scrollTo : mockScroll } ;
315
+ act ( ( ) => {
316
+ listRef . current . onKeyDown ( { which : KeyCode . DOWN } as any ) ;
317
+ } ) ;
318
+ expect ( mockScroll . mock . calls [ 0 ] [ 0 ] ) . toEqual ( { index : 1 } ) ;
319
+ } ) ;
302
320
} ) ;
0 commit comments