"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('NavigationContainer', function () {
  test('basic render', function () {
    var props = {
      highlightedDate: new Date(),
      onSelect: jest.fn(),
      stateReducer: jest.fn()
    };
    var children = jest.fn();
    (0, _enzyme.shallow)(_react.default.createElement(_index.NavigationContainer, props, children));
    expect(children).toHaveBeenCalledTimes(1);
  });
  describe('Children function receives correct props', function () {
    var props = {
      highlightedDate: new Date(),
      stateReducer: jest.fn(),
      onSelect: jest.fn(),
      onDayMouseOver: jest.fn(),
      onDayMouseLeave: jest.fn()
    };
    var children = jest.fn();
    var eArgs = {
      date: new Date(),
      event: {}
    };
    var component = (0, _enzyme.shallow)(_react.default.createElement(_index.NavigationContainer, props, children));
    var handlers = [['onDayMouseOver', true], ['onDayMouseLeave', true], ['onSelect', true]];
    test.each(handlers)('Event handlers', function (handler, replaced) {
      // event handler is passed to children function
      var childrenHandler = children.mock.calls[0][0][handler];

      if (replaced) {
        expect(childrenHandler).toBe(component.instance()[handler]);
        expect(childrenHandler).not.toBe(props[handler]);
      } else {
        expect(childrenHandler).toBe(props[handler]);
      } // event handler from props is called
      // $FlowFixMe


      childrenHandler(eArgs);
      expect(props[handler]).toHaveBeenCalledTimes(1);
      expect(props[handler]).toHaveBeenLastCalledWith(eArgs);
    });
  });
  test('stateReducer', function () {
    var props = {
      highlightedDate: new Date(2010, 6, 8),
      stateReducer: jest.fn()
    };
    var children = jest.fn();
    var state = {
      highlightedDate: new Date(2010, 6, 8)
    };
    var stateUpdated = {
      highlightedDate: new Date(2010, 6, 1)
    };
    var component = (0, _enzyme.shallow)(_react.default.createElement(_index.NavigationContainer, props, children));
    props.stateReducer.mockReturnValueOnce(state);
    component.instance().onKeyDown({
      key: 'ArrowUp',
      preventDefault: function preventDefault() {},
      stopPropagation: function stopPropagation() {}
    });
    expect(props.stateReducer).toHaveBeenCalledTimes(1);
    expect(props.stateReducer.mock.calls[0][0]).toEqual(_index.STATE_CHANGE_TYPE.moveUp);
    expect(props.stateReducer.mock.calls[0][1]).toEqual(stateUpdated);
    expect(props.stateReducer.mock.calls[0][2]).toMatchObject(state);
    expect(component).toHaveState('highlightedDate', state.highlightedDate);
  });
});