diff --git a/__tests__/tests/components/RepositoryProfile.js b/__tests__/tests/components/RepositoryProfile.js new file mode 100644 index 000000000..bb6eb2e36 --- /dev/null +++ b/__tests__/tests/components/RepositoryProfile.js @@ -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('', () => { + it('should render the Icon component if loading is false and repository language is not null', () => { + const wrapper = shallow( + + ); + 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( + + ); + 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( + + ); + 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(); + 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( + + ); + + wrapper + .find({ nativeId: 'repository-navigate-container' }) + .simulate('press'); + + expect(navigateMock).toHaveBeenCalledWith('Repository', { + repository: true, + }); + }); +}); diff --git a/src/components/repository-profile.component.js b/src/components/repository-profile.component.js index 4928b3b71..0623e3385 100644 --- a/src/components/repository-profile.component.js +++ b/src/components/repository-profile.component.js @@ -164,13 +164,17 @@ export const RepositoryProfile = ({ {repository.fork && ( - + {repository.parent && ( {translate('repository.main.forkedFromMessage', locale)} navigation.navigate('Repository', { diff --git a/testenv.js b/testenv.js index 56476a06c..d1ad4482f 100644 --- a/testenv.js +++ b/testenv.js @@ -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', () => ({}));