Skip to content

Commit

Permalink
fix: update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
viktorrusakov committed Oct 13, 2023
1 parent 6e60119 commit 1ec4fa7
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/DataTable/tests/TablePagination.test.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, act } from '@testing-library/react';
import { render, act, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';

import TablePagination from '../TablePagination';
Expand Down Expand Up @@ -29,21 +29,21 @@ describe('<TablePagination />', () => {
it(
'Shows dropdown button with the page count as label and performs actions when dropdown items are clicked',
async () => {
const { getAllByTestId, getByRole } = render(<PaginationWrapper value={instance} />);
const dropdownButton = getByRole('button', { name: /2 of 3/i });
render(<PaginationWrapper value={instance} />);
const dropdownButton = screen.getByRole('button', { name: /2 of 3/i });
expect(dropdownButton).toBeInTheDocument();
await act(async () => {
await userEvent.click(dropdownButton);
});

const dropdownChoices = getAllByTestId('pagination-dropdown-item');
const dropdownChoices = screen.getAllByTestId('pagination-dropdown-item');
expect(dropdownChoices.length).toEqual(instance.pageCount);
await act(async () => {
await userEvent.click(dropdownChoices[1], undefined, { skipPointerEventsCheck: true });
await userEvent.click(dropdownChoices[2], undefined, { skipPointerEventsCheck: true });
});

expect(instance.gotoPage).toHaveBeenCalledTimes(1);
expect(instance.gotoPage).toHaveBeenCalledWith(1);
expect(instance.gotoPage).toHaveBeenCalledWith(2);
},
);
});
6 changes: 5 additions & 1 deletion src/Pagination/subcomponents/PaginationDropdown.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,11 @@ export default function PaginationDropdown() {
</Dropdown.Toggle>
<Dropdown.Menu className="pagination-reduced-dropdown-menu">
{[...Array(pageCount).keys()].map(pageNum => (
<Dropdown.Item onClick={() => handlePageSelect(pageNum + 1)} key={pageNum}>
<Dropdown.Item
onClick={() => handlePageSelect(pageNum + 1)}
key={pageNum}
data-testid="pagination-dropdown-item"
>
{pageNum + 1}
</Dropdown.Item>
))}
Expand Down

0 comments on commit 1ec4fa7

Please sign in to comment.