mirror of
https://github.com/shlinkio/shlink-web-client.git
synced 2024-12-23 17:40:23 +03:00
Created TooltipToggleSwitch test
This commit is contained in:
parent
45c918f4ee
commit
8fd07070b8
2 changed files with 41 additions and 3 deletions
|
@ -4,9 +4,9 @@ import { UncontrolledTooltipProps } from 'reactstrap/lib/Tooltip';
|
||||||
import { BooleanControlProps } from './BooleanControl';
|
import { BooleanControlProps } from './BooleanControl';
|
||||||
import ToggleSwitch from './ToggleSwitch';
|
import ToggleSwitch from './ToggleSwitch';
|
||||||
|
|
||||||
export const TooltipToggleSwitch: FC<BooleanControlProps & { tooltip?: Omit<UncontrolledTooltipProps, 'target'> }> = (
|
export type TooltipToggleSwitchProps = BooleanControlProps & { tooltip?: Omit<UncontrolledTooltipProps, 'target'> };
|
||||||
{ children, tooltip = {}, ...rest },
|
|
||||||
) => {
|
export const TooltipToggleSwitch: FC<TooltipToggleSwitchProps> = ({ children, tooltip = {}, ...rest }) => {
|
||||||
const ref = useRef<HTMLSpanElement>();
|
const ref = useRef<HTMLSpanElement>();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|
38
test/utils/TooltipToggleSwitch.test.tsx
Normal file
38
test/utils/TooltipToggleSwitch.test.tsx
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
import { shallow, ShallowWrapper } from 'enzyme';
|
||||||
|
import { PropsWithChildren } from 'react';
|
||||||
|
import { UncontrolledTooltip } from 'reactstrap';
|
||||||
|
import { TooltipToggleSwitch, TooltipToggleSwitchProps } from '../../src/utils/TooltipToggleSwitch';
|
||||||
|
import ToggleSwitch from '../../src/utils/ToggleSwitch';
|
||||||
|
|
||||||
|
describe('<TooltipToggleSwitch />', () => {
|
||||||
|
let wrapper: ShallowWrapper;
|
||||||
|
const createWrapper = (props: PropsWithChildren<TooltipToggleSwitchProps> = {}) => {
|
||||||
|
wrapper = shallow(<TooltipToggleSwitch {...props} />);
|
||||||
|
|
||||||
|
return wrapper;
|
||||||
|
};
|
||||||
|
|
||||||
|
afterEach(() => wrapper?.unmount());
|
||||||
|
|
||||||
|
it.each([
|
||||||
|
[ 'foo' ],
|
||||||
|
[ 'bar' ],
|
||||||
|
[ 'baz' ],
|
||||||
|
])('shows children inside tooltip', (children) => {
|
||||||
|
const wrapper = createWrapper({ children });
|
||||||
|
const tooltip = wrapper.find(UncontrolledTooltip);
|
||||||
|
|
||||||
|
expect(tooltip.prop('children')).toEqual(children);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('properly propagates corresponding props to every component', () => {
|
||||||
|
const expectedTooltipProps = { placement: 'left', delay: 30 };
|
||||||
|
const expectedToggleProps = { checked: true, className: 'foo' };
|
||||||
|
const wrapper = createWrapper({ tooltip: expectedTooltipProps, ...expectedToggleProps });
|
||||||
|
const tooltip = wrapper.find(UncontrolledTooltip);
|
||||||
|
const toggle = wrapper.find(ToggleSwitch);
|
||||||
|
|
||||||
|
expect(tooltip.props()).toEqual(expect.objectContaining(expectedTooltipProps));
|
||||||
|
expect(toggle.props()).toEqual(expect.objectContaining(expectedToggleProps));
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in a new issue