|
1 | 1 | import '@testing-library/jest-dom';
|
2 |
| -import { createEvent, fireEvent, render } from '@testing-library/react'; |
| 2 | +import { act, createEvent, fireEvent, render } from '@testing-library/react'; |
3 | 3 | import { mount } from 'enzyme';
|
4 | 4 | import { _rs as onLibResize } from 'rc-resize-observer/lib/utils/observerUtil';
|
5 | 5 | import { resetWarned } from 'rc-util/lib/warning';
|
6 | 6 | import React from 'react';
|
7 |
| -import { act } from 'react-dom/test-utils'; |
8 | 7 | import List from '../src';
|
9 | 8 | import { spyElementPrototypes } from './utils/domHook';
|
10 | 9 |
|
@@ -51,11 +50,13 @@ describe('List.Scroll', () => {
|
51 | 50 | });
|
52 | 51 |
|
53 | 52 | function genList(props, func = mount) {
|
54 |
| - let node = ( |
55 |
| - <List component="ul" itemKey="id" {...props}> |
56 |
| - {({ id }) => <li>{id}</li>} |
57 |
| - </List> |
58 |
| - ); |
| 53 | + const mergedProps = { |
| 54 | + component: 'ul', |
| 55 | + itemKey: 'id', |
| 56 | + children: ({ id }) => <li>{id}</li>, |
| 57 | + ...props, |
| 58 | + }; |
| 59 | + let node = <List {...mergedProps} />; |
59 | 60 |
|
60 | 61 | if (props.ref) {
|
61 | 62 | node = <div>{node}</div>;
|
@@ -494,4 +495,43 @@ describe('List.Scroll', () => {
|
494 | 495 |
|
495 | 496 | expect(container.querySelector('.rc-virtual-list-scrollbar-thumb')).toBeVisible();
|
496 | 497 | });
|
| 498 | + |
| 499 | + it('nest scroll', async () => { |
| 500 | + const { container } = genList( |
| 501 | + { |
| 502 | + itemHeight: 20, |
| 503 | + height: 100, |
| 504 | + data: genData(100), |
| 505 | + children: ({ id }) => |
| 506 | + id === '0' ? ( |
| 507 | + <li> |
| 508 | + <List component="ul" itemKey="id" itemHeight={20} height={100} data={genData(100)}> |
| 509 | + {({ id }) => <li>{id}</li>} |
| 510 | + </List> |
| 511 | + </li> |
| 512 | + ) : ( |
| 513 | + <li /> |
| 514 | + ), |
| 515 | + }, |
| 516 | + render, |
| 517 | + ); |
| 518 | + |
| 519 | + fireEvent.wheel(container.querySelector('ul ul li'), { |
| 520 | + deltaY: 10, |
| 521 | + }); |
| 522 | + |
| 523 | + await act(async () => { |
| 524 | + jest.advanceTimersByTime(1000000); |
| 525 | + await Promise.resolve(); |
| 526 | + }); |
| 527 | + |
| 528 | + expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute( |
| 529 | + 'data-dev-offset-top', |
| 530 | + '0', |
| 531 | + ); |
| 532 | + expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute( |
| 533 | + 'data-dev-offset-top', |
| 534 | + '10', |
| 535 | + ); |
| 536 | + }); |
497 | 537 | });
|
0 commit comments