"use strict";

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

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

var _build = _interopRequireWildcard(require("enzyme/build"));

var _build2 = _interopRequireDefault(require("enzyme-adapter-react-16/build"));

var _MagnifyIcon = _interopRequireDefault(require("mdi-react/MagnifyIcon"));

var _Form = require("../../Form");

function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }

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

_build.default.configure({
  adapter: new _build2.default()
});

describe('ExpandingInputButton', function () {
  it('should render when expanded', function () {
    var wrapper = (0, _build.shallow)(_react.default.createElement(_index.ExpandingInputButton, {
      icon: _react.default.createElement(_MagnifyIcon.default, null),
      expanded: true,
      onFocus: function onFocus() {},
      onBlur: function onBlur() {},
      onClear: function onClear() {},
      onChange: function onChange() {},
      placeholder: '',
      value: ''
    }));
    var inputButton = wrapper.find('.vs-expanding-input-button');
    expect(inputButton).toHaveLength(1);
    expect(inputButton.contains(_react.default.createElement(_MagnifyIcon.default, null))).toEqual(true);
    expect(inputButton.find('Input').length).toEqual(1);
    expect(inputButton.find('WindowCloseIcon').length).toEqual(1);
  });
  it('should render when not expanded', function () {
    var wrapper = (0, _build.shallow)(_react.default.createElement(_index.ExpandingInputButton, {
      icon: _react.default.createElement(_MagnifyIcon.default, null),
      expanded: false,
      onFocus: function onFocus() {},
      onBlur: function onBlur() {},
      onClear: function onClear() {},
      onChange: function onChange() {},
      placeholder: '',
      value: ''
    }));
    var inputButton = wrapper.find('.vs-expanding-input-button');
    expect(inputButton).toHaveLength(1);
    expect(inputButton.contains(_react.default.createElement(_MagnifyIcon.default, null))).toEqual(true);
    expect(inputButton.find('Input').length).toEqual(1);
    expect(inputButton.find('WindowCloseIcon').length).toEqual(0);
  });
  it('should call onChange when typing text', function () {
    var mockOnChange = jest.fn();
    var wrapper = (0, _build.shallow)(_react.default.createElement(_index.ExpandingInputButton, {
      onChange: mockOnChange,
      expanded: false,
      onFocus: function onFocus() {},
      onBlur: function onBlur() {},
      onClear: function onClear() {},
      placeholder: '',
      value: ''
    }));
    wrapper.find('Input').simulate('focus');
    wrapper.find('Input').simulate('change', {
      target: {
        value: 'test'
      }
    });
    expect(mockOnChange.mock.calls).toHaveLength(1);
    expect(mockOnChange.mock.calls[0][0]).toEqual({
      target: {
        value: 'test'
      }
    });
  });
  it('should clear text when clicking close button', function () {
    var mockOnClear = jest.fn();
    var wrapper = (0, _build.shallow)(_react.default.createElement(_index.ExpandingInputButton, {
      onClear: mockOnClear,
      value: "test",
      expanded: true
    }));
    wrapper.find('Input').simulate('focus');
    wrapper.find('WindowCloseIcon').simulate('click');
    expect(mockOnClear.mock.calls).toHaveLength(1);
  });
});