-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ft(Pagination) : Pagination support for articles
- Get All Articles Using Page Numbers - Add Pagination Component Below All Articles - Add Previous and Next Buttons on the Pagination Tab [Starts #161348761]
- Loading branch information
1 parent
cbf6795
commit 3bd4b15
Showing
30 changed files
with
687 additions
and
388 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
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
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 |
---|---|---|
|
@@ -71,3 +71,6 @@ $primaryDarker: #345F5B; | |
} | ||
} | ||
} | ||
.NotFound{ | ||
padding-top: 250px; | ||
} |
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,21 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import ArticleDisplay from '.'; | ||
|
||
|
||
describe('Test pagination', () => { | ||
const article = { | ||
count: 44, | ||
title: 'hello', | ||
description: 'World', | ||
image_url: 'https://helloworld.png', | ||
}; | ||
|
||
const ArticleDisplaywrapper = shallow( | ||
<ArticleDisplay article={article} />, | ||
); | ||
|
||
test('ArticleDisplay shpuld render corretly', () => { | ||
expect(ArticleDisplaywrapper.find('.article-card').length).toBe(1); | ||
}); | ||
}); |
68 changes: 68 additions & 0 deletions
68
src/components/Pagination/__snapshots__/index.test.js.snap
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,68 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Test pagination Snap shot pagination Component 1`] = ` | ||
<div> | ||
<br /> | ||
<ul | ||
className="pagination justify-content-center" | ||
> | ||
<li | ||
className="page-item disabled" | ||
> | ||
<a | ||
className="page-link" | ||
href="articles/page/0" | ||
tabIndex="-1" | ||
> | ||
Previous | ||
</a> | ||
</li> | ||
<li | ||
className="page-item active" | ||
key="1" | ||
> | ||
<a | ||
className="page-link" | ||
href="articles/page/1" | ||
> | ||
1 | ||
</a> | ||
</li> | ||
<li | ||
className="page-item null" | ||
key="2" | ||
> | ||
<a | ||
className="page-link" | ||
href="articles/page/2" | ||
> | ||
2 | ||
</a> | ||
</li> | ||
<li | ||
className="page-item null" | ||
key="3" | ||
> | ||
<a | ||
className="page-link" | ||
href="articles/page/3" | ||
> | ||
3 | ||
</a> | ||
</li> | ||
<li | ||
className="page-item null" | ||
> | ||
<a | ||
className="page-link" | ||
href="articles/page/2" | ||
> | ||
Next | ||
</a> | ||
</li> | ||
</ul> | ||
</div> | ||
`; |
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,39 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import _ from 'lodash'; | ||
|
||
const Pagination = ({ article, pageNumber }) => { | ||
const activePage = number => (number === Number(pageNumber) ? 'active' : null); | ||
const disablePrevious = (num1, num2) => (num1 === num2 ? 'disabled' : null); | ||
|
||
const numberOfpages = Math.ceil(article.count / 12); | ||
const ArraynumberOfpages = _.range(1, numberOfpages + 1); | ||
const pages = ArraynumberOfpages.map(number => ( | ||
<li key={number} className={`page-item ${activePage(number)}`}> | ||
{' '} | ||
<a className="page-link" href={`articles/page/${number}`}>{number}</a> | ||
</li> | ||
)); | ||
|
||
return ( | ||
<div> | ||
<br /> | ||
<ul className="pagination justify-content-center"> | ||
<li className={`page-item ${disablePrevious(pageNumber, '1')}`}> | ||
<a className="page-link" href={`articles/page/${Number(pageNumber) - 1}`} tabIndex="-1">Previous</a> | ||
</li> | ||
{pages} | ||
<li className={`page-item ${disablePrevious(Number(pageNumber), numberOfpages)}`}> | ||
<a className="page-link" href={`articles/page/${Number(pageNumber) + 1}`}>Next</a> | ||
</li> | ||
</ul> | ||
</div> | ||
); | ||
}; | ||
|
||
Pagination.propTypes = { | ||
article: PropTypes.shape({}).isRequired, | ||
pageNumber: PropTypes.string.isRequired, | ||
}; | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
import React from 'react'; | ||
import { shallow } from 'enzyme'; | ||
import Pagination from '.'; | ||
|
||
|
||
describe('Test pagination', () => { | ||
const article = { | ||
count: 35, | ||
}; | ||
const pageNumber = '1'; | ||
const Paginationwrapper = shallow( | ||
<Pagination article={article} pageNumber={pageNumber} />, | ||
); | ||
|
||
test('Snap shot pagination Component', () => { | ||
expect(Paginationwrapper).toMatchSnapshot(); | ||
}); | ||
test('Pagination should render correctly', () => { | ||
expect(Paginationwrapper.find('.active').length).toBe(1); | ||
expect(Paginationwrapper.find('.disabled').length).toBe(1); | ||
}); | ||
}); |
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
Oops, something went wrong.