@@ -6,7 +6,7 @@ import Cascader from '../src';
66import { addressOptions , addressOptionsForUneven , optionsForActiveMenuItems } from './demoOptions' ;
77import { mount } from './enzyme' ;
88import { toRawValues } from '../src/utils/commonUtil' ;
9- import { render } from '@testing-library/react' ;
9+ import { fireEvent , render } from '@testing-library/react' ;
1010
1111describe ( 'Cascader.Basic' , ( ) => {
1212 let selectedValue : any ;
@@ -1022,6 +1022,85 @@ describe('Cascader.Basic', () => {
10221022 wrapper . find ( `li[data-path-key]` ) . at ( 0 ) . simulate ( 'click' ) ;
10231023 wrapper . find ( `li[data-path-key]` ) . at ( 1 ) . simulate ( 'click' ) ;
10241024 } ) ;
1025+ it ( 'hover + search' , ( ) => {
1026+ let getOffesetTopTimes = 0 ;
1027+ const spyElement = spyElementPrototypes ( HTMLElement , {
1028+ offsetTop : {
1029+ get : ( ) => ( getOffesetTopTimes ++ % 2 === 0 ? 100 : 0 ) ,
1030+ } ,
1031+ scrollTop : {
1032+ get : ( ) => 0 ,
1033+ } ,
1034+ offsetHeight : {
1035+ get : ( ) => 10 ,
1036+ } ,
1037+ } ) ;
1038+
1039+ const wrapper = render (
1040+ < Cascader
1041+ expandTrigger = "hover"
1042+ options = { [
1043+ {
1044+ label : 'Women Clothing' ,
1045+ value : '1' ,
1046+ children : [
1047+ {
1048+ label : 'Women Tops, Blouses & Tee' ,
1049+ value : '11' ,
1050+ children : [
1051+ {
1052+ label : 'Women T-Shirts' ,
1053+ value : '111' ,
1054+ } ,
1055+ {
1056+ label : 'Women Tops' ,
1057+ value : '112' ,
1058+ } ,
1059+ {
1060+ label : 'Women Tank Tops & Camis' ,
1061+ value : '113' ,
1062+ } ,
1063+ {
1064+ label : 'Women Blouses' ,
1065+ value : '114' ,
1066+ } ,
1067+ ] ,
1068+ } ,
1069+ {
1070+ label : 'Women Suits' ,
1071+ value : '2' ,
1072+ children : [
1073+ {
1074+ label : 'Women Suit Pants' ,
1075+ value : '21' ,
1076+ } ,
1077+ {
1078+ label : 'Women Suit Sets' ,
1079+ value : '22' ,
1080+ } ,
1081+ {
1082+ label : 'Women Blazers' ,
1083+ value : '23' ,
1084+ } ,
1085+ ] ,
1086+ } ,
1087+ ] ,
1088+ } ,
1089+ ] }
1090+ showSearch
1091+ checkable
1092+ open
1093+ /> ,
1094+ ) ;
1095+ fireEvent . change ( wrapper . container . querySelector ( 'input' ) as HTMLElement , {
1096+ target : { value : 'w' } ,
1097+ } ) ;
1098+ const items = wrapper . container . querySelectorAll ( '.rc-cascader-menu-item' ) ;
1099+ fireEvent . mouseEnter ( items [ 9 ] ) ;
1100+ expect ( mockScrollTo ) . toHaveBeenCalledTimes ( 0 ) ;
1101+
1102+ spyElement . mockRestore ( ) ;
1103+ } ) ;
10251104 } ) ;
10261105
10271106 it ( 'not crash when value type is not array' , ( ) => {
0 commit comments