Skip to content

Commit

Permalink
test: improve swipeable bottom sheet test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
shafin-deriv committed Mar 21, 2024
1 parent 5e0713c commit 5c15552
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jest.useFakeTimers();

function patchCreateEvent(createEvent: any) {
// patching createEvent for pointer events to work from jsdom
for (let key in createEvent) {
for (const key in createEvent) {
if (key.indexOf('pointer') === 0) {
const fn = createEvent[key.replace('pointer', 'mouse')];
if (!fn) continue;
Expand Down Expand Up @@ -77,7 +77,7 @@ describe('SwipeableBottomSheet', () => {
expect(handlerElement).toBeInTheDocument();
});

it('should close the bottom sheet on mobile if handler is dragged to the bottom', async () => {
it('should close the bottom sheet on mobile if handler is dragged to the bottom', () => {
const component = renderComponent({ app_register_modal_open: true, on_close: onCancel });
const { rerender } = render(component);
rerender(component);
Expand All @@ -103,4 +103,16 @@ describe('SwipeableBottomSheet', () => {
jest.advanceTimersByTime(600);
expect(onCancel).toBeCalled();
});

it('should not drag the bottom sheet on mobile if drag is disabled', () => {
const component = renderComponent({
app_register_modal_open: true,
on_close: onCancel,
disable_drag: true,
});
const { rerender } = render(component);
rerender(component);
const handlerElement = screen.queryByTestId('dt_action_sheet_handler');
expect(handlerElement).not.toBeInTheDocument();
});
});
1 change: 0 additions & 1 deletion src/components/SwipeableBottomSheet/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ const SwipeableBottomSheet: React.FC<SwipeableBottomSheetProps> = ({

useDrag(
({ last, velocity: [, vy], direction: [, dy], offset: [, oy], cancel, canceled }) => {
if (disable_drag) return;
if (oy < -70) cancel();
if (last) oy > height * 0.5 || (vy > 0.5 && dy > 0) ? close(vy) : open({ canceled });
else api.start({ y: oy, immediate: true });
Expand Down

0 comments on commit 5c15552

Please sign in to comment.