-
Notifications
You must be signed in to change notification settings - Fork 23
/
updateProfile.spec.jsx
68 lines (60 loc) · 2.1 KB
/
updateProfile.spec.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import React from 'react';
import { shallow } from 'enzyme';
import thunk from 'redux-thunk';
import configureMockStore from 'redux-mock-store';
import ConnectedUpdateProfile, { UpdateProfile }
from '../../../components/Dashboard/UpdateProfile';
import { mockStoreData } from '../../__mocks__/mockData';
let props = {
...mockStoreData.authReducer,
updateProfile: jest.fn(() => Promise.resolve(1)),
};
const middleware = [thunk];
const mockStore = configureMockStore(middleware);
const store = mockStore({ ...mockStoreData });
describe('UpdateProfile Component', () => {
it('renders without crashing', () => {
const wrapper = shallow(<UpdateProfile { ...props } />);
expect(wrapper).toBeDefined();
expect(wrapper.getElement().type).toBe('div');
});
it('should redirect to login page if user is not logged in', () => {
props = { ...props, isLoggedIn: false };
const wrapper = shallow(<UpdateProfile { ...props } />);
expect(wrapper).toBeDefined();
expect(wrapper.find('LoginRedirect').length).toBe(1);
expect(wrapper.find('div').length).toBe(0);
});
it('should call handleChange when input fields change value', () => {
const wrapper = shallow(<UpdateProfile { ...props } />);
const handleChangeSpy = jest.spyOn(
wrapper.instance(), 'handleChange'
);
const event = {
preventDefault: jest.fn(),
target: {
value: 'Tolu',
name: 'firstName'
}
};
wrapper.instance().handleChange(event);
expect(handleChangeSpy).toHaveBeenCalledTimes(1);
});
it('should call handleSubmit when form is submited', () => {
const wrapper = shallow(<UpdateProfile { ...props } />);
const handleSubmitSpy = jest.spyOn(
wrapper.instance(), 'handleSubmit'
);
const event = {
preventDefault: jest.fn(),
};
wrapper.instance().handleSubmit(event);
expect(handleSubmitSpy).toHaveBeenCalledTimes(1);
});
it('should render the connected component', () => {
const connectedComponent = shallow(
<ConnectedUpdateProfile { ...props } store={store} />
);
expect(connectedComponent.length).toBe(1);
});
});