-
Notifications
You must be signed in to change notification settings - Fork 783
test: Add RepositoryProfile tests #531
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import { Icon } from 'react-native-elements'; | ||
|
||
import { RepositoryProfile } from 'components'; | ||
|
||
const defaultProps = { | ||
repository: { | ||
fork: true, | ||
parent: true, | ||
language: 'en', | ||
}, | ||
starred: false, | ||
navigation: { | ||
navigate() {}, | ||
}, | ||
loading: false, | ||
subscribed: false, | ||
locale: 'en', | ||
}; | ||
|
||
describe('<RepositoryProfile />', () => { | ||
it('should render the Icon component if loading is false and repository language is not null', () => { | ||
const wrapper = shallow( | ||
<RepositoryProfile {...defaultProps} language={false} /> | ||
); | ||
const theIcon = wrapper.find({ name: 'fiber-manual-record' }); | ||
|
||
expect(theIcon.length).toBeTruthy(); | ||
}); | ||
|
||
it('should not render the Icon component if loading is true', () => { | ||
const wrapper = shallow( | ||
<RepositoryProfile {...defaultProps} loading={true} /> | ||
); | ||
const theIcon = wrapper.find({ name: 'fiber-manual-record' }); | ||
|
||
expect(theIcon.length).toBeFalsy(); | ||
}); | ||
|
||
it('should not render the Icon component if repository language is null', () => { | ||
const wrapper = shallow( | ||
<RepositoryProfile | ||
{...defaultProps} | ||
repository={{ | ||
...defaultProps.repository, | ||
language: null, | ||
}} | ||
/> | ||
); | ||
const theIcon = wrapper.find({ name: 'fiber-manual-record' }); | ||
|
||
expect(theIcon.length).toBeFalsy(); | ||
}); | ||
|
||
it('should render repository fork text container if repository.fork is true', () => { | ||
const wrapper = shallow(<RepositoryProfile {...defaultProps} />); | ||
const repositoryContainer = wrapper.find({ | ||
nativeId: 'repository-fork-container', | ||
}); | ||
|
||
expect(repositoryContainer.length).toBeTruthy(); | ||
}); | ||
|
||
it('should call navigation.navigate onPress repository parent', () => { | ||
const navigateMock = jest.fn(); | ||
const navigation = { | ||
navigate: navigateMock, | ||
}; | ||
|
||
const wrapper = shallow( | ||
<RepositoryProfile {...defaultProps} navigation={navigation} /> | ||
); | ||
|
||
wrapper | ||
.find({ nativeId: 'repository-navigate-container' }) | ||
.simulate('press'); | ||
|
||
expect(navigateMock).toHaveBeenCalledWith('Repository', { | ||
repository: true, | ||
}); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -164,13 +164,17 @@ export const RepositoryProfile = ({ | |
</Text> | ||
|
||
{repository.fork && ( | ||
<Text style={[styles.subtitle, styles.subtitleFork]}> | ||
<Text | ||
nativeId="repository-fork-container" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I had to add this prop so it was possible to target this specific component in its test file. |
||
style={[styles.subtitle, styles.subtitleFork]} | ||
> | ||
{repository.parent && ( | ||
<Text> | ||
<Text> | ||
{translate('repository.main.forkedFromMessage', locale)} | ||
</Text> | ||
<Text | ||
nativeId="repository-navigate-container" | ||
style={{ ...fonts.fontPrimaryBold }} | ||
onPress={() => | ||
navigation.navigate('Repository', { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,3 +29,5 @@ jest.mock('react-native-i18n', () => { | |
jest.mock('react-native-cookies', () => ({})); | ||
|
||
jest.mock('react-native-code-push', () => ({})); | ||
|
||
jest.mock('react-native-safari-view', () => ({})); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Mocking this so we don't get an error. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a bit weird to use "the" in a variable name (unless you have a specific reason?) How about just
const icon = wrapper.find({ name: 'fiber-manual-record' });
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that works too. Will update it on my next PR