2020-12-25 12:39:54 +03:00
|
|
|
import { shallow, ShallowWrapper } from 'enzyme';
|
|
|
|
import { DropdownMenu, DropdownToggle } from 'reactstrap';
|
|
|
|
import { PropsWithChildren } from 'react';
|
2020-12-25 12:43:36 +03:00
|
|
|
import { DropdownBtn, DropdownBtnProps } from '../../src/utils/DropdownBtn';
|
2020-12-25 12:39:54 +03:00
|
|
|
|
2020-12-25 12:43:36 +03:00
|
|
|
describe('<DropdownBtn />', () => {
|
2020-12-25 12:39:54 +03:00
|
|
|
let wrapper: ShallowWrapper;
|
2020-12-25 12:43:36 +03:00
|
|
|
const createWrapper = (props: PropsWithChildren<DropdownBtnProps>) => {
|
|
|
|
wrapper = shallow(<DropdownBtn {...props} />);
|
2020-12-25 12:39:54 +03:00
|
|
|
|
|
|
|
return wrapper;
|
|
|
|
};
|
|
|
|
|
|
|
|
afterEach(() => wrapper?.unmount());
|
|
|
|
|
|
|
|
it.each([[ 'foo' ], [ 'bar' ], [ 'baz' ]])('displays provided text', (text) => {
|
|
|
|
const wrapper = createWrapper({ text });
|
|
|
|
const toggle = wrapper.find(DropdownToggle);
|
|
|
|
|
|
|
|
expect(toggle.html()).toContain(text);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([[ 'foo' ], [ 'bar' ], [ 'baz' ]])('displays provided children', (children) => {
|
|
|
|
const wrapper = createWrapper({ text: '', children });
|
|
|
|
const menu = wrapper.find(DropdownMenu);
|
|
|
|
|
|
|
|
expect(menu.html()).toContain(children);
|
|
|
|
});
|
|
|
|
|
|
|
|
it.each([
|
2020-12-25 12:54:49 +03:00
|
|
|
[ undefined, 'dropdown-btn__toggle btn-block' ],
|
|
|
|
[ '', 'dropdown-btn__toggle btn-block' ],
|
|
|
|
[ 'foo', 'dropdown-btn__toggle btn-block foo' ],
|
|
|
|
[ 'bar', 'dropdown-btn__toggle btn-block bar' ],
|
2020-12-25 12:39:54 +03:00
|
|
|
])('includes provided classes', (className, expectedClasses) => {
|
|
|
|
const wrapper = createWrapper({ text: '', className });
|
|
|
|
const toggle = wrapper.find(DropdownToggle);
|
|
|
|
|
|
|
|
expect(toggle.prop('className')?.trim()).toEqual(expectedClasses);
|
|
|
|
});
|
|
|
|
});
|