Skip to content

Commit

Permalink
[shared][tooltip][tests] test coords override in onMouseMove
Browse files Browse the repository at this point in the history
  • Loading branch information
williaster committed Dec 6, 2017
1 parent cdcb43f commit a1d7310
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions packages/shared/test/enhancer/WithTooltip.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,33 @@ describe('<WithTooltip />', () => {
expect(wrapper.find('#test').length).toBe(1);
});

test.only('it should use the provided `coords` if passed to onMouseMove', () => {
let mouseMove;
const wrapper = mount(
<WithTooltip
TooltipComponent={({ top, left, children }) => (
<div style={{ top, left }} id="tooltip">{children}</div>
)}
renderTooltip={() => <div id="test" />}
>
{({ onMouseMove }) => {
mouseMove = onMouseMove;
return <svg />;
}}
</WithTooltip>,
);

mouseMove({ coords: {} });
wrapper.update();
expect(wrapper.find('#tooltip').prop('style').top).toBe(0);
expect(wrapper.find('#tooltip').prop('style').left).toBe(0);

mouseMove({ coords: { x: 27, y: 13 } });
wrapper.update();
expect(wrapper.find('#tooltip').prop('style').top).toBe(13);
expect(wrapper.find('#tooltip').prop('style').left).toBe(27);
});

test('it should not render a tooltip if renderTooltip returns a falsy value', () => {
const renderTooltip = jest.fn();
renderTooltip.mockReturnValue(<div id="test" />);
Expand Down

0 comments on commit a1d7310

Please sign in to comment.