1
1
import React from 'react' ;
2
2
import { act , fireEvent , render } from '@testing-library/react' ;
3
3
import { spyElementPrototypes } from 'rc-util/lib/test/domHook' ;
4
- import { } from 'rc-resize-observer' ;
5
4
import type { ListRef } from '../src' ;
6
5
import List , { type ListProps } from '../src' ;
7
6
import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil' ;
@@ -18,16 +17,18 @@ describe('List.scrollWidth', () => {
18
17
let mockMouseEvent ;
19
18
let pageX : number ;
20
19
20
+ let holderWidth = 100 ;
21
+
21
22
beforeAll ( ( ) => {
22
23
mockElement = spyElementPrototypes ( HTMLElement , {
23
24
offsetHeight : {
24
25
get : ( ) => ITEM_HEIGHT ,
25
26
} ,
26
27
clientHeight : {
27
- get : ( ) => 100 ,
28
+ get : ( ) => holderWidth ,
28
29
} ,
29
30
getBoundingClientRect : ( ) => ( {
30
- width : 100 ,
31
+ width : holderWidth ,
31
32
height : 100 ,
32
33
} ) ,
33
34
} ) ;
@@ -45,6 +46,7 @@ describe('List.scrollWidth', () => {
45
46
} ) ;
46
47
47
48
beforeEach ( ( ) => {
49
+ holderWidth = 100 ;
48
50
jest . useFakeTimers ( ) ;
49
51
} ) ;
50
52
@@ -229,4 +231,34 @@ describe('List.scrollWidth', () => {
229
231
`${ ITEM_HEIGHT } /${ 4 * ITEM_HEIGHT } ` ,
230
232
) ;
231
233
} ) ;
234
+
235
+ it ( 'resize should back of scrollLeft' , async ( ) => {
236
+ const { container } = await genList ( {
237
+ itemHeight : ITEM_HEIGHT ,
238
+ height : 100 ,
239
+ data : genData ( 100 ) ,
240
+ scrollWidth : 1000 ,
241
+ } ) ;
242
+
243
+ // Wheel
244
+ fireEvent . wheel ( container . querySelector ( '.rc-virtual-list-holder' ) ! , {
245
+ deltaX : 9999999 ,
246
+ } ) ;
247
+
248
+ holderWidth = 200 ;
249
+
250
+ await act ( async ( ) => {
251
+ onLibResize ( [
252
+ {
253
+ target : container . querySelector ( '.rc-virtual-list-holder' ) ! ,
254
+ } as ResizeObserverEntry ,
255
+ ] ) ;
256
+
257
+ await Promise . resolve ( ) ;
258
+ } ) ;
259
+
260
+ expect ( container . querySelector ( '.rc-virtual-list-holder-inner' ) ) . toHaveStyle ( {
261
+ marginLeft : '-800px' ,
262
+ } ) ;
263
+ } ) ;
232
264
} ) ;
0 commit comments