Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maryia/BOT-538/test: search-icon #9891

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import SearchIcon from '../search-box/search-icon';

jest.mock('@deriv/components', () => {
const original_module = jest.requireActual('@deriv/components');
return {
...original_module,
Icon: jest.fn(props => (
<div data-testid-icon={props.icon} data-testid-color={props.color}>
Icon
</div>
)),
};
});

const mocked_props = {
search: 'text',
is_search_loading: false,
onClick: jest.fn(),
};

describe('SearchIcon', () => {
it('should render the SearchIcon component', () => {
render(<SearchIcon {...mocked_props} />);

const icon_element = screen.getByText('Icon');

expect(icon_element).toBeInTheDocument();
});

it('should render the SearchIcon component with IcCloseCircle icon and has correct props when search value is not empty', () => {
render(<SearchIcon {...mocked_props} />);

const icon_close_circle = screen.getByText('Icon');

expect(icon_close_circle).toBeInTheDocument();
expect(icon_close_circle).toHaveAttribute('data-testid-color', 'secondary');
expect(icon_close_circle).toHaveAttribute('data-testid-icon', 'IcCloseCircle');
});

it('should render search icon when search is empty', () => {
render(<SearchIcon {...mocked_props} search='' />);

const search_icon = screen.getByText('Icon');

expect(search_icon).toBeInTheDocument();
expect(search_icon).toHaveAttribute('data-testid-icon', 'IcSearch');
});

it('should render loader when is_search_loading is true', () => {
render(<SearchIcon {...mocked_props} is_search_loading={true} />);

const loader = screen.getByTestId('loader');

expect(loader).toBeInTheDocument();
expect(loader).toHaveClass('loader', { exact: true });
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ type TSearchIcon = {

const SearchIcon = ({ search, is_search_loading, onClick }: TSearchIcon) => {
if (!search) return <Icon icon='IcSearch' />;
if (is_search_loading) return <div className='loader' />;
if (is_search_loading) return <div className='loader' data-testid='loader' />;
return <Icon icon='IcCloseCircle' onClick={onClick} color='secondary' />;
};

Expand Down