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>) => {
|
2021-01-24 20:05:37 +03:00
|
|
|
wrapper = shallow(<DropdownBtn children={'foo'} {...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);
|
|
|
|
|
2021-01-24 20:05:37 +03:00
|
|
|
expect(toggle.prop('children')).toContain(text);
|
2020-12-25 12:39:54 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
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);
|
|
|
|
});
|
|
|
|
});
|