11/* eslint-disable no-undef */
22import { mount , shallow } from 'enzyme' ;
33import React from 'react' ;
4+ import 'regenerator-runtime/runtime' ;
45import { Provider } from 'react-redux' ;
56import renderer from 'react-test-renderer' ;
67import configureStore from 'redux-mock-store' ;
8+ import TextField from '@material-ui/core/TextField' ;
9+ import ThemeProvider from '@material-ui/styles/ThemeProvider' ;
710import customMessage from '../utils/customMessages' ;
811import App from '../entry/App' ;
912import HelloComponent from '../components/HelloComponent' ;
1013import FrontPage from '../views/frontPage' ;
1114import reducer from '../reducers/reducer' ;
1215import firstMessage from '../actions/actions' ;
16+ import Login , {
17+ UserLogin , mapDispatchToProps ,
18+ mapStateToProps ,
19+ } from '../components/forms/UserLogin' ;
20+ import InputField from '../components/forms/InputField' ;
21+ import Lines from '../components/forms/Lines' ;
22+ import Links from '../components/forms/Link' ;
23+ import SubmitButton from '../components/forms/SubmitButton' ;
24+ import SocialLogin from '../components/forms/SocialLogin' ;
25+
1326
1427let component = '' ;
28+ let loginComponent = '' ;
1529
1630const mockStore = configureStore ( [ ] ) ;
1731const store = mockStore ( {
@@ -23,6 +37,24 @@ component = renderer.create(
2337 < HelloComponent />
2438 </ Provider > ,
2539) ;
40+ loginComponent = renderer . create (
41+ < Provider store = { store } >
42+ < Login />
43+ </ Provider > ,
44+ ) ;
45+ const initialObj = {
46+ email : '' ,
47+ errors : '' ,
48+ message : 'Welcome' ,
49+ password : '' ,
50+ success : false ,
51+ token : '' ,
52+ } ;
53+ const handleLoginChange = jest . fn ( ) ;
54+ const props = {
55+ name : 'password' ,
56+ handleLoginChange : handleLoginChange ,
57+ }
2658describe ( 'App tests' , ( ) => {
2759 it ( 'Will prove that the app is rendered from App component' , ( ) => {
2860 const appRender = shallow ( < App /> ) ;
@@ -40,7 +72,7 @@ describe('App tests', () => {
4072 } ) ;
4173
4274 it ( 'should return welcome when no action provided' , ( ) => {
43- expect ( reducer ( undefined , { } ) ) . toEqual ( { message : 'Welcome' } ) ;
75+ expect ( reducer ( undefined , { } ) ) . toEqual ( initialObj ) ;
4476 } ) ;
4577 it ( 'should return Redux when action is provided with value' , ( ) => {
4678 expect ( reducer ( undefined , { ...firstMessage , value : 'Redux' } ) ) . toEqual ( { message : 'Redux' } ) ;
@@ -51,4 +83,31 @@ describe('App tests', () => {
5183 } ) ;
5284 expect ( store . dispatch ) . toHaveBeenCalledTimes ( 1 ) ;
5385 } ) ;
86+ it ( 'rendering the user login component' , ( ) => {
87+ const login = shallow ( < loginComponent /> ) ;
88+ expect ( login . contains ( < InputField /> , < SubmitButton /> , < Links /> , < Lines /> , < SocialLogin /> ) ) ;
89+ } ) ;
90+ it ( 'password should hold what a user entered' , ( ) => {
91+ const wrapper = shallow ( < InputField { ...props } /> ) ;
92+ wrapper
93+ . find ( TextField )
94+ . simulate ( 'change' , { target : { value : 'Example@2020' } } ) ;
95+ expect ( handleLoginChange ) . toBeCalledTimes ( 1 ) ;
96+ } ) ;
97+ it ( 'email should hold what a user entered' , ( ) => {
98+
99+ const props = {
100+ name : 'email' ,
101+ handleLoginChange : handleLoginChange ,
102+ }
103+ const wrapper = shallow ( < InputField { ...props } /> ) ;
104+ wrapper
105+ . find ( TextField )
106+ . simulate ( 'change' , { target : { name :'email' , value : 'Example@2020' } } ) ;
107+ expect ( handleLoginChange ) . toBeCalledTimes ( 1 ) ;
108+ } ) ;
109+ // it('rendering the user login component', () => {
110+ // const login = shallow(<loginComponent />);
111+ // expect(login.contains(<InputField />, <SubmitButton />, <Links />, <Lines />, <SocialLogin />));
112+ // });
54113} ) ;
0 commit comments