"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('StatefulPanelContainer', function () {
  test('basic render', function () {
    var props = {
      overrides: {
        PanelContainer: function CustomContainer() {
          return _react.default.createElement("div", null);
        }
      },
      initialState: {
        expanded: true
      },
      onChange: jest.fn(),
      stateReducer: jest.fn()
    };
    var children = jest.fn();
    (0, _enzyme.shallow)(_react.default.createElement(_index.StatefulPanelContainer, props, children));
    expect(children).toHaveBeenCalledTimes(1);
  });
  test('children function receives the correct expanded prop value', function () {
    var props = {
      initialState: {
        expanded: true
      },
      stateReducer: jest.fn()
    };
    var children = jest.fn();
    var component = (0, _enzyme.shallow)(_react.default.createElement(_index.StatefulPanelContainer, props, children));
    expect(children).toHaveBeenCalledTimes(1);
    var childrenOnClickProp = children.mock.calls[0][0].expanded;
    expect(childrenOnClickProp).toEqual(component.instance().state.expanded);
    expect(childrenOnClickProp).toEqual(props.initialState.expanded);
  });
  test('onChange handler sets state and calls onChange handler from props', function () {
    var props = {
      onChange: jest.fn()
    };
    var children = jest.fn();
    var component = (0, _enzyme.shallow)(_react.default.createElement(_index.StatefulPanelContainer, props, children));
    expect(component).toHaveState('expanded', false);
    component.instance().onChange();
    expect(component).toHaveState('expanded', true);
    expect(props.onChange).toHaveBeenCalledWith({
      expanded: true
    });
  });
  test('stateReducer', function () {
    var props = {
      stateReducer: jest.fn()
    };
    var children = jest.fn();
    var component = (0, _enzyme.shallow)(_react.default.createElement(_index.StatefulPanelContainer, props, children));
    expect(component).toHaveState('expanded', false);
    props.stateReducer.mockReturnValueOnce({
      expanded: false
    });
    component.instance().onChange();
    expect(props.stateReducer).toHaveBeenCalledTimes(1);
    expect(props.stateReducer).toHaveBeenLastCalledWith(_index.STATE_CHANGE_TYPE.expand, {
      expanded: true
    }, {
      expanded: false
    });
    expect(component).toHaveState('expanded', false);
  });
});