-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat: add PaginationListItem unit tests, and minor refactors to impro…
…ve code consistency
- Loading branch information
1 parent
5196c0b
commit 7606368
Showing
6 changed files
with
75 additions
and
26 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ jest.mock('next/router', () => ({ | |
useRouter() { | ||
return { | ||
isReady: true, | ||
asPath: '/link', | ||
asPath: '/', | ||
}; | ||
}, | ||
})); |
56 changes: 56 additions & 0 deletions
56
components/Common/Pagination/PaginationListItem/__tests__/index.test.mjs
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,56 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
import { IntlProvider } from 'react-intl'; | ||
|
||
import PaginationListItem from '@/components/Common/Pagination/PaginationListItem'; | ||
|
||
function renderPaginationListItem({ | ||
url, | ||
pageNumber, | ||
currentPage, | ||
totalPages, | ||
}) { | ||
render( | ||
<IntlProvider> | ||
<PaginationListItem | ||
url={url} | ||
pageNumber={pageNumber} | ||
currentPage={currentPage} | ||
totalPages={totalPages} | ||
/> | ||
</IntlProvider> | ||
); | ||
} | ||
|
||
describe('PaginationListItem', () => { | ||
it('Renders the list item correctly, including the corresponding ARIA attributes', () => { | ||
const pageNumber = 1; | ||
const totalPages = 10; | ||
const url = 'http://'; | ||
|
||
renderPaginationListItem({ | ||
url, | ||
currentPage: 1, | ||
pageNumber, | ||
totalPages, | ||
}); | ||
|
||
const listItem = screen.getByRole('listitem'); | ||
|
||
expect(listItem).toBeVisible(); | ||
expect(listItem).toHaveAttribute('aria-posinset', String(pageNumber)); | ||
expect(listItem).toHaveAttribute('aria-setsize', String(totalPages)); | ||
|
||
expect(screen.getByRole('link')).toHaveAttribute('href', url); | ||
}); | ||
|
||
it('Assigns aria-current="page" attribute to the link when the current page is equal to the page number', () => { | ||
renderPaginationListItem({ | ||
url: 'http://', | ||
currentPage: 1, | ||
pageNumber: 1, | ||
totalPages: 10, | ||
}); | ||
|
||
expect(screen.getByRole('link')).toHaveAttribute('aria-current', 'page'); | ||
}); | ||
}); |
12 changes: 7 additions & 5 deletions
12
components/Common/Pagination/PaginationListItem/index.module.css
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 |
---|---|---|
@@ -1,16 +1,18 @@ | ||
.listItem { | ||
.listItem, | ||
.listItem:link, | ||
.listItem:active { | ||
@apply flex | ||
h-10 | ||
h-10 | ||
w-10 | ||
items-center | ||
justify-center | ||
rounded | ||
px-3 | ||
py-2.5 | ||
!text-neutral-800 | ||
text-neutral-800 | ||
hover:bg-neutral-100 | ||
aria-current:bg-green-600 | ||
aria-current:!text-white | ||
dark:!text-neutral-200 | ||
aria-current:text-white | ||
dark:text-neutral-200 | ||
hover:dark:bg-neutral-900; | ||
} |
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