2022-06-06 13:53:02 +00:00
|
|
|
import React from 'react';
|
|
|
|
import { fireEvent, render } from '@testing-library/react-native';
|
|
|
|
|
|
|
|
import SearchBox from '.';
|
|
|
|
|
|
|
|
const onChangeTextMock = jest.fn();
|
|
|
|
|
|
|
|
const testSearchInputs = {
|
|
|
|
onChangeText: onChangeTextMock,
|
|
|
|
testID: 'search-box-text-input'
|
|
|
|
};
|
|
|
|
|
|
|
|
describe('SearchBox', () => {
|
|
|
|
it('should render the searchbox component', () => {
|
2023-03-17 16:40:32 +00:00
|
|
|
const { findByTestId } = render(<SearchBox onChangeText={testSearchInputs.onChangeText} testID={testSearchInputs.testID} />);
|
2022-06-06 13:53:02 +00:00
|
|
|
|
|
|
|
expect(findByTestId('searchbox')).toBeTruthy();
|
|
|
|
});
|
2023-03-17 16:40:32 +00:00
|
|
|
|
2022-06-06 13:53:02 +00:00
|
|
|
it('should not render clear-input icon', async () => {
|
2023-03-17 16:40:32 +00:00
|
|
|
const { queryByTestId } = render(<SearchBox onChangeText={testSearchInputs.onChangeText} testID={testSearchInputs.testID} />);
|
2022-06-06 13:53:02 +00:00
|
|
|
const clearInput = await queryByTestId('clear-text-input');
|
|
|
|
expect(clearInput).toBeNull();
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should input new value with onChangeText function', async () => {
|
2023-03-17 16:40:32 +00:00
|
|
|
const { findByTestId } = render(<SearchBox onChangeText={onChangeTextMock} testID={testSearchInputs.testID} />);
|
2022-06-06 13:53:02 +00:00
|
|
|
|
|
|
|
const component = await findByTestId(testSearchInputs.testID);
|
|
|
|
fireEvent.changeText(component, 'new-input-value');
|
|
|
|
expect(onChangeTextMock).toHaveBeenCalledWith('new-input-value');
|
|
|
|
});
|
|
|
|
|
2023-03-17 16:40:32 +00:00
|
|
|
it('should clear input when clear icon is pressed', async () => {
|
|
|
|
const { findByTestId } = render(<SearchBox onChangeText={onChangeTextMock} testID={testSearchInputs.testID} />);
|
|
|
|
|
|
|
|
const component = await findByTestId(testSearchInputs.testID);
|
|
|
|
fireEvent.changeText(component, 'new-input-value');
|
2022-06-06 13:53:02 +00:00
|
|
|
|
2023-03-17 16:40:32 +00:00
|
|
|
const clearTextInput = await findByTestId('clear-text-input');
|
|
|
|
fireEvent.press(clearTextInput);
|
|
|
|
expect(onChangeTextMock).toHaveBeenCalledWith('');
|
2022-06-06 13:53:02 +00:00
|
|
|
});
|
|
|
|
});
|