-
Notifications
You must be signed in to change notification settings - Fork 783
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
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,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); | ||
}); | ||
}); |
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); | ||
}); | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ const mapStateToProps = state => ({ | |
notificationsCount: state.notifications.notificationsCount, | ||
}); | ||
|
||
class NotificationIconComponent extends Component { | ||
export class NotificationIconComponent extends Component { | ||
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. Why does this need to be exported? Can you test 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. 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. 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. Although exporting and testing the unwrapped Component seems to be recommended by Redux: https://redux.js.org/docs/recipes/WritingTests.html#connected-components 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. Yep, you're right! This should be exported. 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. (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, | ||
|
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.
🎉