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

#161116965 Create tests for create team module #18

Merged
merged 1 commit into from
Oct 16, 2018
Merged
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
2 changes: 1 addition & 1 deletion client/src/modules/CreateTeam/container/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ export class CreateTeam extends Component {
}
}

const mapStateToProps = ({ teams, isLoading }) => ({
export const mapStateToProps = ({ teams, isLoading }) => ({
teams: teams,
apiMessage: teams.apiResponse,
isFetching: isLoading
Expand Down
1 change: 1 addition & 0 deletions client/src/tests/mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = 'test-file-stub';
38 changes: 38 additions & 0 deletions client/src/tests/modules/CreateTeam/components/Form.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import React from 'react';
import { shallow } from 'enzyme';

import Form from '../../../../modules/CreateTeam/components/Form';

describe('Create Team Form', () => {
const props = {
handleSubmit: jest.fn(),
handleChange: jest.fn(),
name: 'taps-client',
desc: 'taps-client',
checked: true,
submitting: true
};

let wrapper = shallow(<Form {...props} />);
it('Should render form element with submitting props as true', () => {
expect(wrapper.find('form').length).toBe(1);
});

wrapper = shallow(<Form {...props} />);
it('Should render form element with submitting props as false', () => {
props.submitting = false;

wrapper = shallow(<Form {...props} />);

expect(wrapper.find('form').length).toBe(1);
});

it('Should render form element with out name and description', () => {
props.name = '';
props.desc = '';

wrapper = shallow(<Form {...props} />);

expect(wrapper.find('form').length).toBe(1);
});
});
128 changes: 128 additions & 0 deletions client/src/tests/modules/CreateTeam/container/index.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import { shallow } from 'enzyme';

import { CreateTeam, mapStateToProps } from '../../../../modules/CreateTeam/container';
import props, { state, over255Description } from '../mock/containerMock';

global.M = {
AutoInit: () => {},
Dropdown: { init: () => {} }
};

describe('CreateTeam container component', () => {
let CreateTeamWrapper;
it('calls componentDidMount lifecycle', () => {
const spy = jest.spyOn(CreateTeam.prototype, 'componentDidMount');

CreateTeamWrapper = shallow(<CreateTeam {...props} />);

expect(spy).toHaveBeenCalled();

expect(CreateTeamWrapper.find('Fragment').length).toBe(1);
});

it('calls componentWillReceive props lifecycle', () => {
const spy = jest.spyOn(CreateTeam.prototype, 'componentWillReceiveProps');

CreateTeamWrapper.setProps(props);

expect(spy).toHaveBeenCalled();

props.teams = {};

CreateTeamWrapper.setProps(props);

expect(spy).toHaveBeenCalled();

expect(CreateTeamWrapper.find('Fragment').length).toBe(1);
});

it('should call handleSubmit method on form', () => {
const event = {
preventDefault: () => true,
};

CreateTeamWrapper.instance().setState(state);

CreateTeamWrapper.instance().handleSubmit(event);

state.description = over255Description;

CreateTeamWrapper.instance().setState(state);

CreateTeamWrapper.instance().handleSubmit(event);

state.description = 'abac';

CreateTeamWrapper.instance().setState(state);

CreateTeamWrapper.instance().handleSubmit(event);

expect(CreateTeamWrapper.find('Form').length).toBe(1);
});

it('should call handleChange method on form', () => {
const event = {
preventDefault: () => true,
target: {
name: 'taps',
}
};

CreateTeamWrapper.instance().setState(state);

CreateTeamWrapper.instance().handleChange(event);

expect(CreateTeamWrapper.find('Form').length).toBe(1);
});

it('should call menuChange method on form', () => {
const event = {
preventDefault: () => true,
target: {
name: 'taps',
}
};

CreateTeamWrapper.instance().setState(state);

CreateTeamWrapper.instance().menuChange(event, {});

expect(CreateTeamWrapper.find('Form').length).toBe(1);
});

it('calls componentWillUnmount props lifecycle', () => {
const spy = jest.spyOn(CreateTeam.prototype, 'componentWillUnmount');

CreateTeamWrapper.unmount();

expect(spy).toHaveBeenCalled();
});

it('should call the handleModalState method', () => {
props.teams.showModal = true;

CreateTeamWrapper = shallow(<CreateTeam {...props} />);

CreateTeamWrapper.find('VisualFeedback').props().modalState();

expect(CreateTeamWrapper.find('Form').length).toBe(1);
});
});

describe('Test for mapStateToProps', () => {
const state = {
teams: 'taps',
isLoading: false,
};

const result = mapStateToProps(state);

it('should have props teams', () => {
expect(result.teams).toBe('taps');
});

it('should have props isFetching', () => {
expect(result.isFetching).toBe(false);
});
});
30 changes: 30 additions & 0 deletions client/src/tests/modules/CreateTeam/mock/containerMock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
export const over255Description = 'jbjbbkbnkejkkbjekbjkebjbnjbkbjbjljbjbblkbnjbnjbnbwnjnjnbjnjbnjbnjbnbjnbnbjnjbnjbnbjnbsjsbnjbnjbnjsnbjbnjnjbbjnjbbnjnbjsnjbnbjsnjbnbjbnjbsjnjbnjbnjbnsjbnnbbnbnbnbbnbnbnbenoeooernboboebnoonoeonoenneoneoeoeeoeeobooboboe jhghgghg hbgytt gytgygt 3yg3 gvw uygrhwn wu7tyt uttg th3t3nw kwhgi3';

export const state = {
name: 'name',
description: '',
visibility: false,
submitting: false,
integrations: {
github: []
}
};

const props = {
teams: {
data: {
data: ['aba', 'abc', 'abc', 'gers']
}
},
createTeam: jest.fn(data => data),
clearTeams: jest.fn(),
history: {
push: jest.fn()
},
isFetching: {
isLoading: true
},
modalState: jest.fn()
};

export default props;
20 changes: 0 additions & 20 deletions client/src/tests/modules/createTeams/component/form.test.js

This file was deleted.

50 changes: 0 additions & 50 deletions client/src/tests/modules/createTeams/container/index.test.js

This file was deleted.

3 changes: 1 addition & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
module.exports = {
'verbose': true,
'roots': [
'<rootDir>/client'
],
Expand All @@ -15,7 +14,7 @@ module.exports = {
'\\.(css|less|scss)$': '<rootDir>/client/src/tests/__mocks__/assetsTransformer.js',
},
'collectCoverage': true,
'collectCoverageFrom': ["client/src/**/*.{js,x}"],
'collectCoverageFrom': ["client/src/**/*.jsx", "client/src/redux/**/*.js"],
'testPathIgnorePatterns': [
'<rootDir>/client/src/tests/__mocks__',
],
Expand Down
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.