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

/*
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 { Select } from '../index.js';
import { STATE_CHANGE_TYPE, TYPE } from '../constants.js';
describe('Select component', function () {
  var wrapper;
  var props = {};
  var item = {
    id: 'id1',
    label: 'label1'
  };
  var options = [item, {
    id: 'id2',
    label: 'label2'
  }, {
    id: 'id3',
    label: 'bel3'
  }];
  beforeEach(function () {
    props = {
      options: options,
      onChange: jest.fn(),
      onInputChange: jest.fn(),
      onFocus: jest.fn(),
      onBlur: jest.fn()
    };
  });
  afterEach(function () {
    wrapper && wrapper.unmount();
  });
  test.each([[TYPE.select, false], [TYPE.select, true], [TYPE.search, false], [TYPE.search, true]])('renders component in %s mode and %s for multiple choice', function (type, multiple) {
    props.type = type;
    props.multiple = multiple;
    wrapper = mount(React.createElement(Select, props));
    expect(wrapper).toMatchSnapshot('Component has correct render in ' + type + ' mode and multiple choice equals ' + multiple);
  });
  test('calls onInputChange when input value changes', function () {
    wrapper = mount(React.createElement(Select, props));
    var e = {
      target: {
        value: 'test'
      }
    };
    wrapper.instance().handleInputChange(e);
    expect(props.onInputChange).toHaveBeenCalledWith(e);
  });
  test('removes selected tag on clear', function () {
    wrapper = mount(React.createElement(Select, _extends({}, props, {
      value: [item]
    })));
    var e = {
      type: 'click',
      button: 0,
      preventDefault: jest.fn()
    };
    wrapper.instance().clearValue(e);
    expect(props.onChange).toHaveBeenCalled();
    expect(props.onChange.mock.calls[0][0]).toEqual({
      type: STATE_CHANGE_TYPE.clear,
      option: null,
      value: []
    });
  });
  test('highlights the found item by default', function () {
    wrapper = mount(React.createElement(Select, props));
    var e = {
      target: {
        value: 'label1'
      }
    };
    wrapper.instance().handleInputChange(e);
    expect(wrapper.render().find('ul').html()).toMatch(/aria-activedescendant="true"/);
  });
});