import React from 'react';

import Input from './index';

const mockCallbackOnchange = jest.fn();

const data = {
  onChange: mockCallbackOnchange,
};

describe('Input', () => {
  const defaultElement = <Input {...data} />;
  let wrapper;

  beforeEach(() => {
    wrapper = shallow(defaultElement);
  });

  it('should render correctly', () => {
    expect(wrapper).toMatchSnapshot();
  });

  it('should render correctly with password', () => {
    expect(wrapper.setProps({ type: 'password' })).toMatchSnapshot();
  });

  it('should fire onChange event', () => {
    const event = {
      preventDefault(): void {
        // do nothing.
      },
      target: { value: 'value' },
    };
    wrapper.find('input').simulate('change', event);
    expect(mockCallbackOnchange.mock.calls.length).toBe(1);
    expect(mockCallbackOnchange).toBeCalledWith(event);
  });
});
