"use strict";

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

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

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

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 }; }

function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }

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

var getStyles = function getStyles() {
  // Returns an ES6 Proxy that pretends to have a value for any prop you give it
  return new Proxy({}, {
    get: function get(_, prop) {
      return prop;
    }
  });
};

describe('ButtonWithDropDown', function () {
  test('expanded works', function () {
    var expanded = (0, _enzyme.shallow)(_react.default.createElement(uut.ButtonWithDropdown, {
      expanded: true,
      styles: getStyles(),
      buttonContent: ""
    }));
    expect(expanded.find('.vs-dropdown.vs-visible')).toHaveLength(1);
    var collapsed = (0, _enzyme.shallow)(_react.default.createElement(uut.ButtonWithDropdown, {
      expanded: false,
      styles: getStyles(),
      buttonContent: ""
    }));
    expect(collapsed.find('.vs-dropdown.vs-visible')).toHaveLength(0);
    expect(collapsed.find('.vs-dropdown')).toHaveLength(1);
  });
  test('button wired correctly', function () {
    var doExpand = function doExpand() {};

    var component = (0, _enzyme.shallow)(_react.default.createElement(uut.ButtonWithDropdown, {
      expanded: true,
      doExpand: doExpand,
      buttonContent: "hi",
      className: "newClass",
      id: "id",
      styles: getStyles()
    }, _react.default.createElement("div", {
      id: "target"
    })));
    expect(component.find('.newClass-button').shallow().text().slice(0, 2)).toEqual('hi');
    expect(component.find('.newClass-button').prop('onClick')).toEqual(doExpand);
    expect(component.prop('className')).toMatch(/.*\bnewClass\b.*/);
    expect(component.prop('id')).toEqual('id');
    expect(component.find('.vs-dropdown #target')).toHaveLength(1);
  });
  test('uses renderButton render prop', function () {
    var doExpand = function doExpand() {};

    var renderButton = function renderButton(props) {
      return _react.default.createElement("div", _extends({}, props, {
        id: "button"
      }));
    };

    var component = (0, _enzyme.shallow)(_react.default.createElement(uut.ButtonWithDropdown, {
      expanded: true,
      doExpand: doExpand,
      buttonContent: "hi",
      className: "newClass",
      id: "id",
      styles: getStyles(),
      renderButton: renderButton
    }, _react.default.createElement("div", {
      id: "target"
    })));
    var button = component.find('#button');
    expect(button).toHaveLength(1);
    expect(button.prop('expanded')).toEqual(true);
    expect(button.prop('onClick')).toEqual(doExpand);
    expect(button.text()).toEqual('hi');
  });
});