"use strict";

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

var _enzyme = require("enzyme");

var _index = require("../index.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.
*/
describe('', function () {
  test('basic render', function () {
    var props = {
      onChange: jest.fn(),
      overrides: {
        Input: function CustomInput(props) {
          return _react.default.createElement("span", null, _react.default.createElement(_index.StyledInput, props));
        }
      }
    };
    var component = (0, _enzyme.shallow)(_react.default.createElement(_index.StatefulInput, props));
    expect(component).toMatchSnapshot('renders <StatefulContainer/>');
    expect(component.dive()).toMatchSnapshot('renders <Input/> as a child');
  });
  test('onChange handling and state updates', function () {
    var props = {
      onChange: jest.fn(),
      stateReducer: jest.fn().mockImplementation(function (type, nextState) {
        return nextState;
      })
    };
    var newValue = 'new value';
    var event = {
      target: {
        value: newValue
      }
    };
    var component = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulInput, props));
    var renderedStatefulContainer = component.find(_index.StatefulContainer).first();
    var statefulContainerInstance = renderedStatefulContainer.instance();
    expect(statefulContainerInstance.state.value).toEqual('');
    statefulContainerInstance.onChange(event);
    expect(props.stateReducer).toHaveBeenCalledWith('change', {
      value: newValue
    }, {
      value: ''
    });
    expect(statefulContainerInstance.state.value).toEqual(newValue);
  });
});