"use strict";

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

var _enzyme = require("enzyme");

var _dropdown = _interopRequireDefault(require("../dropdown"));

var _constants = require("../constants");

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

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

/*
Copyright (c) 2018 Uber Technologies, Inc.

This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.
*/
jest.mock('../../menu');
describe('SelectDropdown', function () {
  var wrapper;
  var props = {};
  var options = [{
    id: '1',
    label: 'label1'
  }, {
    id: '2',
    label: 'label2'
  }];
  var value = [{
    id: '1',
    label: 'label1'
  }];
  beforeEach(function () {
    props = {
      value: value,
      valueKey: 'id',
      labelKey: 'label',
      size: _constants.SIZE.default,
      options: options,
      onItemSelect: jest.fn(),
      getOptionLabel: jest.fn(function (_ref) {
        var option = _ref.option;
        return _react.default.createElement("span", null, "option.label");
      }),
      maxDropdownHeight: '1000px',
      overrides: {},
      error: false,
      isLoading: false,
      multi: false,
      required: false,
      searchable: true,
      type: _constants.TYPE.select
    };
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_dropdown.default, props));
  });
  afterEach(function () {
    wrapper && wrapper.unmount();
  });
  afterAll(function () {
    jest.restoreAllMocks();
  });
  test('renders StatefulMenu', function () {
    // $FlowFixMe
    var menuProps = _menu.StatefulMenu.mock.calls[0][0];
    expect(_menu.StatefulMenu).toHaveBeenCalled();
    expect(menuProps).toMatchObject({
      onItemSelect: props.onItemSelect,
      items: props.options,
      size: props.size
    });
    expect(menuProps.overrides).toMatchSnapshot('Passes correct overrides to the StatefulMenu');
  });
  test('getItemLabel is passed to a menu Option', function () {
    // $FlowFixMe
    var menuProps = _menu.StatefulMenu.mock.calls[1][0];
    expect(menuProps.overrides.Option.props.getItemLabel).toEqual(wrapper.instance().getItemLabel);
  });
  test('passes correct props to OptionContent', function () {
    var renderedOption = wrapper.instance().getItemLabel(options[1]);
    expect(renderedOption.props.$selected).toEqual(false);
    expect(renderedOption.props).toMatchSnapshot('OptionContent gets correct props when an option is not selected');
  });
  test('passes correct props to OptionContent for a selected item', function () {
    var renderedOption = wrapper.instance().getItemLabel(options[0]);
    expect(renderedOption.props.$selected).toEqual(true);
    expect(renderedOption.props).toMatchSnapshot('OptionContent gets correct props when an option is selected');
  });
});