{"size": 1288, "ext": "js", "max_stars_repo_path": "src/javascript/components/SearchInput/__tests__/SearchInput.spec.js", "max_stars_repo_name": "ralph-learning/references-project", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/javascript/components/SearchInput/__tests__/SearchInput.spec.js", "max_issues_repo_name": "ralph-learning/references-project", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/javascript/components/SearchInput/__tests__/SearchInput.spec.js", "max_forks_repo_name": "ralph-learning/references-project", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 29.9534883721, "max_line_length": 78, "alphanum_fraction": 0.5877329193}
import React from 'react';
import { shallow, mount, render } from 'enzyme';

import SearchInput from '../index';

describe('SearchInput', () => {
  describe('input search', () => {
    it('should have a input', () => {
      const wrapper = shallow(<SearchInput />);
      expect(wrapper.find('input').length).toEqual(1);
    });

    it('should exist "query" state', () => {
      const wrapper = mount(<SearchInput />);
      expect(wrapper.state().query).not.toBeUndefined();
    });

    it('should update correcly "query" state when change input value', () => {
      const wrapper = mount(<SearchInput />);
      const input = wrapper.find('input');
      input.simulate('change', { target: { value: 'Hello' } });

      expect(wrapper.state().query).toEqual('Hello');
    })
  });

  describe('button search', () => {
    it('should have a search button', () => {
      const wrapper = shallow(<SearchInput />);
      expect(wrapper.find('button').length).toEqual(1);
    });

    it('should called search() when button is clicked', () => {
      const wrapper = mount(<SearchInput />);
      const button = wrapper.find('button');
      const spy = jest.spyOn(wrapper.instance(), 'search');

      button.simulate('click');
      expect(spy).toHaveBeenCalled();
    });
  });
});
