Skip to content

Commit 8ad5498

Browse files
committed
fix: hotfix pagination tests and provider
1 parent e7d6e09 commit 8ad5498

File tree

4 files changed

+22
-21
lines changed

4 files changed

+22
-21
lines changed

components/Common/Pagination/PaginationListItem/__tests__/index.test.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { render, screen } from '@testing-library/react';
2-
import { IntlProvider } from 'react-intl';
32

43
import PaginationListItem from '@/components/Common/Pagination/PaginationListItem';
4+
import { LocaleProvider } from '@/providers/localeProvider';
55

66
function renderPaginationListItem({
77
url,
@@ -10,14 +10,14 @@ function renderPaginationListItem({
1010
totalPages,
1111
}) {
1212
render(
13-
<IntlProvider>
13+
<LocaleProvider>
1414
<PaginationListItem
1515
url={url}
1616
pageNumber={pageNumber}
1717
currentPage={currentPage}
1818
totalPages={totalPages}
1919
/>
20-
</IntlProvider>
20+
</LocaleProvider>
2121
);
2222
}
2323

components/Common/Pagination/PaginationListItem/index.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ const PaginationListItem: FC<PaginationListItemProps> = ({
2424
return (
2525
<li key={pageNumber} aria-setsize={totalPages} aria-posinset={pageNumber}>
2626
<LocalizedLink
27-
prefetch={false}
2827
href={url}
2928
aria-label={intl.formatMessage(
3029
{ id: 'components.common.pagination.pageLabel' },

components/Common/Pagination/__tests__/index.test.mjs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
11
import { render, screen } from '@testing-library/react';
2-
import { IntlProvider } from 'react-intl';
32

43
import Pagination from '@/components/Common/Pagination';
4+
import { LocaleProvider } from '@/providers/localeProvider';
55

66
function renderPagination({
77
currentPage = 1,
88
pages,
99
currentPageSiblingsCount,
1010
}) {
11-
const parsedPages = new Array(pages).fill({ url: 'page' });
11+
const parsedPages = new Array(pages)
12+
.fill({ url: 'page' })
13+
.map(item => ({ url: `${item.url}-${Math.random()}` }));
1214

1315
render(
14-
<IntlProvider>
16+
<LocaleProvider>
1517
<Pagination
1618
currentPage={currentPage}
1719
pages={parsedPages}
1820
currentPageSiblingsCount={currentPageSiblingsCount}
1921
/>
20-
</IntlProvider>
22+
</LocaleProvider>
2123
);
2224

2325
return {

components/Common/Pagination/useGetPageElements.tsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -68,28 +68,28 @@ export const useGetPageElements = (
6868
totalPages
6969
);
7070

71-
const firstPageIndex = 0;
72-
const lastPageIndex = totalPages - 1;
71+
const firstIndex = 0;
72+
const lastIndex = totalPages - 1;
7373

7474
// If there are at least two (2) elements between the far-left sibling of
7575
// the current page, and the first page, we should show left ellipsis
7676
// between them
77-
const hasLeftEllipsis = leftSiblingsFirstIndex > firstPageIndex + 2;
77+
const hasLeftEllipsis = leftSiblingsFirstIndex > firstIndex + 2;
7878

7979
// If there are at least two (2) elements between the far-right sibling of
8080
// the current page, and the last page, we should show right ellipsis
8181
// between them
82-
const hasRightEllipsis = rightSiblingsLastIndex < lastPageIndex - 1;
82+
const hasRightEllipsis = rightSiblingsLastIndex < lastIndex - 1;
8383

8484
if (!hasLeftEllipsis && hasRightEllipsis) {
8585
const leftPagesLastIndex = MINIMUM_AMOUNT_OF_ELEMENTS + totalSiblingsCount;
8686

87-
const leftPages = parsedPages.slice(firstPageIndex, leftPagesLastIndex);
87+
const leftPages = parsedPages.slice(firstIndex, leftPagesLastIndex);
8888

8989
return [
9090
...createPaginationListItems(leftPages),
91-
Ellipsis(),
92-
...createPaginationListItems(parsedPages.slice(lastPageIndex)),
91+
<Ellipsis key="elipsis" />,
92+
...createPaginationListItems(parsedPages.slice(lastIndex)),
9393
];
9494
}
9595

@@ -101,9 +101,9 @@ export const useGetPageElements = (
101101

102102
return [
103103
...createPaginationListItems(
104-
parsedPages.slice(firstPageIndex, firstPageIndex + 1)
104+
parsedPages.slice(firstIndex, firstIndex + 1)
105105
),
106-
Ellipsis(),
106+
<Ellipsis key="elipsis" />,
107107
...createPaginationListItems(rightPages),
108108
];
109109
}
@@ -116,12 +116,12 @@ export const useGetPageElements = (
116116

117117
return [
118118
...createPaginationListItems(
119-
parsedPages.slice(firstPageIndex, firstPageIndex + 1)
119+
parsedPages.slice(firstIndex, firstIndex + 1)
120120
),
121-
Ellipsis(),
121+
<Ellipsis key="elipsis-1" />,
122122
...createPaginationListItems(middlePages),
123-
Ellipsis(),
124-
...createPaginationListItems(parsedPages.slice(lastPageIndex)),
123+
<Ellipsis key="elipsis-2" />,
124+
...createPaginationListItems(parsedPages.slice(lastIndex)),
125125
];
126126
}
127127
};

0 commit comments

Comments
 (0)