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

Improved test for Team Component (fixes #3639) #3638

Closed
wants to merge 1 commit into from
Closed
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
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);
});
}
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.