mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 09:30:31 +03:00
Added InfoTooltip test
This commit is contained in:
parent
410d372755
commit
9887cae4fd
2 changed files with 46 additions and 7 deletions
|
@ -10,16 +10,14 @@ interface InfoTooltipProps {
|
|||
}
|
||||
|
||||
export const InfoTooltip: FC<InfoTooltipProps> = ({ className = '', placement, children }) => {
|
||||
const ref = useRef<HTMLElement | null>();
|
||||
const ref = useRef<HTMLSpanElement | null>();
|
||||
const refCallback = (el: HTMLSpanElement) => {
|
||||
ref.current = el;
|
||||
};
|
||||
|
||||
return (
|
||||
<>
|
||||
<span
|
||||
className={className}
|
||||
ref={(el) => {
|
||||
ref.current = el;
|
||||
}}
|
||||
>
|
||||
<span className={className} ref={refCallback}>
|
||||
<FontAwesomeIcon icon={infoIcon} />
|
||||
</span>
|
||||
<UncontrolledTooltip target={(() => ref.current) as any} placement={placement}>{children}</UncontrolledTooltip>
|
||||
|
|
41
test/utils/InfoTooltip.test.tsx
Normal file
41
test/utils/InfoTooltip.test.tsx
Normal file
|
@ -0,0 +1,41 @@
|
|||
import { shallow } from 'enzyme';
|
||||
import { UncontrolledTooltip } from 'reactstrap';
|
||||
import { InfoTooltip } from '../../src/utils/InfoTooltip';
|
||||
import Popper from 'popper.js';
|
||||
|
||||
describe('<InfoTooltip />', () => {
|
||||
it.each([
|
||||
[ undefined ],
|
||||
[ 'foo' ],
|
||||
[ 'bar' ],
|
||||
])('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([
|
||||
[ <span key={1} /> ],
|
||||
[ 'Foo' ],
|
||||
[ 'Hello' ],
|
||||
[[ 'One', 'Two', <span key={3} /> ]],
|
||||
])('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([
|
||||
[ 'right' as Popper.Placement ],
|
||||
[ 'left' as Popper.Placement ],
|
||||
[ 'top' as Popper.Placement ],
|
||||
[ 'bottom' as Popper.Placement ],
|
||||
])('places tooltip where requested', (placement) => {
|
||||
const wrapper = shallow(<InfoTooltip placement={placement} />);
|
||||
const tooltip = wrapper.find(UncontrolledTooltip);
|
||||
|
||||
expect(tooltip.prop('placement')).toEqual(placement);
|
||||
});
|
||||
});
|
Loading…
Reference in a new issue