diff --git a/src/utils/TooltipToggleSwitch.tsx b/src/utils/TooltipToggleSwitch.tsx index 6acfba70..0c708bcc 100644 --- a/src/utils/TooltipToggleSwitch.tsx +++ b/src/utils/TooltipToggleSwitch.tsx @@ -4,9 +4,9 @@ import { UncontrolledTooltipProps } from 'reactstrap/lib/Tooltip'; import { BooleanControlProps } from './BooleanControl'; import ToggleSwitch from './ToggleSwitch'; -export const TooltipToggleSwitch: FC }> = ( - { children, tooltip = {}, ...rest }, -) => { +export type TooltipToggleSwitchProps = BooleanControlProps & { tooltip?: Omit }; + +export const TooltipToggleSwitch: FC = ({ children, tooltip = {}, ...rest }) => { const ref = useRef(); return ( diff --git a/test/utils/TooltipToggleSwitch.test.tsx b/test/utils/TooltipToggleSwitch.test.tsx new file mode 100644 index 00000000..d35906d5 --- /dev/null +++ b/test/utils/TooltipToggleSwitch.test.tsx @@ -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('', () => { + let wrapper: ShallowWrapper; + const createWrapper = (props: PropsWithChildren = {}) => { + wrapper = shallow(); + + 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)); + }); +});