"use strict";

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

var _enzyme = require("enzyme");

var _styledComponents = require("../styled-components.js");

var _optionList = _interopRequireDefault(require("../option-list.js"));

var _menu = _interopRequireDefault(require("../menu.js"));

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

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }

var mockItems = [{
  label: 'item1'
}, {
  label: 'item2'
}];

function getSharedProps() {
  return {
    items: mockItems,
    getItemLabel: function getItemLabel(item) {
      return item.label;
    },
    rootRef: _react.default.createRef()
  };
}

describe('Menu Stateless Component', function () {
  test('basic renders', function () {
    var component = (0, _enzyme.mount)(_react.default.createElement(_menu.default, getSharedProps()));
    expect(component.find(_styledComponents.List)).toExist();
    expect(component.find(_styledComponents.List)).toHaveProp({
      $ref: _react.default.createRef()
    });
    expect(component.find(_optionList.default)).toExist();
    component.setProps({
      getRequiredItemProps: function getRequiredItemProps(item, index) {
        return {
          key: String(index),
          isHighlighted: true
        };
      }
    });
    expect(component.find(_optionList.default).first()).toHaveProp({
      $isHighlighted: true
    });
  });
  test('renders with components overrides', function () {
    var NewOption = function NewOption() {
      return _react.default.createElement("div", null);
    };

    var props = _objectSpread({}, getSharedProps(), {
      overrides: {
        Option: {
          component: NewOption,
          props: {
            custom: 'prop'
          }
        }
      }
    });

    var component = (0, _enzyme.mount)(_react.default.createElement(_menu.default, props));
    expect(component.find(_optionList.default)).not.toExist();
    expect(component.find(NewOption)).toExist();
    expect(component.find(NewOption).first().prop('custom')).toEqual('prop');
  });
});