import React from 'react';

import Checkbox from './index';

const mockOnChange = jest.fn();
const mockOnBlur = jest.fn();
const data = {
  label: 'label',
  required: false,
  name: 'name',
  value: false,
  onChange: mockOnChange,
  onBlur: mockOnBlur,
};

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

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

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

  it('should fire onChange event', () => {
    wrapper.find('input').simulate('change');
    expect(mockOnChange.mock.calls.length).toBe(1);
  });

  it('should be checked when value is set', () => {
    wrapper.setProps({ value: true });
    expect(wrapper.find('input').props().checked).toBe(true);
  });

  it('should fire onBlur event', () => {
    wrapper.find('input').simulate('blur');
    expect(mockOnBlur.mock.calls.length).toBe(1);
  });
});
