"use strict";

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

var _enzyme = require("enzyme");

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

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

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

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

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([[_constants.TYPE.select, false], [_constants.TYPE.select, true], [_constants.TYPE.search, false], [_constants.TYPE.search, true]])('renders component in %s mode and %s for multiple choice', function (type, multiple) {
    props.type = type;
    props.multiple = multiple;
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Select, props));
    expect(wrapper).toMatchSnapshot('Component has correct render in ' + type + ' mode and mutiple choice equals ' + multiple);
  });
  test('calls onInputChange when input value changes', function () {
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.Select, props));
    var e = {
      target: {
        value: 'test'
      }
    };
    wrapper.instance().handleInputChange(e);
    expect(props.onInputChange).toHaveBeenCalledWith(e);
  });
  test('removes selected tag on clear', function () {
    wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.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: _constants.STATE_CHANGE_TYPE.clear,
      option: null,
      value: []
    });
  });
});