/*
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 { shallow, mount } from 'enzyme';
import { StatefulInput, StyledInput, StatefulContainer } from '../index.js';
describe('', function () {
  test('basic render', function () {
    var props = {
      onChange: jest.fn(),
      overrides: {
        Input: function CustomInput(props) {
          return React.createElement("span", null, React.createElement(StyledInput, props));
        }
      }
    };
    var component = shallow(React.createElement(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 = mount(React.createElement(StatefulInput, props));
    var renderedStatefulContainer = component.find(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);
  });
});