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

describe('TextInput Component', () => {
    it('renders correctly with label', () => {
        const onChangeTextMock = jest.fn();
        const tree = renderer.create(
            <TextInput 
                value=""
                onChangeText={onChangeTextMock}
                label="Example Label"
            />
        ).toJSON();
        expect(tree).toMatchSnapshot();
    });

    it('renders correctly without label', () => {
        const onChangeTextMock = jest.fn();
        const tree = renderer.create(
            <TextInput 
                value=""
                onChangeText={onChangeTextMock}
            />
        ).toJSON();
        expect(tree).toMatchSnapshot();
    });

    it('renders correctly with success status', () => {
        const onChangeTextMock = jest.fn();
        const tree = renderer.create(
            <TextInput 
                value=""
                onChangeText={onChangeTextMock}
                status="success"
            />
        ).toJSON();
        expect(tree).toMatchSnapshot();
    });

    it('renders correctly with warning status', () => {
        const onChangeTextMock = jest.fn();
        const tree = renderer.create(
            <TextInput 
                value=""
                onChangeText={onChangeTextMock}
                status="warning"
            />
        ).toJSON();
        expect(tree).toMatchSnapshot();
    });

    it('renders correctly with error status', () => {
        const onChangeTextMock = jest.fn();
        const tree = renderer.create(
            <TextInput 
                value=""
                onChangeText={onChangeTextMock}
                status="error"
            />
        ).toJSON();
        expect(tree).toMatchSnapshot();
    });

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