Skip to content

Commit

Permalink
Merge pull request #43 from andela/ch-common-module-tests-161117046
Browse files Browse the repository at this point in the history
#161117046 Common Module Tests
  • Loading branch information
Chieze-Franklin committed Oct 21, 2018
2 parents 621f618 + 51c355a commit ab4aabf
Show file tree
Hide file tree
Showing 9 changed files with 155 additions and 3 deletions.
1 change: 1 addition & 0 deletions client/src/modules/common/Modals/AddIntegration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import github from '../../../../public/resources/images/github.png';
import pt from '../../../../public/resources/images/pt.png';
import slack from '../../../../public/resources/images/slack.png';

// Modal.setAppElement('#app');

const AddIntegration = ({ isModalOpen, closeModal }) => (
<Modal
Expand Down
8 changes: 7 additions & 1 deletion client/src/modules/common/Navbar/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { warningMessage, successMessage } from '../../../toasts';
import errorFormatter from '../../../utils/errorFormatter.json';
import { clearRequestState } from '../../../redux/actions';

class Navbar extends Component {
export class Navbar extends Component {
static propTypes = {
signOut: PropTypes.func.isRequired,
makeRequest: PropTypes.func.isRequired,
Expand Down Expand Up @@ -130,6 +130,7 @@ class Navbar extends Component {
</NavLink>
{showIcon && (
<a
id="showSearchBar"
href="#!"
onClick={() => this.toggleState('showSearchBar')}
className=" float-right sidenav-trigger"
Expand All @@ -141,6 +142,7 @@ class Navbar extends Component {
{this.props.showIcon && (
<li>
<a
id="showSearchBar2"
href="#!"
onClick={() => this.toggleState('showSearchBar')}
>
Expand Down Expand Up @@ -223,6 +225,7 @@ class Navbar extends Component {
<ul className="tabs tabs-transparent">
<li className="tab">
<a
className="projects"
href="#Projects"
onClick={event => switchContent(event, 'project')}
>
Expand All @@ -231,6 +234,7 @@ class Navbar extends Component {
</li>
<li className="tab">
<a
className="members"
href="#members"
onClick={event => switchContent(event, 'member')}
>
Expand All @@ -239,6 +243,7 @@ class Navbar extends Component {
</li>
<li className="tab">
<a
className="account"
href="#account"
onClick={event => switchContent(event, 'account')}
>
Expand All @@ -265,6 +270,7 @@ class Navbar extends Component {
</label>
{/* eslint-disable-next-line */}
<i
id="showSearchBar3"
className="material-icons"
onClick={() => this.toggleState('showSearchBar')}
>
Expand Down
4 changes: 2 additions & 2 deletions client/src/modules/common/Preloader/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import PropTypes from 'prop-types';
*
* @returns {JSX.Element} React element
*/
const Preloader = ({ isLoading: { isLoading } }) => (
export const Preloader = ({ isLoading: { isLoading } }) => (
<React.Fragment>
{isLoading && (
<div className="progress preloader">
Expand All @@ -18,7 +18,7 @@ const Preloader = ({ isLoading: { isLoading } }) => (
)}
</React.Fragment>
);
const mapStateToProps = state => ({
export const mapStateToProps = state => ({
isLoading: state.isLoading
});

Expand Down
11 changes: 11 additions & 0 deletions client/src/tests/modules/common/Footer/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import React from 'react';
import { shallow } from 'enzyme';
import Footer from '../../../../modules/common/Footer';

describe('<Footer />', () => {
it('should mount without crashing', () => {
const wrapper = shallow(<Footer />);
expect(wrapper.find('.col').props().children[0]).toBe('© ');
expect(wrapper.find('.col').props().children[1]).toBe(2018);
});
});
14 changes: 14 additions & 0 deletions client/src/tests/modules/common/Modals/AddIntegration.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import AddIntegration from '../../../../modules/common/Modals/AddIntegration';

describe('<AddIntegration />', () => {
it('should mount without crashing', () => {
const wrapper = shallow(<AddIntegration />);
expect(wrapper.find('p').get(0).props.children).toBe('Select an integration to add');
expect(wrapper.find('p').get(1).props.children).toBe('Github Repository');
expect(wrapper.find('p').get(2).props.children).toBe('Pivotal Tracker');
expect(wrapper.find('p').get(3).props.children).toBe('Slack Channel (private)');
expect(wrapper.find('p').get(4).props.children).toBe('Slack Channel (public)');
});
});
14 changes: 14 additions & 0 deletions client/src/tests/modules/common/Modals/AddMember.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import React from 'react';
import { shallow } from 'enzyme';
import AddMember from '../../../../modules/common/Modals/AddMember';

describe('<AddMember />', () => {
it('should mount without crashing', () => {
const wrapper = shallow(<AddMember />);
expect(wrapper.find('h4').props().children).toBe('Add member');
expect(wrapper.find('i').props().children).toBe('account_circle');
expect(wrapper.find('label').props().children).toBe('Find member');
expect(wrapper.find('a').get(0).props.children).toBe('Back');
expect(wrapper.find('a').get(1).props.children).toBe('Add');
});
});
75 changes: 75 additions & 0 deletions client/src/tests/modules/common/Navbar/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Navbar } from '../../../../modules/common/Navbar';

describe('<Navbar />', () => {
let wrapper;
const onClick = jest.fn();
const checkUserRequest = jest.fn();
const auth = {
name: 'Taps Client'
};
const requestsReducer = {
error: '',
success: ''
};
document.getElementById = jest.fn(() => ({
focus: jest.fn()
}));
beforeEach(() => {
wrapper = shallow(<Navbar
switchContent={onClick}
showTabs
showIcon
auth={auth}
handleSubmit={onClick}
signOut={onClick}
id="search"
requestsReducer={requestsReducer}
checkUserRequest={checkUserRequest}
/>);
});
it('should mount without crashing', () => {
expect(wrapper.length).toBe(1);
});
it('should click projects', () => {
wrapper.find('.projects').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should click members', () => {
wrapper.find('.members').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should click account', () => {
wrapper.find('.account').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should show search bar', () => {
wrapper.find('#showSearchBar').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should show search bar', () => {
wrapper.find('#showSearchBar2').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should show search bar', () => {
wrapper.find('#showSearchBar3').simulate('click');
expect(onClick).toHaveBeenCalled();
});
it('should test handleSearch method', () => {
wrapper.instance().handleSearch({ preventDefault: jest.fn() });
expect(wrapper.instance().state.showSearchBar).toBe(false);
});
it('should test signOut method', () => {
wrapper.instance().signOut({ preventDefault: jest.fn() });
expect(onClick).toHaveBeenCalled();
});
it('should test toggleState', () => {
jest.useFakeTimers();
wrapper.instance().toggleState('showSearchBar');
setTimeout(() => {
document.getElementById();
}, 100);
jest.runAllTimers();
});
});
19 changes: 19 additions & 0 deletions client/src/tests/modules/common/Preloader/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Preloader, mapStateToProps } from '../../../../modules/common/Preloader';

const isLoading = {
isLoading: true
};

describe('<Preloader />', () => {
it('should mount without crashing', () => {
const wrapper = shallow(<Preloader isLoading={isLoading} />);
expect(wrapper.length).toBe(1);
expect(wrapper.exists('.indeterminate')).toEqual(true);
});
it('should test mapStateToProps', () => {
const newState = mapStateToProps(isLoading);
expect(newState.isLoading).toBe(true);
});
});
12 changes: 12 additions & 0 deletions client/src/tests/modules/common/Spinner/Spinner.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { shallow } from 'enzyme';
import Spinner from '../../../../modules/common/Spinner/Spinner';


describe('<Spinner />', () => {
it('should mount without crashing', () => {
const wrapper = shallow(<Spinner />);
expect(wrapper.length).toBe(1);
expect(wrapper.exists('.spinner')).toEqual(true);
});
});

0 comments on commit ab4aabf

Please sign in to comment.