Skip to content

Commit

Permalink
Merge pull request #29 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 15, 2018
2 parents c52984e + 8809026 commit fdbeda0
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 4 deletions.
3 changes: 2 additions & 1 deletion client/src/modules/common/Modals/AddIntegration.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@ const customStyles = {
}
};

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

const AddIntegration = ({ isModalOpen, closeModal }) => (
<Modal
isOpen={isModalOpen}
contentLabel="Add Integration"
onRequestClose={closeModal}
style={customStyles}
ariaHideApp="false"
>
<p className="integration-header">Select an integration to add</p>
<p className="integration-tools">Github Repo</p>
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 @@ -8,7 +8,7 @@ import createAdminRequest from '../../../redux/actions/requests';
import { warningMessage, successMessage } from '../../../toasts';
import errorFormatter from '../../../utils/errorFormatter.json';

class Navbar extends Component {
export class Navbar extends Component {
static propTypes = {
signOut: PropTypes.func.isRequired,
createAdminRequest: PropTypes.func.isRequired,
Expand Down Expand Up @@ -108,6 +108,7 @@ class Navbar extends Component {
</NavLink>
{showIcon && (
<a
id="showSearchBar"
href="#!"
onClick={() => this.toggleState('showSearchBar')}
className=" float-right sidenav-trigger"
Expand All @@ -119,6 +120,7 @@ class Navbar extends Component {
{this.props.showIcon && (
<li>
<a
id="showSearchBar2"
href="#!"
onClick={() => this.toggleState('showSearchBar')}
>
Expand Down Expand Up @@ -200,6 +202,7 @@ class Navbar extends Component {
<ul className="tabs tabs-transparent">
<li className="tab">
<a
id="projects"
href="#Projects"
onClick={event => switchContent(event, 'project')}
>
Expand All @@ -208,6 +211,7 @@ class Navbar extends Component {
</li>
<li className="tab">
<a
id="members"
href="#members"
onClick={event => switchContent(event, 'member')}
>
Expand All @@ -216,6 +220,7 @@ class Navbar extends Component {
</li>
<li className="tab">
<a
id="account"
href="#account"
onClick={event => switchContent(event, 'account')}
>
Expand All @@ -242,6 +247,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 Repo');
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');
});
});
73 changes: 73 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,73 @@
import React from 'react';
import { shallow } from 'enzyme';
import { Navbar } from '../../../../modules/common/Navbar';

describe('<Navbar />', () => {
let wrapper;
const onClick = 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}
/>);
});
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 fdbeda0

Please sign in to comment.