/*
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.
*/
import React from 'react';
import { mount } from 'enzyme';
import { StatefulSelect, StatefulSelectContainer, StyledRoot, StyledControlContainer, StyledValueContainer, StyledPlaceholder, StyledSingleValue, StyledInputContainer, StyledInput, StyledInputSizer, StyledSelectArrow, StyledClearIcon, StyledSearchIcon, StyledOptionContent } from '../index.js';
import Select from '../select.js';
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: StyledRoot,
        ControlContainer: StyledControlContainer,
        ValueContainer: StyledValueContainer,
        Placeholder: StyledPlaceholder,
        SingleValue: StyledSingleValue,
        MultiValue: function MultiValueComponent(_ref) {
          var children = _ref.children;
          return React.createElement("div", null, children);
        },
        InputContainer: StyledInputContainer,
        Input: StyledInput,
        InputSizer: StyledInputSizer,
        SelectArrow: StyledSelectArrow,
        ClearIcon: StyledClearIcon,
        SearchIcon: StyledSearchIcon,
        OptionContent: StyledOptionContent
      }
    };
    wrapper = mount(React.createElement(StatefulSelect, props)); // $FlowFixMe

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

    var selectProps = Select.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 = mount(React.createElement(StatefulSelect, props));
    var renderedContainer = wrapper.find(StatefulSelectContainer).first();
    var params = {
      value: ''
    };
    renderedContainer.instance().onChange(params);
    expect(props.onChange).toHaveBeenCalledWith(params);
  });
});