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([
|
|
|
|
[ undefined, 'dropdown__btn btn-block' ],
|
|
|
|
[ '', 'dropdown__btn btn-block' ],
|
|
|
|
[ 'foo', 'dropdown__btn btn-block foo' ],
|
|
|
|
[ 'bar', 'dropdown__btn btn-block bar' ],
|
|
|
|
])('includes provided classes', (className, expectedClasses) => {
|
|
|
|
const wrapper = createWrapper({ text: '', className });
|
|
|
|
const toggle = wrapper.find(DropdownToggle);
|
|
|
|
|
|
|
|
expect(toggle.prop('className')?.trim()).toEqual(expectedClasses);
|
|
|
|
});
|
|
|
|
});
|