import React from 'react';
import renderer, { ReactTestInstance } from 'react-test-renderer';
import { TextArea } from '../../../';

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

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

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