forked from deriv-com/deriv-app
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharrow-buton.spec.tsx
53 lines (39 loc) · 1.88 KB
/
arrow-buton.spec.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import React from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import ArrowButton from '../arrow-button';
const mockedTitle = 'mocked title';
const mockedDefaultProps = {
is_collapsed: false,
position: 'top' as React.ComponentProps<typeof ArrowButton>['position'],
onClick: jest.fn(),
title: mockedTitle,
handle_button: false,
};
describe('<ArrowButton/>', () => {
it('should render icon with title for top position if title is defined', () => {
render(<ArrowButton {...mockedDefaultProps} />);
expect(screen.getByText(mockedTitle)).toBeInTheDocument();
});
it('should not render icon with title for top position if title is undefined', () => {
render(<ArrowButton {...mockedDefaultProps} title={undefined} />);
expect(screen.queryByText(mockedTitle)).not.toBeInTheDocument();
});
it('should render icon with title for bottom position if title is defined', () => {
render(<ArrowButton {...mockedDefaultProps} position='bottom' />);
expect(screen.getByText(mockedTitle)).toBeInTheDocument();
});
it('should not render icon with title for bottom position if title is undefined', () => {
render(<ArrowButton {...mockedDefaultProps} title={undefined} position='bottom' />);
expect(screen.queryByText(mockedTitle)).not.toBeInTheDocument();
});
it('should render icon_flat with if handle_button === true', () => {
render(<ArrowButton {...mockedDefaultProps} handle_button />);
expect(screen.getByTestId('icon_handle')).toBeInTheDocument();
});
it('should call onClick function if user clicks on icon', () => {
render(<ArrowButton {...mockedDefaultProps} />);
userEvent.click(screen.getByText(mockedTitle));
expect(mockedDefaultProps.onClick).toHaveBeenCalled();
});
});