From 27e3d6514314b2ffb0fe25f3d81dbf803e9775b9 Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Mon, 20 Sep 2021 21:31:14 +0200 Subject: [PATCH] Created PaginationDropdown test --- test/utils/PaginationDropdown.test.tsx | 35 ++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 test/utils/PaginationDropdown.test.tsx diff --git a/test/utils/PaginationDropdown.test.tsx b/test/utils/PaginationDropdown.test.tsx new file mode 100644 index 00000000..6c76f7cc --- /dev/null +++ b/test/utils/PaginationDropdown.test.tsx @@ -0,0 +1,35 @@ +import { shallow, ShallowWrapper } from 'enzyme'; +import { DropdownItem } from 'reactstrap'; +import PaginationDropdown from '../../src/utils/PaginationDropdown'; + +describe('', () => { + const setValue = jest.fn(); + let wrapper: ShallowWrapper; + + beforeEach(() => { + wrapper = shallow(); + }); + + afterEach(jest.clearAllMocks); + afterEach(() => wrapper?.unmount()); + + test('expected amount of items is rendered', () => { + const items = wrapper.find(DropdownItem); + + expect(items).toHaveLength(6); + }); + + test.each([ + [ 0, 10 ], + [ 1, 50 ], + [ 2, 100 ], + [ 3, 200 ], + [ 5, Infinity ], + ])('expected value is set when an item is clicked', (index, expectedValue) => { + const item = wrapper.find(DropdownItem).at(index); + + expect(setValue).not.toHaveBeenCalled(); + item.simulate('click'); + expect(setValue).toHaveBeenCalledWith(expectedValue); + }); +});