mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2025-01-03 23:07:26 +03:00
Migrated PaginationDropdown test to react testing library
This commit is contained in:
parent
f97fce873b
commit
bdf181adec
1 changed files with 15 additions and 15 deletions
|
@ -1,22 +1,23 @@
|
||||||
import { shallow, ShallowWrapper } from 'enzyme';
|
import { screen } from '@testing-library/react';
|
||||||
import { DropdownItem } from 'reactstrap';
|
|
||||||
import { PaginationDropdown } from '../../src/utils/PaginationDropdown';
|
import { PaginationDropdown } from '../../src/utils/PaginationDropdown';
|
||||||
|
import { renderWithEvents } from '../__helpers__/setUpTest';
|
||||||
|
|
||||||
describe('<PaginationDropdown />', () => {
|
describe('<PaginationDropdown />', () => {
|
||||||
const setValue = jest.fn();
|
const setValue = jest.fn();
|
||||||
let wrapper: ShallowWrapper;
|
const setUp = async () => {
|
||||||
|
const result = renderWithEvents(<PaginationDropdown ranges={[10, 50, 100, 200]} value={50} setValue={setValue} />);
|
||||||
|
const { user } = result;
|
||||||
|
|
||||||
beforeEach(() => {
|
await user.click(screen.getByRole('button'));
|
||||||
wrapper = shallow(<PaginationDropdown ranges={[10, 50, 100, 200]} value={50} setValue={setValue} />);
|
|
||||||
});
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
afterEach(jest.clearAllMocks);
|
afterEach(jest.clearAllMocks);
|
||||||
afterEach(() => wrapper?.unmount());
|
|
||||||
|
|
||||||
it('renders expected amount of items', () => {
|
it('renders expected amount of items', async () => {
|
||||||
const items = wrapper.find(DropdownItem);
|
await setUp();
|
||||||
|
expect(screen.getAllByRole('menuitem')).toHaveLength(5);
|
||||||
expect(items).toHaveLength(6);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
@ -24,12 +25,11 @@ describe('<PaginationDropdown />', () => {
|
||||||
[1, 50],
|
[1, 50],
|
||||||
[2, 100],
|
[2, 100],
|
||||||
[3, 200],
|
[3, 200],
|
||||||
[5, Infinity],
|
])('sets expected value when an item is clicked', async (index, expectedValue) => {
|
||||||
])('sets expected value when an item is clicked', (index, expectedValue) => {
|
const { user } = await setUp();
|
||||||
const item = wrapper.find(DropdownItem).at(index);
|
|
||||||
|
|
||||||
expect(setValue).not.toHaveBeenCalled();
|
expect(setValue).not.toHaveBeenCalled();
|
||||||
item.simulate('click');
|
await user.click(screen.getAllByRole('menuitem')[index]);
|
||||||
expect(setValue).toHaveBeenCalledWith(expectedValue);
|
expect(setValue).toHaveBeenCalledWith(expectedValue);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue