@@ -3,11 +3,22 @@ import Enzyme, { mount, ReactWrapper } from 'enzyme';
33import Adapter from '@wojtekmaj/enzyme-adapter-react-17' ;
44import MatchMediaMock from 'jest-matchmedia-mock' ;
55import { Scroller } from '../Body/Scroller' ;
6- import { Button } from '../../../Button ' ;
6+ import { ColumnType , StickyOffsets } from '../OcTable.types ' ;
77
88Enzyme . configure ( { adapter : new Adapter ( ) } ) ;
99
10- let matchMedia : any ;
10+ /** Minimal stand-in for the scroll body element the Scroller reads/writes. */
11+ interface MockScrollBody {
12+ scrollLeft : number ;
13+ clientWidth : number ;
14+ scrollWidth : number ;
15+ scrollTo : jest . Mock ;
16+ getBoundingClientRect : ( ) => Pick < DOMRect , 'top' | 'height' > ;
17+ addEventListener : jest . Mock ;
18+ removeEventListener : jest . Mock ;
19+ }
20+
21+ let matchMedia : MatchMediaMock ;
1122
1223describe ( 'Table.Scroller arrow navigation' , ( ) => {
1324 beforeAll ( ( ) => {
@@ -20,13 +31,13 @@ describe('Table.Scroller arrow navigation', () => {
2031
2132 // Three unfixed 128px columns => the Scroller builds stop-points
2233 // scrollOffsets = [0, 128, 256, 384].
23- const columns : any = [
34+ const columns : ColumnType < unknown > [ ] = [
2435 { title : 'C1' , dataIndex : 'c1' , key : 'c1' , width : 128 } ,
2536 { title : 'C2' , dataIndex : 'c2' , key : 'c2' , width : 128 } ,
2637 { title : 'C3' , dataIndex : 'c3' , key : 'c3' , width : 128 } ,
2738 ] ;
2839
29- const makeScrollBody = ( scrollLeft : number ) : any => ( {
40+ const makeScrollBody = ( scrollLeft : number ) : MockScrollBody => ( {
3041 scrollLeft,
3142 clientWidth : 100 ,
3243 scrollWidth : 384 ,
@@ -37,12 +48,17 @@ describe('Table.Scroller arrow navigation', () => {
3748 } ) ;
3849
3950 const createScroller = (
40- scrollBody : any ,
51+ scrollBody : MockScrollBody ,
4152 direction : string = 'ltr'
4253 ) : ReactWrapper => {
43- const scrollBodyRef = { current : scrollBody } ;
44- const stickyOffsets : any = { left : [ 0 , 0 , 0 , 0 ] , right : [ 0 , 0 , 0 , 0 ] } ;
45- const titleRef : any = { current : null } ;
54+ const scrollBodyRef : React . RefObject < HTMLDivElement > = {
55+ current : scrollBody as unknown as HTMLDivElement ,
56+ } ;
57+ const stickyOffsets : StickyOffsets = {
58+ left : [ 0 , 0 , 0 , 0 ] ,
59+ right : [ 0 , 0 , 0 , 0 ] ,
60+ } ;
61+ const titleRef : React . RefObject < HTMLDivElement > = { current : null } ;
4662 return mount (
4763 < Scroller
4864 columns = { columns }
@@ -58,12 +74,7 @@ describe('Table.Scroller arrow navigation', () => {
5874 } ;
5975
6076 const clickArrow = ( wrapper : ReactWrapper , ariaLabel : string ) : void => {
61- const onClick = wrapper
62- . find ( Button )
63- . filterWhere ( ( node ) => node . prop ( 'ariaLabel' ) === ariaLabel )
64- . first ( )
65- . prop ( 'onClick' ) as ( ) => void ;
66- onClick ( ) ;
77+ wrapper . find ( `button[aria-label="${ ariaLabel } "]` ) . first ( ) . simulate ( 'click' ) ;
6778 } ;
6879
6980 it ( 'right arrow advances to the next column from the start' , ( ) => {
0 commit comments