2022-07-10 21:11:01 +03:00
|
|
|
import { screen } from '@testing-library/react';
|
2022-05-28 12:16:59 +03:00
|
|
|
import { PaginationDropdown } from '../../src/utils/PaginationDropdown';
|
2022-07-10 21:11:01 +03:00
|
|
|
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();
|
2022-07-10 21:11:01 +03:00
|
|
|
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
|
|
|
|
2022-07-10 21:11:01 +03:00
|
|
|
await user.click(screen.getByRole('button'));
|
2021-09-20 22:31:14 +03:00
|
|
|
|
2022-07-10 21:11:01 +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
|
|
|
|
2022-07-10 21:11:01 +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
|
|
|
});
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it.each([
|
2022-03-26 14:17:42 +03:00
|
|
|
[0, 10],
|
|
|
|
[1, 50],
|
|
|
|
[2, 100],
|
|
|
|
[3, 200],
|
2022-07-10 21:11:01 +03:00
|
|
|
])('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();
|
2022-07-10 21:11:01 +03:00
|
|
|
await user.click(screen.getAllByRole('menuitem')[index]);
|
2021-09-20 22:31:14 +03:00
|
|
|
expect(setValue).toHaveBeenCalledWith(expectedValue);
|
|
|
|
});
|
|
|
|
});
|