From 580a5b6adb5cf89dbf6d5f6fe7a222064482a833 Mon Sep 17 00:00:00 2001 From: shahnawaz19415 Date: Tue, 18 Dec 2018 15:02:37 +0500 Subject: [PATCH] Redux form validation test in Login --- client/src/store/configureStore.dev.js | 9 +++++++-- client/src/store/configureStore.prod.js | 4 +++- client/src/test/login.test.js | 19 +++++++++++++++++-- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/client/src/store/configureStore.dev.js b/client/src/store/configureStore.dev.js index 3419614..f747235 100644 --- a/client/src/store/configureStore.dev.js +++ b/client/src/store/configureStore.dev.js @@ -4,6 +4,7 @@ import { createLogger } from 'redux-logger'; import rootReducer from '../reducers'; import DevTools from '../containers/DevTools'; import persistState from 'redux-localstorage'; +const env = process.env.NODE_ENV; const configureStore = preloadedState => { const store = createStore( @@ -11,7 +12,9 @@ const configureStore = preloadedState => { preloadedState, compose( persistState(['userState', { key: 'eMgr' }]), - applyMiddleware(thunk, createLogger()), + env === 'test' + ? applyMiddleware(thunk) + : applyMiddleware(thunk, createLogger()), DevTools.instrument() ) ); @@ -26,4 +29,6 @@ const configureStore = preloadedState => { return store; }; -export default configureStore(); +const configured = configureStore(); + +export default configured; diff --git a/client/src/store/configureStore.prod.js b/client/src/store/configureStore.prod.js index 52443d3..0711cda 100644 --- a/client/src/store/configureStore.prod.js +++ b/client/src/store/configureStore.prod.js @@ -13,4 +13,6 @@ const configureStore = preloadedState => ) ); -export default configureStore(); +const store = configureStore(); + +export default store; diff --git a/client/src/test/login.test.js b/client/src/test/login.test.js index 4aac417..9d8ad05 100644 --- a/client/src/test/login.test.js +++ b/client/src/test/login.test.js @@ -1,6 +1,7 @@ // Login Form Full DOM Rendering Test import React from 'react'; import Login from '../containers/Login/Login'; +import LoginForm from '../components/LoginForm/LoginForm'; import { mount } from 'enzyme'; import { Provider } from 'react-redux'; import store from '../store/configureStore'; @@ -29,15 +30,29 @@ describe('', () => { expect(wrapper.find('form').length).toEqual(1); }); - it('Component should trigger login', () => { + it('Should check if empty form is invalid', () => { + expect( + wrapper.find(LoginForm).instance().ref.wrappedInstance.props.valid + ).toEqual(false); + }); + + it('Should check if fields can be edited', () => { wrapper .find('input[name="username"]') .simulate('change', { target: { value: 'jack' } }); wrapper .find('input[name="password"]') .simulate('change', { target: { value: '123456' } }); - wrapper.find('form').simulate('submit'); + }); + it('Should check if filled form is valid', () => { + expect( + wrapper.find(LoginForm).instance().ref.wrappedInstance.props.valid + ).toEqual(true); + }); + + it('SHould check if login is triggered', () => { + wrapper.find('form').simulate('submit'); expect(mockLogin).toHaveBeenCalledTimes(1); expect(mockLogin).toHaveBeenCalledWith({