"use strict";

var _react = _interopRequireDefault(require("react"));

var _index = _interopRequireWildcard(require("../index"));

var _enzyme = _interopRequireWildcard(require("enzyme"));

var _reactPopper = require("react-popper");

var _enzymeAdapterReact = _interopRequireDefault(require("enzyme-adapter-react-16"));

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

_enzyme.default.configure({
  adapter: new _enzymeAdapterReact.default()
});

describe('Popover', function () {
  it('should render when told to show and default placement bottom', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: true
    }));
    expect(wrapper.find('.vs-popover-container')).toHaveLength(1);
    expect(wrapper.find(_reactPopper.Popper).prop('placement')).toBe('bottom');
  });
  it('should be hidden when not shown', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: false
    }));
    expect(wrapper.find('.vs-popover-container')).toHaveLength(0);
  });
  it('should accept a placement prop to control default placement', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: true,
      placement: 'right'
    }));
    expect(wrapper.find(_reactPopper.Popper).prop('placement')).toBe('right');
  });
  it('should render children as the reference element', function () {
    var expectedChildElement = _react.default.createElement("div", {
      className: 'test-target-element'
    });

    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: false
    }, expectedChildElement));
    expect(wrapper.find('.vs-popover-reference').find('.test-target-element')).toHaveLength(1);
    expect(wrapper.find('.vs-popover-reference').children().getElement()).toEqual(expectedChildElement);
  });
  it('should render content as the popover content', function () {
    var expectedContentElement = _react.default.createElement("div", {
      className: 'test-target-content-element'
    });

    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: true,
      content: expectedContentElement
    }, _react.default.createElement("div", {
      className: 'test-target-element'
    })));
    expect(wrapper.find('.vs-popover-container').find('.test-target-content-element')).toHaveLength(1);
    expect(wrapper.find('.vs-popover-content').children().at(0).getElement()).toEqual(expectedContentElement);
  });
  it('should call onMouseOver and onMouseLeave events', function () {
    var onMouseOver = jest.fn();
    var onMouseLeave = jest.fn();
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: false,
      onMouseOver: onMouseOver,
      onMouseLeave: onMouseLeave
    }, _react.default.createElement("div", {
      className: 'test-target-element'
    })));
    wrapper.find('.vs-popover-wrapper').simulate('mouseOver');
    expect(onMouseOver).toHaveBeenCalled();
    wrapper.find('.vs-popover-wrapper').simulate('mouseLeave');
    expect(onMouseLeave).toHaveBeenCalled();
  });
  it('should pass popper props down to popper', function () {
    var eventsEnabled = false;
    var modifiers = {
      flip: {
        enabled: false
      }
    };
    var positionFixed = true;
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.default, {
      shown: true,
      eventsEnabled: eventsEnabled,
      modifiers: modifiers,
      positionFixed: positionFixed
    }, _react.default.createElement("div", {
      className: 'test-target-element'
    })));
    var popper = wrapper.find(_reactPopper.Popper);
    expect(popper.prop("eventsEnabled")).toBe(eventsEnabled);
    expect(popper.prop("modifiers")).toBe(modifiers);
    expect(popper.prop("positionFixed")).toBe(positionFixed);
  });
});
describe('HoverPopover', function () {
  it('should show when hovered over and hide when mouse leaves', function () {
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.HoverPopover, null, _react.default.createElement("div", {
      className: 'test-target-element'
    })));
    expect(wrapper.find(_index.default).prop('shown')).toBe(false);
    wrapper.find('.vs-popover-wrapper').simulate('mouseOver');
    expect(wrapper.find(_index.default).prop('shown')).toBe(true);
    wrapper.find('.vs-popover-wrapper').simulate('mouseLeave');
    expect(wrapper.find(_index.default).prop('shown')).toBe(false);
  });
});