Skip to content

Commit 0bad8e5

Browse files
committed
test: cov
1 parent 71fa5d0 commit 0bad8e5

File tree

2 files changed

+54
-11
lines changed

2 files changed

+54
-11
lines changed

src/List.tsx

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,8 +408,6 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
408408
onWheelDelta,
409409
);
410410

411-
const onDeduplicatedRawWheel = onRawWheel;
412-
413411
// Mobile touch move
414412
useMobileTouchMove(useVirtual, componentRef, (isHorizontal, delta, smoothOffset, e) => {
415413
const event = e as TouchEvent & {
@@ -426,7 +424,7 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
426424
event._virtualHandled = true;
427425
}
428426

429-
onDeduplicatedRawWheel({
427+
onRawWheel({
430428
preventDefault() {},
431429
deltaX: isHorizontal ? delta : 0,
432430
deltaY: isHorizontal ? 0 : delta,
@@ -447,12 +445,12 @@ export function RawList<T>(props: ListProps<T>, ref: React.Ref<ListRef>) {
447445
}
448446

449447
const componentEle = componentRef.current;
450-
componentEle.addEventListener('wheel', onDeduplicatedRawWheel, { passive: false });
448+
componentEle.addEventListener('wheel', onRawWheel, { passive: false });
451449
componentEle.addEventListener('DOMMouseScroll', onFireFoxScroll as any, { passive: true });
452450
componentEle.addEventListener('MozMousePixelScroll', onMozMousePixelScroll, { passive: false });
453451

454452
return () => {
455-
componentEle.removeEventListener('wheel', onDeduplicatedRawWheel);
453+
componentEle.removeEventListener('wheel', onRawWheel);
456454
componentEle.removeEventListener('DOMMouseScroll', onFireFoxScroll as any);
457455
componentEle.removeEventListener('MozMousePixelScroll', onMozMousePixelScroll as any);
458456
};

tests/touch.test.js

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
import React from 'react';
1+
import { act, fireEvent, render } from '@testing-library/react';
22
import { mount } from 'enzyme';
3-
import { spyElementPrototypes } from './utils/domHook';
3+
import React from 'react';
44
import List from '../src';
5+
import { spyElementPrototypes } from './utils/domHook';
56

67
function genData(count) {
78
return new Array(count).fill(null).map((_, index) => ({ id: String(index) }));
@@ -123,11 +124,55 @@ describe('List.Touch', () => {
123124

124125
const touchEvent = new Event('touchstart');
125126
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);
130128

131129
expect(preventDefault).toHaveBeenCalled();
132130
});
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+
});
133178
});

0 commit comments

Comments
 (0)