shlink-web-client/test/utils/DropdownBtn.test.tsx

42 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-12-25 12:39:54 +03:00
import { shallow, ShallowWrapper } from 'enzyme';
import { DropdownMenu, DropdownToggle } from 'reactstrap';
import { PropsWithChildren } from 'react';
import { DropdownBtn, DropdownBtnProps } from '../../src/utils/DropdownBtn';
2020-12-25 12:39:54 +03:00
describe('<DropdownBtn />', () => {
2020-12-25 12:39:54 +03:00
let wrapper: ShallowWrapper;
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([
[ 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);
});
});