/*
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 { mount } from 'enzyme';
import { StatefulContainer, MODE } from '../index.js';
describe('ButtonGroup StatefulContainer', function () {
  it('provides expected props to children render function', function () {
    var children = jest.fn(function () {
      return React.createElement("div", null, "children");
    });
    mount(React.createElement(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 = mount(React.createElement(StatefulContainer, {
      onClick: onClick
    }, function (childProps) {
      return React.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 = mount(React.createElement(StatefulContainer, {
      onClick: onClick,
      stateReducer: stateReducer
    }, function (childProps) {
      return React.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 = mount(React.createElement(StatefulContainer, {
      mode: MODE.radio,
      onClick: onClick,
      stateReducer: stateReducer
    }, function (childProps) {
      return React.createElement("div", childProps, "children");
    }));
    var element = wrapper.find('div').first();
    element.simulate('click');
    expect(stateReducer).toHaveBeenCalledTimes(1);
  });
});