Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redux form validation test in Login #250

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions client/src/store/configureStore.dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@ 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(
rootReducer,
preloadedState,
compose(
persistState(['userState', { key: 'eMgr' }]),
applyMiddleware(thunk, createLogger()),
env === 'test'
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need to remove redux logs in test env?

? applyMiddleware(thunk)
: applyMiddleware(thunk, createLogger()),
DevTools.instrument()
)
);
Expand All @@ -26,4 +29,6 @@ const configureStore = preloadedState => {
return store;
};

export default configureStore();
const configured = configureStore();

export default configured;
4 changes: 3 additions & 1 deletion client/src/store/configureStore.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,6 @@ const configureStore = preloadedState =>
)
);

export default configureStore();
const store = configureStore();

export default store;
19 changes: 17 additions & 2 deletions client/src/test/login.test.js
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -29,15 +30,29 @@ describe('<Login />', () => {
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({
Expand Down