|
1 |
| -import React from 'react'; |
| 1 | +import { act, fireEvent, render } from '@testing-library/react'; |
2 | 2 | import { mount } from 'enzyme';
|
3 |
| -import { spyElementPrototypes } from './utils/domHook'; |
| 3 | +import React from 'react'; |
4 | 4 | import List from '../src';
|
| 5 | +import { spyElementPrototypes } from './utils/domHook'; |
5 | 6 |
|
6 | 7 | function genData(count) {
|
7 | 8 | return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
|
@@ -123,11 +124,55 @@ describe('List.Touch', () => {
|
123 | 124 |
|
124 | 125 | const touchEvent = new Event('touchstart');
|
125 | 126 | touchEvent.preventDefault = preventDefault;
|
126 |
| - wrapper |
127 |
| - .find('.rc-virtual-list-scrollbar') |
128 |
| - .instance() |
129 |
| - .dispatchEvent(touchEvent); |
| 127 | + wrapper.find('.rc-virtual-list-scrollbar').instance().dispatchEvent(touchEvent); |
130 | 128 |
|
131 | 129 | expect(preventDefault).toHaveBeenCalled();
|
132 | 130 | });
|
| 131 | + |
| 132 | + it('nest touch', async () => { |
| 133 | + const { container } = render( |
| 134 | + <List component="ul" itemHeight={20} height={100} data={genData(100)}> |
| 135 | + {({ id }) => |
| 136 | + id === '0' ? ( |
| 137 | + <li> |
| 138 | + <List component="ul" itemKey="id" itemHeight={20} height={100} data={genData(100)}> |
| 139 | + {({ id }) => <li>{id}</li>} |
| 140 | + </List> |
| 141 | + </li> |
| 142 | + ) : ( |
| 143 | + <li /> |
| 144 | + ) |
| 145 | + } |
| 146 | + </List>, |
| 147 | + ); |
| 148 | + |
| 149 | + const targetLi = container.querySelector('ul ul li'); |
| 150 | + |
| 151 | + fireEvent.touchStart(targetLi, { |
| 152 | + touches: [{ pageY: 0 }], |
| 153 | + }); |
| 154 | + |
| 155 | + fireEvent.touchMove(targetLi, { |
| 156 | + touches: [{ pageY: -1 }], |
| 157 | + }); |
| 158 | + |
| 159 | + await act(async () => { |
| 160 | + jest.advanceTimersByTime(1000000); |
| 161 | + await Promise.resolve(); |
| 162 | + }); |
| 163 | + |
| 164 | + expect(container.querySelectorAll('[data-dev-offset-top]')[0]).toHaveAttribute( |
| 165 | + 'data-dev-offset-top', |
| 166 | + '0', |
| 167 | + ); |
| 168 | + |
| 169 | + // inner not to be 0 |
| 170 | + expect(container.querySelectorAll('[data-dev-offset-top]')[1]).toHaveAttribute( |
| 171 | + 'data-dev-offset-top', |
| 172 | + ); |
| 173 | + expect(container.querySelectorAll('[data-dev-offset-top]')[1]).not.toHaveAttribute( |
| 174 | + 'data-dev-offset-top', |
| 175 | + '0', |
| 176 | + ); |
| 177 | + }); |
133 | 178 | });
|
0 commit comments