"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('ButtonGroup StatefulContainer', function () {
  it('provides expected props to children render function', function () {
    var children = jest.fn(function () {
      return _react.default.createElement("div", null, "children");
    });
    (0, _enzyme.mount)(_react.default.createElement(_index.StatefulContainer, null, children));
    var actual = children.mock.calls[0][0];
    expect(actual).toHaveProperty('onClick');
    expect(actual).toHaveProperty('selected', []);
  });
  it('calls provided click handler', function () {
    var onClick = jest.fn();
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulContainer, {
      onClick: onClick
    }, function (childProps) {
      return _react.default.createElement("div", childProps, "children");
    }));
    var element = wrapper.find('div').first();
    element.simulate('click');
    expect(onClick).toHaveBeenCalledTimes(1);
  });
  it('does not call state reducer if mode is not set', function () {
    var onClick = jest.fn();
    var stateReducer = jest.fn();
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulContainer, {
      onClick: onClick,
      stateReducer: stateReducer
    }, function (childProps) {
      return _react.default.createElement("div", childProps, "children");
    }));
    var element = wrapper.find('div').first();
    element.simulate('click');
    expect(stateReducer).toHaveBeenCalledTimes(0);
  });
  it('calls state reducer if mode is set', function () {
    var onClick = jest.fn();
    var stateReducer = jest.fn();
    var wrapper = (0, _enzyme.mount)(_react.default.createElement(_index.StatefulContainer, {
      mode: _index.MODE.radio,
      onClick: onClick,
      stateReducer: stateReducer
    }, function (childProps) {
      return _react.default.createElement("div", childProps, "children");
    }));
    var element = wrapper.find('div').first();
    element.simulate('click');
    expect(stateReducer).toHaveBeenCalledTimes(1);
  });
});