(
{firstIndex} - {lastIndex} of many
)}
/>
);
expect(screen.getAllByText('1 - 10 of many')[0]).toBeInTheDocument();
});
test('toggleTemplate toggle text with string', () => {
render();
expect(screen.getAllByText('I am a string')[0]).toBeInTheDocument();
});
test('should not update generated options menu id on rerenders', () => {
const { rerender } = render();
const id = screen.getByLabelText('test label').getAttribute('id');
rerender();
expect(screen.getByLabelText('test label')).toHaveAttribute('id', id);
});
test('page insets', () => {
render();
expect(screen.getByTestId('pagination-insets')).toHaveClass('pf-m-page-insets');
});
test('page insets', () => {
render();
expect(screen.getByTestId('pagination-insets')).toHaveClass('pf-m-page-insets');
});
});
describe('API', () => {
describe('onSetPage', () => {
const onSetPage = jest.fn();
test('should call first', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to first page' }));
expect(onSetPage).toHaveBeenCalled();
});
test('should call previous', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
expect(onSetPage).toHaveBeenCalled();
});
test('should call next', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to next page' }));
expect(onSetPage).toHaveBeenCalled();
});
test('should call last', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
expect(onSetPage).toHaveBeenCalled();
});
test('should call input', async () => {
const user = userEvent.setup();
render();
const input = screen.getByLabelText('Current page');
await user.type(input, '1');
await user.type(input, `{${KeyTypes.Enter}}`);
expect(onSetPage).toHaveBeenCalled();
});
test('should call input wrong value', async () => {
const user = userEvent.setup();
render();
const input = screen.getByLabelText('Current page');
await user.type(input, 'a');
await user.type(input, `{${KeyTypes.Enter}}`);
expect(onSetPage).toHaveBeenCalled();
});
test('should call input huge page number', async () => {
const user = userEvent.setup();
render();
const input = screen.getByLabelText('Current page');
await user.type(input, '10');
await user.type(input, `{${KeyTypes.Enter}}`);
expect(onSetPage).toHaveBeenCalled();
});
test('should call input small page number', async () => {
const user = userEvent.setup();
render();
const input = screen.getByLabelText('Current page');
await user.type(input, '-10');
await user.type(input, `{${KeyTypes.Enter}}`);
expect(onSetPage).toHaveBeenCalled();
});
test('should NOT call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
expect(onSetPage).not.toHaveBeenCalled();
});
});
describe('onFirst', () => {
const onFirst = jest.fn();
test('should call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to first page' }));
expect(onFirst).toHaveBeenCalled();
});
test('should NOT call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to first page' }));
expect(onFirst).not.toHaveBeenCalled();
});
});
describe('onLast', () => {
const onLast = jest.fn();
test('should call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
expect(onLast).toHaveBeenCalled();
});
test('should NOT call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to last page' }));
expect(onLast).not.toHaveBeenCalled();
});
});
describe('onPrevious', () => {
const onPrevious = jest.fn();
test('should call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
expect(onPrevious).toHaveBeenCalled();
});
test('should NOT call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
expect(onPrevious).not.toHaveBeenCalled();
});
});
describe('onNext', () => {
const onNext = jest.fn();
test('should call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to next page' }));
expect(onNext).toHaveBeenCalled();
});
test('should NOT call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: 'Go to previous page' }));
expect(onNext).not.toHaveBeenCalled();
});
});
describe('onPerPage', () => {
const onPerPage = jest.fn();
test('should call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: '1 - 10 of 40' }));
await user.click(screen.getByText('20 per page'));
expect(onPerPage).toHaveBeenCalled();
});
test('should NOT call', async () => {
const user = userEvent.setup();
render();
await user.click(screen.getByRole('button', { name: '1 - 10 of 40' }));
await user.click(screen.getByText('20 per page'));
expect(onPerPage).not.toHaveBeenCalled();
});
});
Object.values(['insetNone', 'insetSm', 'insetMd', 'insetLg', 'insetXl', 'inset2xl'] as [
'insetNone',
'insetSm',
'insetMd',
'insetLg',
'insetXl',
'inset2xl'
]).forEach(inset => {
test(`verify ${inset} inset breakpoints`, () => {
const { asFragment } = render(
test
);
expect(asFragment()).toMatchSnapshot();
});
});
});
});