Skip to content

Commit

Permalink
[BOT] Maryia/[Test Coverage] Folder: bot-web-ui/src/components/dragga…
Browse files Browse the repository at this point in the history
…ble (deriv-com#14302)

* test: upgrade draggable.tsx file

* test: upgrade draggable.tsx file(2)

* test: upgrade draggable.tsx file(3)
  • Loading branch information
maryia-matskevich-deriv authored Mar 25, 2024
1 parent 05885f2 commit 15af5a0
Showing 1 changed file with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';
import { mockStore, StoreProvider } from '@deriv/stores';
import { fireEvent, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import RootStore from 'Stores/index';
import { DBotStoreProvider, mockDBotStore } from 'Stores/useDBotStore';
import Draggable from '../draggable';
Expand Down Expand Up @@ -45,20 +46,52 @@ describe('Draggable', () => {
</StoreProvider>
);
});

it('should render Draggable', () => {
render(<Draggable is_visible={true} onCloseDraggable={jest.fn()} header_title='dummy' />, { wrapper });
expect(screen.getByTestId('react-rnd-wrapper')).toBeInTheDocument();
});

it('should not render Draggable', () => {
render(<Draggable is_visible={false} onCloseDraggable={jest.fn()} header_title='' />, { wrapper });
const draggable_element = screen.queryByTestId('react-rnd-wrapper');
expect(draggable_element).not.toBeInTheDocument();
});

it('should call onClose function on close button click', () => {
const mock_close = jest.fn();
render(<Draggable is_visible={true} onCloseDraggable={mock_close} header_title='' />, { wrapper });

const close_btn = screen.getByTestId('react-rnd-close-modal');
fireEvent.click(close_btn);

expect(mock_close).toBeCalled();
});

it('should change styles on the left and top by drag', () => {
const mock_close = jest.fn();
render(<Draggable is_visible={true} onCloseDraggable={mock_close} header_title='' />, { wrapper });

const draggable_element = screen.getByTestId('react-rnd-wrapper');
fireEvent.mouseDown(draggable_element);
fireEvent.mouseMove(draggable_element, { clientX: 100, clientY: 200 });
fireEvent.mouseUp(draggable_element);

const styles = window.getComputedStyle(draggable_element);
expect(styles.left).toBe('100px');
expect(styles.top).toBe('200px');
});

it('should onCloseDraggable() be invoked by start drag', () => {
const mock_close = jest.fn();
const { container } = render(<Draggable is_visible={true} onCloseDraggable={mock_close} header_title='' />, {
wrapper,
});
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access,
const svg = container.getElementsByTagName('use')[0];
// eslint-disable-next-line testing-library/no-container, testing-library/no-node-access
userEvent.click(svg);

expect(mock_close).toBeCalled();
});
});

0 comments on commit 15af5a0

Please sign in to comment.