'use strict';

var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

var _enzyme = require('enzyme');

var _react = require('react');

var _react2 = _interopRequireDefault(_react);

var _ = require('../');

var _2 = _interopRequireDefault(_);

var _Wizard = require('../../../Wizard');

var _Wizard2 = _interopRequireDefault(_Wizard);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

var buildWrapper = function buildWrapper(props) {
  return (0, _enzyme.shallow)(_react2.default.createElement(
    _2.default,
    _extends({
      className: 'customTestClass',
      onStepChange: jest.fn(),
      steps: ['Step 1', 'Step 2', 'Step 3']
    }, props),
    'Test Child Content'
  ));
};

describe('LayoutWizard', function () {
  it('should render layout wizard content for the first step by default', function () {
    expect(buildWrapper()).toMatchSnapshot();
  });

  it('should render layout wizard content for the given initial step', function () {
    var wrapper = buildWrapper({ initialStepIndex: 1 });
    expect(wrapper).toMatchSnapshot();
  });

  describe('when the current step changes', function () {
    var wrapper = void 0;

    beforeEach(function () {
      wrapper = buildWrapper();

      var _wrapper$find$props = wrapper.find(_Wizard2.default).props(),
          onChangeStep = _wrapper$find$props.onChangeStep;

      onChangeStep(2);
    });

    it('should render the wizard at the new current step', function () {
      expect(wrapper).toMatchSnapshot();
    });

    it('should call "onStepChange" callback with the new step', function () {
      var _wrapper$instance = wrapper.instance(),
          onStepChange = _wrapper$instance.props.onStepChange;

      expect(onStepChange).toHaveBeenCalledWith(2);
    });
  });

  describe('when the component is "controlled"', function () {
    var wrapper = void 0;

    beforeEach(function () {
      wrapper = buildWrapper({ currentStep: 1 });
    });

    it('should render the wizard at the given current step', function () {
      expect(wrapper).toMatchSnapshot();
    });

    describe('when the step changes in the <Wizard /> component', function () {
      beforeEach(function () {
        var _wrapper$find$props2 = wrapper.find(_Wizard2.default).props(),
            onChangeStep = _wrapper$find$props2.onChangeStep;

        onChangeStep(2);
      });

      it('should keep rendering the wizard at the step specified by the "currentStep" prop', function () {
        expect(wrapper).toMatchSnapshot();
      });

      it('should call "onStepChange" callback with the new step', function () {
        var _wrapper$instance2 = wrapper.instance(),
            onStepChange = _wrapper$instance2.props.onStepChange;

        expect(onStepChange).toHaveBeenCalledWith(2);
      });
    });
  });
});