{"size": 3441, "ext": "js", "max_stars_repo_path": "src/components/atoms/Input/__tests__/Input.spec.js", "max_stars_repo_name": "Frodigo/react-atomic-components", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/components/atoms/Input/__tests__/Input.spec.js", "max_issues_repo_name": "Frodigo/react-atomic-components", "max_issues_repo_issues_event_min_datetime": "2021-10-20T06:50:50.000Z", "max_issues_repo_issues_event_max_datetime": "2021-10-21T06:22:34.000Z", "max_forks_repo_path": "src/components/atoms/Input/__tests__/Input.spec.js", "max_forks_repo_name": "Frodigo/react-atomic-components", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": 14, "max_forks_count": null, "avg_line_length": 29.6637931034, "max_line_length": 79, "alphanum_fraction": 0.5068294101}
import React from 'react';
import { render, getByTestId, getByText } from '@testing-library/react';

import Input from '../Input';

describe('Input should be rendered', () => {
    test('Input renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            onChange: jest.fn()
        };
        const { container } = render(<Input {...props} />);

        expect(container).toMatchSnapshot();
        expect(
            getByTestId(container, 'input').getAttribute('type')
        ).toStrictEqual('text');
        expect(
            getByTestId(container, 'input').getAttribute('placeholder')
        ).toStrictEqual('Type here...');
    });

    test('Input error renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            type: 'email',
            onChange: jest.fn(),
            state: 'error'
        };
        const { container } = render(<Input {...props} />);

        expect(container).toMatchSnapshot();
        expect(
            getByTestId(container, 'input').classList.contains('inputError')
        ).toBe(true);
    });

    test('Input focus renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            type: 'email',
            onChange: jest.fn(),
            state: 'focus'
        };
        const { container } = render(<Input {...props} />);

        expect(container).toMatchSnapshot();
        expect(
            getByTestId(container, 'input').classList.contains('inputFocus')
        ).toBe(true);
    });

    test('Input disabled renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            type: 'email',
            onChange: jest.fn(),
            state: 'disabled'
        };
        const { container } = render(<Input {...props} />);

        expect(container).toMatchSnapshot();
        expect(
            getByTestId(container, 'input').classList.contains('inputDisabled')
        ).toBe(true);
        expect(
            getByTestId(container, 'input').getAttribute('disabled')
        ).toBeDefined();
    });

    test('textarea renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            isTextarea: true,
            onChange: jest.fn()
        };
        const { container } = render(<Input {...props} />);

        expect(container).toMatchSnapshot();
        expect(
            getByTestId(container, 'input').classList.contains('textarea')
        ).toBe(true);
    });

    test('error message renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            isTextarea: true,
            errorMessage: {
                message: 'error'
            },
            onChange: jest.fn()
        };
        const { container } = render(<Input {...props} />);

        expect(container).toMatchSnapshot();
        expect(getByText(container, 'error')).toBeDefined();
    });

    test('error class renders correctly', () => {
        const props = {
            placeholder: 'Type here...',
            isTextarea: false,
            errorMessage: {
                message: 'error'
            },
            onChange: jest.fn()
        };
        const { container } = render(<Input {...props} />);

        expect(
            getByTestId(container, 'input').classList.contains('hasError')
        ).toBe(true);
    });
});
