// @flow
import React from 'react';
import { mountWrappedComponent, renderSnapshot } from '../../../../utils/tests';

import type { TooltipProps, ReferenceArgs } from './tooltip.proptypes';
import { Tooltip } from './index';

const REFERENCE_PROPS = {
  ref: () => {},
  referenceProps: {
    onMouseEnter: () => {},
    onMouseLeave: () => {},
    onFocus: () => {},
    onBlur: () => {},
  },
};

const DEFAULT_PROPS: TooltipProps = {
  reference: ({ referenceProps, ref }: ReferenceArgs) => (
    <div {...referenceProps} ref={ref}>
      Reference element
    </div>
  ),
  placement: 'left',
  children: '',
};

describe('Tooltip', () => {
  describe('snapshot', () => {
    it('matches the previous snapshot', () => {
      // set isVisible so that tooltip is always rendered
      const tooltip = renderSnapshot(<Tooltip isVisible {...DEFAULT_PROPS} />);

      expect(tooltip).toMatchSnapshot();
    });
  });

  it('renders the reference element', () => {
    const tooltip = mountWrappedComponent(<Tooltip {...DEFAULT_PROPS} />);
    const referenceElement = tooltip.renderProp('reference')(REFERENCE_PROPS);
    expect(referenceElement.text()).toBe('Reference element');
  });
});
