function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; var ownKeys = Object.keys(source); if (typeof Object.getOwnPropertySymbols === 'function') { ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) { return Object.getOwnPropertyDescriptor(source, sym).enumerable; })); } ownKeys.forEach(function (key) { _defineProperty(target, key, source[key]); }); } return target; }

function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return 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.
*/
import React from 'react';
import { mount } from 'enzyme';
import { StatefulContainer as StatefulSliderContainer } from '../index.js';
import { STATE_CHANGE_TYPE } from '../constants.js';
describe('Stateful Slider Container', function () {
  var allProps, childFn;
  var wrapper;
  beforeEach(function () {
    var stateReducer = function stateReducer(type, nextState) {
      return nextState;
    };

    childFn = jest.fn(function () {
      return React.createElement("div", null, "test");
    });
    allProps = {
      children: childFn,
      initialState: {},
      stateReducer: stateReducer,
      prop1: 'some other slider prop'
    };
  });
  afterEach(function () {
    jest.restoreAllMocks();
    wrapper && wrapper.unmount();
  });
  test('should correctly render', function () {
    wrapper = mount(React.createElement(StatefulSliderContainer, allProps));
    expect(wrapper).toMatchSnapshot('Component has correct render ');
  });
  test('should provide all needed props to children render func', function () {
    wrapper = mount(React.createElement(StatefulSliderContainer, allProps));
    var actualProps = childFn.mock.calls[0][0];
    expect(actualProps).toMatchObject({
      prop1: allProps.prop1
    });
  });
  test('should provide initial state as part of state', function () {
    allProps.initialState = {
      value: [30, 80]
    };
    wrapper = mount(React.createElement(StatefulSliderContainer, allProps));
    var actualProps = childFn.mock.calls[0][0];
    expect(actualProps).toMatchObject(allProps.initialState);
  });
  describe('Events', function () {
    var value = [40];
    var events, stateReducerMock, instance, event;
    event = {
      target: {}
    };
    var handlers = [['onChange', STATE_CHANGE_TYPE.change, {
      value: value
    }]];
    beforeEach(function () {
      events = {
        onChange: jest.fn()
      };
      allProps = _objectSpread({}, allProps, events);
      stateReducerMock = jest.fn();
      allProps.stateReducer = stateReducerMock;
      wrapper = mount(React.createElement(StatefulSliderContainer, allProps));
      instance = wrapper.instance();
    });
    test.each(handlers)('should call state reducer to apply new state for %s event with %s type', function (eventHandler, type, newState) {
      var handler = instance[eventHandler];

      var params = _objectSpread({}, newState);

      handler(_objectSpread({
        event: event
      }, params));
      expect(stateReducerMock).toHaveBeenCalledWith(type, newState, {}, event);
      expect(events[eventHandler]).toHaveBeenCalledWith(_objectSpread({
        event: event
      }, params));
    });
  });
});