import React from 'react';

import FormRegister from './index';

const mockHandleChange = jest.fn();
const mockHandleBlur = jest.fn();
const mockHandleSubmit = jest.fn();

const data = {
  values: {
    firstName: '',
    lastName: '',
    emailAddress: '',
    phoneNumber: {
      isValid: true,
      number: '',
    },
    password: '',
    partnerType: '',
    company: '',
    countryCode: '',
  },
  touched: {
    firstName: false,
    lastName: false,
    emailAddress: false,
    phoneNumber: false,
    password: false,
    partnerType: false,
    company: false,
    countryCode: false,
  },
  errors: {
    firstName: '',
    lastName: '',
    emailAddress: '',
    phoneNumber: '',
    password: '',
    partnerType: '',
    company: '',
    countryCode: '',
  },
  handleChange: mockHandleChange,
  handleBlur: mockHandleBlur,
  handleSubmit: mockHandleSubmit,
  labels: {
    firstName: 'firstName',
    lastName: 'lastName',
    emailAddress: 'emailAddress',
    phoneNumber: 'phoneNumber',
    password: 'password',
    company: 'company',
    inProgress: 'inProgress',
    showPassword: 'showPassword',
    hidePassword: 'hidePassword',
    accountInformation: 'accountInformation',
    contactInformation: 'contactInformation',
    partnerTypes: 'partnerTypes',
    country: 'country',
    register: 'register',
    registerInfo: 'registerInfo',
    next: {
      title: 'title',
      desc: 'desc',
      stepsTitle: 'stepsTitle',
      steps: ['step1', 'step2'],
    },
  },
  isSubmitting: false,
  status: {
    msg: '',
  },
  partnerTypes: [
    {
      name: 'partnerType',
      value: 'partnerType',
      label: 'partnerType',
    },
  ],
  countryCodes: [
    {
      value: 'countryCode',
      name: 'countryCode',
    },
  ],
};

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

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

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

  it('should submit form', () => {
    wrapper = mount(defaultElement);
    wrapper.find('button[type="submit"]').simulate('submit');
    expect(mockHandleSubmit.mock.calls.length).toBe(1);
  });

  it('should call handle change', () => {
    wrapper = mount(defaultElement);
    const event = {
      target: { value: 'value' },
    };

    wrapper.find('input[name="firstName"]').simulate('change', event);
    expect(mockHandleChange.mock.calls.length).toBe(1);
  });
});
