Skip to content
Merged
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
83 changes: 83 additions & 0 deletions __tests__/tests/components/RepositoryProfile.js
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' });
Copy link
Copy Markdown
Member

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' });

Copy link
Copy Markdown
Member Author

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


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,
});
});
});
6 changes: 5 additions & 1 deletion src/components/repository-profile.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,13 +164,17 @@ export const RepositoryProfile = ({
</Text>

{repository.fork && (
<Text style={[styles.subtitle, styles.subtitleFork]}>
<Text
nativeId="repository-fork-container"
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The 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.
nativeId is used for e2e tests Docs About nativeId

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', {
Expand Down
2 changes: 2 additions & 0 deletions testenv.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => ({}));
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mocking this so we don't get an error.