Skip to content

Commit

Permalink
chore: add SidebarContainer tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Chris Maina committed Apr 2, 2019
1 parent 38c2753 commit a5a9668
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';

import { RedemptionsContainer } from '../RedemptionsContainer';

Expand Down Expand Up @@ -28,7 +28,7 @@ describe('<RedemptionsContainer />', () => {
fetchSocietyInfoRequest: jest.fn(),
fetchSocietyRedemptionsRequest: jest.fn(),
};
const shallowWrapper = shallow(<RedemptionsContainer {...props} />);
const shallowWrapper = mount(<RedemptionsContainer {...props} />);

it('has a 3 ButtonComponents', () => {
expect(shallowWrapper.find('ButtonComponent')).toHaveLength(3);
Expand All @@ -44,7 +44,7 @@ describe('<RedemptionsContainer />', () => {

it('invokes fetchSocietyRedemptionsRequest in componentDidUpdate when societyName props change', () => {
const instance = shallowWrapper.instance();
const spy = jest.spyOn(instance.props, 'fetchSocietyRedemptionsRequest');
const spy = jest.spyOn(instance.props, 'fetchSocietyInfoRequest');
shallowWrapper.setProps({ societyName: 'istelle' });
expect(spy).toHaveBeenCalled();
});
Expand Down
36 changes: 26 additions & 10 deletions src/app/Sidebar/components/tests/SidebarContainer.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,37 @@
import React from 'react';
import { shallow } from 'enzyme';
import { mount } from 'enzyme';
import { SidebarContainer } from '../SidebarContainer';
import { BrowserRouter as Router } from 'react-router-dom';

describe('<SidebarContainer />', () => {
const props = {
className: '',
userRole: {},
fetchUserRole: jest.fn(),
toggleSidebarState: jest.fn(),
}
const shallowWrapper = shallow(<SidebarContainer {...props} />);
const setUpWrapper = ({ userRole = {} } = {}) => {
const props = {
userRole,
userId: '',
className: '',
fetchUserRole: jest.fn(),
toggleSidebarState: jest.fn(),
};
return mount(<Router><SidebarContainer {...props} /></Router>);
};

it('should have the a nav item with text Settings', () => {
expect(shallowWrapper.find('.sidebar_nav-label--footer').html()).toContain('Settings');
const wrapper = setUpWrapper();
expect(wrapper.find('.sidebar_nav-label--footer').html()).toContain('Settings');
});

it('has LogoComponent', () => {
expect(shallowWrapper.find('LogoComponent')).toHaveLength(1);
const wrapper = setUpWrapper();
expect(wrapper.find('LogoComponent')).toHaveLength(1);
});

it('has Verify Activities navigation item', () => {
const wrapper = setUpWrapper({ userRole: { 'society secretary': '12345' }});
expect(wrapper.html()).toContain('Verify-activities');
});

it('has Redemptions navigation item', () => {
const wrapper = setUpWrapper({ userRole: { 'society president': '12345' }});
expect(wrapper.html()).toContain('Redemptions');
});
});

0 comments on commit a5a9668

Please sign in to comment.