test: Unskip SearchBox test (#4966)
This commit is contained in:
parent
f916375fd7
commit
2748e6d475
|
@ -1,6 +1,5 @@
|
||||||
import React from 'react';
|
import React from 'react';
|
||||||
import { fireEvent, render } from '@testing-library/react-native';
|
import { fireEvent, render } from '@testing-library/react-native';
|
||||||
import { TextInputProps } from 'react-native';
|
|
||||||
|
|
||||||
import SearchBox from '.';
|
import SearchBox from '.';
|
||||||
|
|
||||||
|
@ -11,35 +10,35 @@ const testSearchInputs = {
|
||||||
testID: 'search-box-text-input'
|
testID: 'search-box-text-input'
|
||||||
};
|
};
|
||||||
|
|
||||||
const Render = ({ onChangeText, testID }: TextInputProps) => <SearchBox testID={testID} onChangeText={onChangeText} />;
|
|
||||||
|
|
||||||
describe('SearchBox', () => {
|
describe('SearchBox', () => {
|
||||||
it('should render the searchbox component', () => {
|
it('should render the searchbox component', () => {
|
||||||
const { findByTestId } = render(<Render onChangeText={testSearchInputs.onChangeText} testID={testSearchInputs.testID} />);
|
const { findByTestId } = render(<SearchBox onChangeText={testSearchInputs.onChangeText} testID={testSearchInputs.testID} />);
|
||||||
|
|
||||||
expect(findByTestId('searchbox')).toBeTruthy();
|
expect(findByTestId('searchbox')).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should not render clear-input icon', async () => {
|
it('should not render clear-input icon', async () => {
|
||||||
const { queryByTestId } = render(<Render onChangeText={testSearchInputs.onChangeText} testID={testSearchInputs.testID} />);
|
const { queryByTestId } = render(<SearchBox onChangeText={testSearchInputs.onChangeText} testID={testSearchInputs.testID} />);
|
||||||
const clearInput = await queryByTestId('clear-text-input');
|
const clearInput = await queryByTestId('clear-text-input');
|
||||||
expect(clearInput).toBeNull();
|
expect(clearInput).toBeNull();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should input new value with onChangeText function', async () => {
|
it('should input new value with onChangeText function', async () => {
|
||||||
const { findByTestId } = render(<Render onChangeText={onChangeTextMock} testID={testSearchInputs.testID} />);
|
const { findByTestId } = render(<SearchBox onChangeText={onChangeTextMock} testID={testSearchInputs.testID} />);
|
||||||
|
|
||||||
const component = await findByTestId(testSearchInputs.testID);
|
const component = await findByTestId(testSearchInputs.testID);
|
||||||
fireEvent.changeText(component, 'new-input-value');
|
fireEvent.changeText(component, 'new-input-value');
|
||||||
expect(onChangeTextMock).toHaveBeenCalledWith('new-input-value');
|
expect(onChangeTextMock).toHaveBeenCalledWith('new-input-value');
|
||||||
});
|
});
|
||||||
|
|
||||||
// we need skip this test for now, until discovery how handle with functions effect
|
it('should clear input when clear icon is pressed', async () => {
|
||||||
// https://github.com/callstack/react-native-testing-library/issues/978
|
const { findByTestId } = render(<SearchBox onChangeText={onChangeTextMock} testID={testSearchInputs.testID} />);
|
||||||
it.skip('should clear input when call onCancelSearch function', async () => {
|
|
||||||
const { findByTestId } = render(<Render testID={'input-with-value'} onChangeText={onChangeTextMock} />);
|
|
||||||
|
|
||||||
const component = await findByTestId('clear-text-input');
|
const component = await findByTestId(testSearchInputs.testID);
|
||||||
fireEvent.press(component, 'input-with-value');
|
fireEvent.changeText(component, 'new-input-value');
|
||||||
expect(onChangeTextMock).toHaveBeenCalledWith('input-with-value');
|
|
||||||
|
const clearTextInput = await findByTestId('clear-text-input');
|
||||||
|
fireEvent.press(clearTextInput);
|
||||||
|
expect(onChangeTextMock).toHaveBeenCalledWith('');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue