Skip to content

Commit 11f6174

Browse files
author
Raphaël Benitte
committed
Merge pull request #10 from macklinu/pull-requests-title
Provide optional PullRequests title
2 parents a26a397 + 13a73ce commit 11f6174

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

src/components/PullRequests.jsx

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,18 @@ class PullRequests extends Component {
3333

3434
render() {
3535
let { pullRequests } = this.state;
36+
let { repository, title } = this.props
37+
38+
let titleNode = title === undefined ? (
39+
<span>
40+
<span className="widget__header__subject">{repository}</span> Pull Requests
41+
</span>
42+
) : title;
3643

3744
return (
3845
<div>
3946
<div className="widget__header">
40-
Pull requests
47+
{titleNode}
4148
<span className="widget__header__count">
4249
{pullRequests.length}
4350
</span>
@@ -54,7 +61,8 @@ class PullRequests extends Component {
5461
}
5562

5663
PullRequests.propTypes = {
57-
repository: PropTypes.string.isRequired
64+
repository: PropTypes.string.isRequired,
65+
title: PropTypes.string
5866
};
5967

6068
reactMixin(PullRequests.prototype, ListenerMixin);

src/tests/PullRequests.test.js

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import mockery from 'mockery';
77
var PullRequests;
88
var pullRequests;
99

10+
const repository = 'plouc/mozaik';
11+
1012
describe('Github — PullRequests', () => {
1113

1214
let sandbox;
@@ -23,7 +25,7 @@ describe('Github — PullRequests', () => {
2325

2426
beforeEach(() => {
2527
sandbox = sinon.sandbox.create();
26-
pullRequests = TestUtils.renderIntoDocument(<PullRequests repository="plouc/mozaik" />);
28+
pullRequests = TestUtils.renderIntoDocument(<PullRequests repository={repository} />);
2729
});
2830

2931
afterEach(() => {
@@ -38,9 +40,9 @@ describe('Github — PullRequests', () => {
3840

3941
it('should return correct api request', () => {
4042
expect(pullRequests.getApiRequest()).to.eql({
41-
id: 'github.pullRequests.plouc/mozaik',
43+
id: `github.pullRequests.${repository}`,
4244
params: {
43-
repository: 'plouc/mozaik'
45+
repository: repository
4446
}
4547
});
4648
});
@@ -80,4 +82,16 @@ describe('Github — PullRequests', () => {
8082
let count = TestUtils.findRenderedDOMComponentWithClass(pullRequests, 'widget__header__count');
8183
expect(count.getDOMNode().textContent).to.equal('3');
8284
});
83-
});
85+
86+
it('renders default title `repository Pull Requests`', () => {
87+
let title = TestUtils.findRenderedDOMComponentWithClass(pullRequests, 'widget__header');
88+
expect(title.getDOMNode().textContent).to.contain(`${repository} Pull Requests`);
89+
});
90+
91+
it('renders custom title when supplied', () => {
92+
let customTitle = 'Custom Title';
93+
pullRequests = TestUtils.renderIntoDocument(<PullRequests repository={repository} title={customTitle} />)
94+
let title = TestUtils.findRenderedDOMComponentWithClass(pullRequests, 'widget__header');
95+
expect(title.getDOMNode().textContent).to.contain(customTitle);
96+
});
97+
});

0 commit comments

Comments
 (0)