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

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2021-08-23 19:26:15 +03:00
import { shallow } from 'enzyme';
import { UncontrolledTooltip } from 'reactstrap';
import { Placement } from '@popperjs/core';
2021-08-24 20:53:28 +03:00
import { InfoTooltip } from '../../src/utils/InfoTooltip';
2021-08-23 19:26:15 +03:00
describe('<InfoTooltip />', () => {
it.each([
2022-03-26 14:17:42 +03:00
[undefined],
['foo'],
['bar'],
2021-08-23 19:26:15 +03:00
])('renders expected className on span', (className) => {
const wrapper = shallow(<InfoTooltip placement="right" className={className} />);
const span = wrapper.find('span');
expect(span.prop('className')).toEqual(className ?? '');
});
it.each([
2022-03-26 14:17:42 +03:00
[<span key={1} />],
['Foo'],
['Hello'],
[['One', 'Two', <span key={3} />]],
2021-08-23 19:26:15 +03:00
])('passes children down to the nested tooltip component', (children) => {
const wrapper = shallow(<InfoTooltip placement="right">{children}</InfoTooltip>);
const tooltip = wrapper.find(UncontrolledTooltip);
expect(tooltip.prop('children')).toEqual(children);
});
it.each([
2022-03-26 14:17:42 +03:00
['right' as Placement],
['left' as Placement],
['top' as Placement],
['bottom' as Placement],
2021-08-23 19:26:15 +03:00
])('places tooltip where requested', (placement) => {
const wrapper = shallow(<InfoTooltip placement={placement} />);
const tooltip = wrapper.find(UncontrolledTooltip);
expect(tooltip.prop('placement')).toEqual(placement);
});
});