Skip to content

Commit 15c6723

Browse files
author
Marek Rozmus
committed
Update SwipeableList test
1 parent b6f47a3 commit 15c6723

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/__tests__/SwipeableList.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,38 @@ test('blocking swipe on scroll', () => {
6666
swipeLeftMouse(listItem);
6767
expect(callbackLeft).toHaveBeenCalledTimes(2);
6868
});
69+
70+
test('blocking swipe on scrollElement scroll', () => {
71+
const callbackLeft = jest.fn();
72+
73+
const { queryAllByTestId } = render(
74+
<SwipeableList scrollElement={window.document}>
75+
<SwipeableListItem
76+
swipeLeft={{
77+
content: <span>Left swipe content</span>,
78+
action: callbackLeft
79+
}}
80+
>
81+
<span>Item content 1</span>
82+
</SwipeableListItem>
83+
</SwipeableList>
84+
);
85+
86+
const listItem = queryAllByTestId('content')[0];
87+
88+
// try to swipe - should work
89+
swipeLeftMouse(listItem);
90+
expect(callbackLeft).toHaveBeenCalledTimes(1);
91+
92+
fireEvent.scroll(window.document, { target: { scrollY: 100 } });
93+
94+
// block swipe should be on
95+
swipeLeftMouse(listItem);
96+
expect(callbackLeft).toHaveBeenCalledTimes(1);
97+
98+
fireEvent.mouseUp(window.document);
99+
100+
// swiping should be possible again
101+
swipeLeftMouse(listItem);
102+
expect(callbackLeft).toHaveBeenCalledTimes(2);
103+
});

0 commit comments

Comments
 (0)