{"size": 1230, "ext": "js", "max_stars_repo_path": "test/spec/pages/LoginPage.spec.js", "max_stars_repo_name": "janstuemmel/typescript-react", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "test/spec/pages/LoginPage.spec.js", "max_issues_repo_name": "janstuemmel/typescript-react", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "test/spec/pages/LoginPage.spec.js", "max_forks_repo_name": "janstuemmel/typescript-react", "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": 18.0882352941, "max_line_length": 54, "alphanum_fraction": 0.6130081301}
jest.mock('react-redux', () => ({
  useDispatch: jest.fn(),
  useSelector: jest.fn(),
}))

import React from 'react'
import { mount } from 'enzyme'
import { useDispatch, useSelector } from 'react-redux'

import LoginPage from '../../../src/pages/LoginPage'


it('should mount with loading state', () => {

  // given
  useSelector.mockImplementationOnce(cb => cb({
    auth: {
      error: null,
      loading: true
    }
  }))

  // when
  const wrapper = mount(<LoginPage />)

  // then
  expect(wrapper.contains('Loading...')).toBe(true)
})


it('should mount with error state', () => {

  // given
  useSelector.mockImplementationOnce(cb => cb({
    auth: {
      error: 'test_error',
      loading: false
    }
  }))

  // when
  const wrapper = mount(<LoginPage />)

  // then
  expect(wrapper.contains('test_error')).toBe(true)
})


it('should call authenticate', () => {

  // given
  const dispatch = jest.fn()
  useDispatch.mockImplementationOnce(() => dispatch)
  useSelector.mockImplementationOnce(cb => cb({
    auth: {
      error: null,
      loading: false
    }
  }))

  const wrapper = mount(<LoginPage />)

  // when
  wrapper.find('button').simulate('click')

  // then
  expect(dispatch).toHaveBeenCalled()
})