-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Write component tests for ProjectInfo, ProjectSummary
- Loading branch information
Showing
4 changed files
with
153 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React from 'react' | ||
import { mount } from 'enzyme' | ||
import ProjectSummary from '../../components/ProjectSummary' | ||
import { StaticRouter } from 'react-router' | ||
import project from '../../fixtures/projectInfo' | ||
|
||
describe('ProjectSummary', () => { | ||
let wrapper | ||
const context = {} | ||
const props = { | ||
project | ||
} | ||
beforeEach(() => { | ||
wrapper = mount( | ||
<StaticRouter context={context}> | ||
<ProjectSummary {...props} /> | ||
</StaticRouter> | ||
) | ||
}) | ||
|
||
it('displays a link to GitHub repo', () => { | ||
project.sourceRepositories[0].url = 'https://github.com/AgileVentures/WebsiteOne' | ||
let linkToRepo = wrapper.find('a').filterWhere(item => { | ||
return item.prop('href') === project.sourceRepositories[0].url | ||
}) | ||
|
||
expect(linkToRepo.text()).toEqual('WebsiteOne') | ||
}) | ||
|
||
it('handles repo urls with ending in forward slashes', () => { | ||
project.sourceRepositories[0].url = 'https://github.com/AgileVentures/WebsiteOne/' | ||
wrapper = mount( | ||
<StaticRouter context={context}> | ||
<ProjectSummary {...props} /> | ||
</StaticRouter> | ||
) | ||
let linkToRepo = wrapper.find('a').filterWhere(item => { | ||
return item.prop('href') === project.sourceRepositories[0].url | ||
}) | ||
expect(linkToRepo.text()).toEqual('WebsiteOne') | ||
}) | ||
|
||
it('displays a spinner when no project is in the props', () => { | ||
wrapper = mount( | ||
<StaticRouter context={context}> | ||
<ProjectSummary /> | ||
</StaticRouter> | ||
) | ||
expect(wrapper.find('Loader').props().loading).toBe(true) | ||
}) | ||
|
||
it("displays a project's image if there is one", () => { | ||
project.image_url = 'http://i.imgur.com/23ePvyN.jpg' | ||
wrapper = mount( | ||
<StaticRouter context={context}> | ||
<ProjectSummary {...props} /> | ||
</StaticRouter> | ||
) | ||
let projectsImageUrl = wrapper.find('Image').filterWhere(item => { | ||
return item.hasClass('project-info-image') | ||
}) | ||
expect(projectsImageUrl.props().src).toEqual(project.image_url) | ||
}) | ||
|
||
it("displays a member's name if there is one", () => { | ||
project.members[0].first_name = 'Matt' | ||
project.members[0].last_name = 'Rider' | ||
wrapper = mount( | ||
<StaticRouter context={context}> | ||
<ProjectSummary {...props} /> | ||
</StaticRouter> | ||
) | ||
let linkToMember = wrapper.find('Link').filterWhere(item => { | ||
return item.prop('to') === '/users/2' | ||
}) | ||
expect(linkToMember.text()).toEqual('Matt Rider') | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import React from 'react' | ||
import { shallow } from 'enzyme' | ||
import { ProjectInfo } from '../../containers/ProjectInfo' | ||
import project from '../../fixtures/projectInfo' | ||
|
||
describe('ProjectInfo', () => { | ||
let wrapper | ||
const props = { | ||
match: { params: { slug: 'websiteone' } }, | ||
project: { | ||
slug: 'rundfunk-mitbestimmen' | ||
}, | ||
fetchProjectInfo: jest.fn(), | ||
setLastLocation: () => {}, | ||
location: { pathname: '/projects/websiteone' } | ||
} | ||
beforeEach(() => { | ||
wrapper = shallow(<ProjectInfo {...props} />) | ||
}) | ||
|
||
it('renders ProjectSummary', () => { | ||
expect(wrapper.find('ProjectSummary')).toBeTruthy() | ||
}) | ||
|
||
it('calls fetchProjectInfo if the project slug is different from the project slug in the url', () => { | ||
expect(props.fetchProjectInfo).toHaveBeenLastCalledWith(props.match.params.slug) | ||
}) | ||
|
||
it('sets state if the project props are updated', () => { | ||
wrapper.setProps({ project }) | ||
expect(wrapper.state().project).toEqual(project) | ||
}) | ||
|
||
it('sets state if the project slug is the same as in the url', () => { | ||
wrapper = shallow(<ProjectInfo {...props} project={project} />) | ||
expect(wrapper.state().project).toEqual(project) | ||
}) | ||
}) |