Skip to content

Commit

Permalink
Improved test for Team Component
Browse files Browse the repository at this point in the history
  • Loading branch information
ashutoshc8101 committed Jan 6, 2021
1 parent 1a2475b commit 7e00a02
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/__tests__/components/About/Team/Team.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,35 @@
import React from 'react';
import Team from '../../../../components/About/Team';
import { shallow } from 'enzyme';

import { shallow, mount } from 'enzyme';
import Card from '@material-ui/core/Card';
// eslint-disable-next-line no-undef
jest.mock('../../../../apis/index');
// eslint-disable-next-line no-undef
jest.mock('../../../../constants/team');
describe('<Team />', () => {
it('render Team without crashing', () => {
shallow(<Team location={{ pathname: '/team' }} />);
});

it('renders contributor data fetched from api', (done) => {
// eslint-disable-next-line no-undef
const wrapper = mount(<Team />);
const testNames = [
'MEMBER 1',
'MEMBER 2',
'MANAGER 1Event Manager',
'MANAGER 2Community and Project Manager',
'contributer1',
'contributer2',
];
setTimeout(() => {
wrapper.update();
const cards = wrapper.find(Card.displayName);
// eslint-disable-next-line max-nested-callbacks
cards.forEach((card, i) => {
expect(card.text() === testNames[i]).toBeTruthy();
});
done();
});
});
});
18 changes: 18 additions & 0 deletions src/apis/__mocks__/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
export async function getContributors() {
const data = [
{
avatar: 'https://avatars3.githubusercontent.com/u/contributer1_avatar',
github: 'https://github.com/contributer1',
name: 'contributer1',
},
{
avatar: 'https://avatars0.githubusercontent.com/u/contributer2_avatar',
github: 'https://github.com/contributer2',
name: 'contributer2',
},
];

return new Promise((resolve, reject) => {
resolve(data);
});
}
1 change: 1 addition & 0 deletions src/components/About/Team/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ const Team = (props) => {

(async function fetchContributorsList() {
const response = await getContributors();

let flags = [],
output = [];
for (let i = 0; i < response.length; i++) {
Expand Down
43 changes: 43 additions & 0 deletions src/constants/__mocks__/team.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
const TEAM_MEMBERS = {
MENTORS: [
{
name: 'MEMBER 1',
github: 'http://github.com/member1',
avatar: 'test_member.png',
twitter: 'https://twitter.com/member1',
linkedin: 'https://www.linkedin.com/in/member1/',
blog: '#',
},
{
name: 'MEMBER 2',
github: 'https://github.com/member2',
avatar: 'test_member.png',
twitter: 'https://twitter.com/member2',
linkedin: 'https://www.linkedin.com/in/member2/',
blog: '#',
},
],

MANAGERS: [
{
name: 'MANAGER 1',
github: '#',
avatar: 'test_member.png',
designation: 'Event Manager',
twitter: 'https://twitter.com/manager1',
linkedin: 'https://www.linkedin.com/in/manager1/',
blog: '#',
},
{
name: 'MANAGER 2',
github: 'https://github.com/Manager2',
avatar: 'test_member.png',
designation: 'Community and Project Manager',
twitter: 'https://twitter.com/manager2',
linkedin: 'https://www.linkedin.com/in/manager2/',
blog: '#',
},
],
};

export default TEAM_MEMBERS;
Binary file added src/images/members/test_member.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 7e00a02

Please sign in to comment.