"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.
*/
test('MaskedInput - basic functionality', function () {
  var props = {
    mask: '(999) 999-9999',
    placeholder: 'Placeholder',
    onFocus: jest.fn(),
    onBlur: jest.fn(),
    onChange: jest.fn(),
    onKeyDown: jest.fn(),
    onKeyPress: jest.fn(),
    onKeyUp: jest.fn(),
    overrides: {
      Before: jest.fn().mockImplementation(function () {
        return _react.default.createElement("span", null);
      }),
      After: jest.fn().mockImplementation(function () {
        return _react.default.createElement("span", null);
      })
    }
  }; // $FlowFixMe

  var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.MaskedInput, props)); // Renders input, before and after

  var renderedInput = wrapper.find('input').first();
  expect(renderedInput).toExist();
  expect(renderedInput.props()).toMatchSnapshot('Masked input has correct props');
  var renderedBefore = wrapper.find(props.overrides.Before);
  expect(renderedBefore).toHaveLength(1);
  expect(renderedBefore.props()).toMatchSnapshot('Before gets correct props');
  var renderedAfter = wrapper.find(props.overrides.After);
  expect(renderedAfter).toHaveLength(1);
  expect(renderedAfter.props()).toMatchSnapshot('After gets correct props'); // onFocus handler from props is called

  renderedInput.simulate('focus');
  expect(props.onFocus).toBeCalled(); // onBlur handler from props is called

  renderedInput.simulate('blur');
  expect(props.onBlur).toBeCalled(); // onChange handler from props is called

  renderedInput.simulate('change');
  expect(props.onChange).toBeCalled(); // onKeyDown handler from props is called

  renderedInput.simulate('keyDown', {
    keyCode: 40
  });
  expect(props.onKeyDown).toBeCalled(); // onKeyPress handler from props is called

  renderedInput.simulate('keyPress', {
    keyCode: 40
  });
  expect(props.onKeyPress).toBeCalled(); // onKeyUp handler from props is called

  renderedInput.simulate('keyUp', {
    keyCode: 40
  });
  expect(props.onKeyUp).toBeCalled(); // Correct props passed when error state

  wrapper.setProps({
    error: true
  });
  var updatedBefore = wrapper.find(props.overrides.Before);
  expect(updatedBefore.props()).toMatchSnapshot('Before gets correct error prop');
  var updatedAfter = wrapper.find(props.overrides.After);
  expect(updatedAfter.props()).toMatchSnapshot('After gets correct error prop');
});