{"size": 3385, "ext": "js", "max_stars_repo_path": "client/test/components/Signup.spec.js", "max_stars_repo_name": "enodi/PostIt", "max_stars_repo_stars_event_min_datetime": "2017-08-05T17:30:55.000Z", "max_stars_repo_stars_event_max_datetime": "2017-08-05T17:30:55.000Z", "max_issues_repo_path": "client/test/components/Signup.spec.js", "max_issues_repo_name": "enodi/PostIt", "max_issues_repo_issues_event_min_datetime": "2017-08-21T18:59:19.000Z", "max_issues_repo_issues_event_max_datetime": "2017-12-22T12:39:21.000Z", "max_forks_repo_path": "client/test/components/Signup.spec.js", "max_forks_repo_name": "enodi/PostIt", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 1, "max_issues_count": 17, "max_forks_count": null, "avg_line_length": 27.7459016393, "max_line_length": 82, "alphanum_fraction": 0.5982274742}
import React from 'react';

import { SignupContainer } from '../../src/components/Signup/SignupContainer.jsx';

jest.mock('react-dom');

const setup = () => {
  const props = {
    signupAction: jest.fn()
  };

  const wrapper = mount(<SignupContainer {...props} />);
  return {
    props,
    wrapper
  };
};

describe('Signup Container Component', () => {
  const { props, wrapper } = setup();
  const event = {
    preventDefault: jest.fn(),
    target: {
      value: 'enodi',
      name: 'username',
    }
  };

  it('should setState on input change', () => {
    wrapper.instance().onChange(event);
    expect(wrapper.state().username).toEqual('enodi');
  });

  it(`should return usernameError when user tries
  to signup with a username less than 4 characters`, () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        value: '',
        name: 'username',
      } };
    wrapper.instance().onBlur(evt);
    expect(wrapper.state().usernameError)
    .toEqual('Username cannot be less than 4 characters');
  });

  it('should return passwordError when user enters an empty field', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        value: '',
        name: 'password',
      } };
    wrapper.instance().onBlur(evt);
    expect(wrapper.state().passwordError).toEqual('This field cannot be empty');
  });

  it('should return fullnameError when user enters an empty field', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        value: '',
        name: 'fullname',
      } };
    wrapper.instance().onBlur(evt);
    expect(wrapper.state().fullnameError).toEqual('This field cannot be empty');
  });

  it('should return passwordError when user enters wrong email', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        value: '',
        name: 'email',
      } };
    wrapper.instance().onBlur(evt);
    expect(wrapper.state().emailError).toEqual('Invalid email');
  });

  it('should clear passwordError when user clicks on username field', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        name: 'username',
      } };
    wrapper.instance().onFocus(evt);
    expect(wrapper.state().usernameError).toEqual('');
  });

  it('should clear passwordError when user clicks on password field', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        name: 'password',
      } };
    wrapper.instance().onFocus(evt);
    expect(wrapper.state().passwordError).toEqual('');
  });

  it('should clear passwordError when user clicks on fullname field', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        name: 'fullname',
      } };
    wrapper.instance().onFocus(evt);
    expect(wrapper.state().fullnameError).toEqual('');
  });

  it('should clear passwordError when user clicks on email field', () => {
    const evt = { preventDefault: jest.fn(),
      target: {
        name: 'email',
      } };
    wrapper.instance().onFocus(evt);
    expect(wrapper.state().emailError).toEqual('');
  });

  it('should dispatch signupAction action when user signup', () => {
    wrapper.setState({
      fullname: 'Enodi Audu',
      email: 'enodiaudu5@gmail.com',
      username: 'enodi',
      password: 'password' });
    wrapper.instance().onSubmit(event);
    expect(props.signupAction.mock.calls.length).toEqual(1);
  });
});
