-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #29 from andela/ft-articles-pagination-165305229
#165305229 Implement pagination support for articles
- Loading branch information
Showing
9 changed files
with
199 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React, { Component } from 'react'; | ||
|
||
class Pagination extends Component { | ||
render() { | ||
const { | ||
handleLink, handleClick, pageNumbers, next, previous, currentPage, | ||
} = this.props; | ||
return ( | ||
<div className="pagination"> | ||
<nav aria-label="Page navigation"> | ||
<ul className="pagination"> | ||
{previous ? ( | ||
<li className="page-item"> | ||
<span | ||
className="page-link" | ||
id={previous} | ||
onClick={handleLink} | ||
aria-label="Previous" | ||
> | ||
<span aria-hidden="true">«</span> | ||
<span className="sr-only">Previous</span> | ||
</span> | ||
</li> | ||
) : null} | ||
|
||
{pageNumbers.map((num, index) => ( | ||
<li key={index} className="page-item"> | ||
{currentPage === num ? ( | ||
<span id={num} className="page-link active-page" onClick={handleClick}> | ||
{num} | ||
</span> | ||
) : ( | ||
<span id={num} className="page-link" onClick={handleClick}> | ||
{num} | ||
</span> | ||
)} | ||
</li> | ||
))} | ||
|
||
{next ? ( | ||
<li className="page-item"> | ||
<span className="page-link" id={next} onClick={handleLink} aria-label="Next"> | ||
<span aria-hidden="true">»</span> | ||
<span className="sr-only">Next</span> | ||
</span> | ||
</li> | ||
) : null} | ||
</ul> | ||
</nav> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default Pagination; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import React from 'react'; | ||
import { shallow, mount } from 'enzyme'; | ||
import { BrowserRouter } from 'react-router-dom'; | ||
import { Provider } from 'react-redux'; | ||
import store from '../src/redux/store'; | ||
import Pagination from '../src/components/articles/Pagination'; | ||
|
||
describe('should mount Pagination component when it is called', () => { | ||
it('tests for successful mount of pagination', () => { | ||
const props = { | ||
handleLink: jest.fn(), | ||
handleClick: jest.fn(), | ||
pageNumbers: [], | ||
next: '', | ||
previous: '', | ||
currentPage: 1, | ||
}; | ||
const wrapper = mount( | ||
<BrowserRouter> | ||
<Provider store={store}> | ||
<Pagination {...props} /> | ||
</Provider> | ||
</BrowserRouter>, | ||
); | ||
}); | ||
|
||
it('renders Pagination component', () => { | ||
const props = { | ||
handleLink: jest.fn(), | ||
handleClick: jest.fn(), | ||
pageNumbers: [], | ||
next: '', | ||
previous: 'a', | ||
currentPage: 1, | ||
}; | ||
const event = { | ||
preventDefault() {}, | ||
target: { value: 'the-value' }, | ||
}; | ||
const wrapper = shallow(<Pagination {...props} />); | ||
|
||
wrapper.find('.page-link').simulate('click', event); | ||
expect(props.handleLink).toHaveBeenCalled(); | ||
}); | ||
}); |