Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 29 additions & 1 deletion src/components/pagination/pagination-controls.spec.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import React from 'react';
import PaginationControl from './pagination-controls';
import PagingOptionsMenu from './paging-options-menu';
import { PAGING_PROPS } from './pagination-test-helper';
import { render } from '@testing-library/react';
import { fireEvent, render, screen } from '@testing-library/react';

jest.useFakeTimers();
describe('Pagination Controls with page buttons', () => {
Expand All @@ -16,6 +17,33 @@ describe('Pagination Controls with page buttons', () => {
expect(getByRole('button', { name: 'Previous page' })).toBeInTheDocument();
expect(getByRole('button', { name: 'Next page' })).toBeInTheDocument();
});

it('closes the menu when an option has been selected', () => {
const { getByRole, getByText } = render(<PaginationControl pagingProps={PAGING_PROPS} />);
const menuButton = getByRole('button', { name: 'rows-per-page-menu' });
expect(menuButton).toBeInTheDocument();
fireEvent.click(menuButton);
const rowsPerPageButton = getByText('50');
fireEvent.click(rowsPerPageButton);
expect(PAGING_PROPS.handlePerPageChange).toHaveBeenCalledWith(50);
});

it('resets selected option to 1 when applicable', async () => {
const initialProps = {
selected: 5,
label: 'Go to Page',
options: [5, 10, 50],
updateSelected: jest.fn(),
disabled: false,
};
const { rerender, getByRole } = render(<PagingOptionsMenu menuProps={initialProps} />);

const menuButton = getByRole('button', { name: 'rows-per-page-menu' });
expect(menuButton).toHaveTextContent('5');
const newProps = { ...initialProps, selected: 10 };
rerender(<PagingOptionsMenu menuProps={newProps} />);
expect(screen.getByText('1')).toBeInTheDocument();
});
});

describe('Pagination Controls without page buttons', () => {
Expand Down
Loading