"use strict";

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

var _enzyme = require("enzyme");

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

var _select = _interopRequireDefault(require("../select.js"));

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('../select');
describe('Stateful select', function () {
  var wrapper = null;
  afterEach(function () {
    wrapper && wrapper.unmount();
  });
  afterAll(function () {
    jest.restoreAllMocks();
  });
  test('should provide default styled components to render', function () {
    var props = {
      overrides: {
        Root: _index.StyledRoot,
        ControlContainer: _index.StyledControlContainer,
        ValueContainer: _index.StyledValueContainer,
        Placeholder: _index.StyledPlaceholder,
        SingleValue: _index.StyledSingleValue,
        MultiValue: function MultiValueComponent(_ref) {
          var children = _ref.children;
          return _react.default.createElement("div", null, children);
        },
        InputContainer: _index.StyledInputContainer,
        Input: _index.StyledInput,
        InputSizer: _index.StyledInputSizer,
        SelectArrow: _index.StyledSelectArrow,
        ClearIcon: _index.StyledClearIcon,
        SearchIcon: _index.StyledSearchIcon,
        OptionContent: _index.StyledOptionContent
      }
    };
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulSelect, props)); // $FlowFixMe

    var overrides = _select.default.mock.calls[0][0].overrides;
    expect(overrides).toEqual(props.overrides);
    expect(_select.default).toHaveBeenCalled();
  });
  test('should pass value and other props to stateless select', function () {
    var props = {
      initialState: {
        value: [{
          id: 'id'
        }]
      },
      onChange: jest.fn(),
      multi: true
    };
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulSelect, props));
    var renderedContainer = wrapper.find(_index.StatefulSelectContainer).first(); // $FlowFixMe

    var selectProps = _select.default.mock.calls[1][0];
    expect(selectProps).toMatchObject({
      value: props.initialState.value,
      multi: props.multi,
      onChange: renderedContainer.instance().onChange
    });
  });
  test('should call onChange from props', function () {
    var props = {
      onChange: jest.fn()
    };
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulSelect, props));
    var renderedContainer = wrapper.find(_index.StatefulSelectContainer).first();
    var params = {
      value: ''
    };
    renderedContainer.instance().onChange(params);
    expect(props.onChange).toHaveBeenCalledWith(params);
  });
});