shlink-web-client/test/utils/PaginationDropdown.test.tsx

36 lines
1 KiB
TypeScript
Raw Normal View History

import { screen } from '@testing-library/react';
import { PaginationDropdown } from '../../src/utils/PaginationDropdown';
import { renderWithEvents } from '../__helpers__/setUpTest';
2021-09-20 22:31:14 +03:00
describe('<PaginationDropdown />', () => {
2023-05-27 12:57:26 +03:00
const setValue = vi.fn();
const setUp = async () => {
const result = renderWithEvents(<PaginationDropdown ranges={[10, 50, 100, 200]} value={50} setValue={setValue} />);
const { user } = result;
2021-09-20 22:31:14 +03:00
await user.click(screen.getByRole('button'));
2021-09-20 22:31:14 +03:00
return result;
};
2021-09-20 22:31:14 +03:00
2023-05-27 12:57:26 +03:00
afterEach(vi.clearAllMocks);
2021-09-20 22:31:14 +03:00
it('renders expected amount of items', async () => {
await setUp();
expect(screen.getAllByRole('menuitem')).toHaveLength(5);
2021-09-20 22:31:14 +03:00
});
it.each([
2022-03-26 14:17:42 +03:00
[0, 10],
[1, 50],
[2, 100],
[3, 200],
])('sets expected value when an item is clicked', async (index, expectedValue) => {
const { user } = await setUp();
2021-09-20 22:31:14 +03:00
expect(setValue).not.toHaveBeenCalled();
await user.click(screen.getAllByRole('menuitem')[index]);
2021-09-20 22:31:14 +03:00
expect(setValue).toHaveBeenCalledWith(expectedValue);
});
});