import React from 'react';
import renderer from 'react-test-renderer';
import {SearchBar} from '../../TextFields/SearchBar';

describe('SearchBar Component', () => {
    it('renders correctly', () => {
        const onChangeTextMock = jest.fn();
        const tree = renderer.create(
            <SearchBar 
                value=""
                onChangeText={onChangeTextMock}
                placeholder="Search"
            />
        ).toJSON();
        expect(tree).toMatchSnapshot();
    });

    it('calls onChangeText function when text is changed', () => {
        const onChangeTextMock = jest.fn();
        const component = renderer.create(
            <SearchBar 
                value=""
                onChangeText={onChangeTextMock}
                placeholder="Search"
            />
        );
        const textInput = component.root.findByType("TextInput");
        textInput.props.onChangeText("example");
        expect(onChangeTextMock).toHaveBeenCalledWith("example");
    });
});
