Skip to content

test: add tests for NotificationIcon and RepositorySectionTitle #677

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

Merged
merged 1 commit into from
Dec 22, 2017
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
10 changes: 10 additions & 0 deletions .all-contributorsrc
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,16 @@
"contributions": [
"doc"
]
},
{
"login": "ZahraTee",
"name": "Zahra Traboulsi",
"avatar_url": "https://avatars0.githubusercontent.com/u/5565340?v=4",
"profile": "http://www.zahra.tech",
"contributions": [
"code",
"test"
]
Copy link
Member

Choose a reason for hiding this comment

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

🎉

}
]
}
2 changes: 1 addition & 1 deletion CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ Thank you to all the people who have already contributed to GitPoint!
| [<img src="https://avatars3.githubusercontent.com/u/14539?v=4" width="100px;"/><br /><sub><b>Peter Blazejewicz</b></sub>](http://www.linkedin.com/in/peterblazejewicz)<br />[🌍](#translation-peterblazejewicz "Translation") | [<img src="https://avatars0.githubusercontent.com/u/6516758?v=4" width="100px;"/><br /><sub><b>Eric Adamski</b></sub>](https://github.com/ericadamski)<br />[🐛](https://github.com/gitpoint/git-point/issues?q=author%3Aericadamski "Bug reports") | [<img src="https://avatars2.githubusercontent.com/u/1559013?v=4" width="100px;"/><br /><sub><b>Jouderian Nobre Junior</b></sub>](https://github.com/jouderianjr)<br />[💻](https://github.com/gitpoint/git-point/commits?author=jouderianjr "Code") | [<img src="https://avatars2.githubusercontent.com/u/5158502?v=4" width="100px;"/><br /><sub><b>Phi Dong</b></sub>](http://www.phidong.com)<br />[💻](https://github.com/gitpoint/git-point/commits?author=pdong "Code") | [<img src="https://avatars2.githubusercontent.com/u/17956698?v=4" width="100px;"/><br /><sub><b>John Patrick Salcedo</b></sub>](https://github.com/jpls93)<br />[💻](https://github.com/gitpoint/git-point/commits?author=jpls93 "Code") | [<img src="https://avatars2.githubusercontent.com/u/11599942?v=4" width="100px;"/><br /><sub><b>Óscar Carretero</b></sub>](https://github.com/ocarreterom)<br />[💻](https://github.com/gitpoint/git-point/commits?author=ocarreterom "Code") |
| [<img src="https://avatars3.githubusercontent.com/u/5528931?v=4" width="100px;"/><br /><sub><b>Dyesse YUMBA</b></sub>](https://github.com/dyesseyumba)<br />[🔧](#tool-dyesseyumba "Tools") | [<img src="https://avatars0.githubusercontent.com/u/20456165?v=4" width="100px;"/><br /><sub><b>Bink</b></sub>](https://binkpitch.me/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=binkpitch "Code") | [<img src="https://avatars2.githubusercontent.com/u/10085841?v=4" width="100px;"/><br /><sub><b>khvilaboa</b></sub>](https://github.com/khvilaboa)<br />[🌍](#translation-khvilaboa "Translation") | [<img src="https://avatars1.githubusercontent.com/u/40802?v=4" width="100px;"/><br /><sub><b>James Glover</b></sub>](http://jamesmglover.com)<br />[💻](https://github.com/gitpoint/git-point/commits?author=jglover "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=jglover "Tests") | [<img src="https://avatars2.githubusercontent.com/u/3025600?v=4" width="100px;"/><br /><sub><b>Jose Luis Naranjo</b></sub>](https://co.linkedin.com/in/josenaranjo/en)<br />[💻](https://github.com/gitpoint/git-point/commits?author=josenaranjo "Code") | [<img src="https://avatars0.githubusercontent.com/u/1285032?v=4" width="100px;"/><br /><sub><b>Tobias Lohse</b></sub>](http://MrLoh.se)<br />[💻](https://github.com/gitpoint/git-point/commits?author=MrLoh "Code") |
| [<img src="https://avatars3.githubusercontent.com/u/5467717?v=4" width="100px;"/><br /><sub><b>Serhii Baraniuk</b></sub>](https://www.facebook.com/serhii.baraniuk)<br />[⚠️](https://github.com/gitpoint/git-point/commits?author=kenitive "Tests") | [<img src="https://avatars2.githubusercontent.com/u/57701?v=4" width="100px;"/><br /><sub><b>Ben Snider</b></sub>](http://www.bensnider.com/)<br />[⚠️](https://github.com/gitpoint/git-point/commits?author=stupergenius "Tests") | [<img src="https://avatars1.githubusercontent.com/u/23706543?v=4" width="100px;"/><br /><sub><b>Simon Hoyos</b></sub>](https://www.linkedin.com/in/simonhoyos/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=shmesa22 "Code") [🎨](#design-shmesa22 "Design") | [<img src="https://avatars3.githubusercontent.com/u/10438692?v=4" width="100px;"/><br /><sub><b>Damien Leroy</b></sub>](https://github.com/ShiiFu)<br />[🌍](#translation-ShiiFu "Translation") | [<img src="https://avatars1.githubusercontent.com/u/686676?v=4" width="100px;"/><br /><sub><b>botbotbot</b></sub>](http://dev.im-bot.com)<br />[⚠️](https://github.com/gitpoint/git-point/commits?author=ibotdotout "Tests") | [<img src="https://avatars1.githubusercontent.com/u/8254906?v=4" width="100px;"/><br /><sub><b>Dmytro Kytsmen</b></sub>](https://github.com/Kietzmann)<br />[🌍](#translation-Kietzmann "Translation") |
| [<img src="https://avatars0.githubusercontent.com/u/3683673?v=4" width="100px;"/><br /><sub><b>TheCodeTalker</b></sub>](https://thecodetalker.github.io/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=TheCodeTalker "Code") | [<img src="https://avatars0.githubusercontent.com/u/2670744?v=4" width="100px;"/><br /><sub><b>Leonardo</b></sub>](https://github.com/LeoCp)<br />[💻](https://github.com/gitpoint/git-point/commits?author=LeoCp "Code") | [<img src="https://avatars2.githubusercontent.com/u/13105865?v=4" width="100px;"/><br /><sub><b>Stephen</b></sub>](https://github.com/coderste)<br />[📖](https://github.com/gitpoint/git-point/commits?author=coderste "Documentation") |
| [<img src="https://avatars0.githubusercontent.com/u/3683673?v=4" width="100px;"/><br /><sub><b>TheCodeTalker</b></sub>](https://thecodetalker.github.io/)<br />[💻](https://github.com/gitpoint/git-point/commits?author=TheCodeTalker "Code") | [<img src="https://avatars0.githubusercontent.com/u/2670744?v=4" width="100px;"/><br /><sub><b>Leonardo</b></sub>](https://github.com/LeoCp)<br />[💻](https://github.com/gitpoint/git-point/commits?author=LeoCp "Code") | [<img src="https://avatars2.githubusercontent.com/u/13105865?v=4" width="100px;"/><br /><sub><b>Stephen</b></sub>](https://github.com/coderste)<br />[📖](https://github.com/gitpoint/git-point/commits?author=coderste "Documentation") | [<img src="https://avatars0.githubusercontent.com/u/5565340?v=4" width="100px;"/><br /><sub><b>Zahra Traboulsi</b></sub>](http://www.zahra.tech)<br />[💻](https://github.com/gitpoint/git-point/commits?author=ZahraTee "Code") [⚠️](https://github.com/gitpoint/git-point/commits?author=ZahraTee "Tests") |
<!-- ALL-CONTRIBUTORS-LIST:END -->
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@

[![Build Status](https://img.shields.io/travis/gitpoint/git-point.svg?style=flat-square)](https://travis-ci.org/gitpoint/git-point)
[![Coveralls](https://img.shields.io/coveralls/github/gitpoint/git-point.svg?style=flat-square)](https://coveralls.io/github/gitpoint/git-point)
[![All Contributors](https://img.shields.io/badge/all_contributors-69-orange.svg?style=flat-square)](#contributors)
[![All Contributors](https://img.shields.io/badge/all_contributors-70-orange.svg?style=flat-square)](#contributors)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
[![Commitizen friendly](https://img.shields.io/badge/commitizen-friendly-brightgreen.svg?style=flat-square)](http://commitizen.github.io/cz-cli/)
[![Gitter chat](https://img.shields.io/badge/chat-on_gitter-008080.svg?style=flat-square)](https://gitter.im/git-point)
Expand Down
47 changes: 47 additions & 0 deletions __tests__/tests/components/NotificationIcon.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import React from 'react';
import { shallow, render } from 'enzyme';
import { Badge, NotificationIconComponent } from 'components';

const defaultProps = {
iconColor: 'red',
notificationsCount: 10,
};

describe('<NotificationIcon />', () => {
it('should display a Badge component when notificationsCount is greater than 0', () => {
const wrapper = shallow(<NotificationIconComponent {...defaultProps} />);

const badges = wrapper.find(Badge);
expect(badges.length).toBe(1);
});

it('should not display a Badge component when notificationsCount is 0', () => {
const wrapper = shallow(
<NotificationIconComponent {...defaultProps} notificationsCount={0} />
);

const badges = wrapper.find(Badge);
expect(badges.length).toBe(0);
});

it("should display a Badge component displaying '99+' in normal text when notificationsCount is greater than 99", () => {
const wrapper = shallow(
<NotificationIconComponent {...defaultProps} notificationsCount={100} />
);

const badge = wrapper.find(Badge);
expect(badge.prop('text')).toBe('99+');
expect(badge.prop('largeText')).toBe(false);
});

it('should display a Badge component displaying notificationsCount in largeText if notificationsCount is less than or equal to 99', () => {
const wrapper = shallow(
<NotificationIconComponent {...defaultProps} notificationsCount={99} />
);

const badge = wrapper.find(Badge);

expect(badge.prop('text')).toBe(99);
expect(badge.prop('largeText')).toBe(true);
});
});
28 changes: 28 additions & 0 deletions __tests__/tests/components/RepositorySectionTitle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import React from 'react';
import { shallow, render } from 'enzyme';
import { RepositorySectionTitle, StateBadge } from 'components';

const defaultProps = {
text: 'test title',
openCount: 10,
closedCount: 10,
loading: false,
};

describe('<RepositorySectionTitle />', () => {
it('should display no StateBadge components if loading is true', () => {
const wrapper = shallow(
<RepositorySectionTitle {...defaultProps} loading={true} />
);
const badges = wrapper.find(StateBadge);

expect(badges.length).toBe(0);
});

it('should display two StateBadge components if loading is false', () => {
const wrapper = shallow(<RepositorySectionTitle {...defaultProps} />);
const badges = wrapper.find(StateBadge);

expect(badges.length).toBe(2);
});
});
2 changes: 1 addition & 1 deletion src/components/notification-icon.component.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ const mapStateToProps = state => ({
notificationsCount: state.notifications.notificationsCount,
});

class NotificationIconComponent extends Component {
export class NotificationIconComponent extends Component {
Copy link
Member

Choose a reason for hiding this comment

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

Why does this need to be exported? Can you test NotificationIcon which is exported at the bottom of this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Given NotificationIcon is this component but connected to a Redux store, the options were to either just test this inner component or to test NotificationIcon itself and mock out the store etc. I can look into the latter option.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Although exporting and testing the unwrapped Component seems to be recommended by Redux: https://redux.js.org/docs/recipes/WritingTests.html#connected-components

Copy link
Member

Choose a reason for hiding this comment

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

Yep, you're right! This should be exported.

Copy link
Member

Choose a reason for hiding this comment

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

(not to self: we might want to make this a dumb component w/o access to redux state and do all that state management elsewhere)

props: {
iconColor: string,
notificationsCount: number,
Expand Down