2021-09-20 22:31:14 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { DropdownItem } from 'reactstrap';
|
|
|
|
import PaginationDropdown from '../../src/utils/PaginationDropdown';
|
|
|
|
|
|
|
|
describe('<PaginationDropdown />', () => {
|
|
|
|
const setValue = jest.fn();
|
|
|
|
let wrapper: ShallowWrapper;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
2022-03-26 14:17:42 +03:00
|
|
|
wrapper = shallow(<PaginationDropdown ranges={[10, 50, 100, 200]} value={50} setValue={setValue} />);
|
2021-09-20 22:31:14 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(jest.clearAllMocks);
|
|
|
|
afterEach(() => wrapper?.unmount());
|
|
|
|
|
2021-09-20 23:00:34 +03:00
|
|
|
it('renders expected amount of items', () => {
|
2021-09-20 22:31:14 +03:00
|
|
|
const items = wrapper.find(DropdownItem);
|
|
|
|
|
|
|
|
expect(items).toHaveLength(6);
|
|
|
|
});
|
|
|
|
|
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],
|
|
|
|
[5, Infinity],
|
2021-09-20 23:00:34 +03:00
|
|
|
])('sets expected value when an item is clicked', (index, expectedValue) => {
|
2021-09-20 22:31:14 +03:00
|
|
|
const item = wrapper.find(DropdownItem).at(index);
|
|
|
|
|
|
|
|
expect(setValue).not.toHaveBeenCalled();
|
|
|
|
item.simulate('click');
|
|
|
|
expect(setValue).toHaveBeenCalledWith(expectedValue);
|
|
|
|
});
|
|
|
|
});
|