'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 _semanticUiReact = require('semantic-ui-react');

var _BasicControls = require('../BasicControls');

var _BasicControls2 = _interopRequireDefault(_BasicControls);

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

var buildWrapper = function buildWrapper(props) {
  return (0, _enzyme.shallow)(_react2.default.createElement(_BasicControls2.default, _extends({
    currentStep: 1,
    onChangeStep: jest.fn(),
    totalSteps: 3
  }, props)));
};

describe('WizardFooterBasicControls', function () {
  it('should render "cancel", "previous" and "next" buttons', function () {
    expect(buildWrapper()).toMatchSnapshot();
  });

  describe('when the current step is the first step', function () {
    it('should render "cancel" and "next" buttons', function () {
      var wrapper = buildWrapper({ currentStep: 0 });
      expect(wrapper).toMatchSnapshot();
    });
  });

  describe('when the "showBackOnFirstStep" prop is true', function () {
    describe('when the current step is the first step', function () {
      it('should render "cancel", "previous" and "next" buttons', function () {
        var wrapper = buildWrapper({
          currentStep: 0,
          showBackOnFirstStep: true
        });
        expect(wrapper).toMatchSnapshot();
      });
    });
  });

  describe('when the current step is the last step', function () {
    it('should render "cancel", "previous" and "finish" buttons', function () {
      var wrapper = buildWrapper({ currentStep: 2 });
      expect(wrapper).toMatchSnapshot();
    });

    it('should call the "onFinish" prop when the "finish" button is clicked', function () {
      var onFinish = jest.fn();
      var wrapper = buildWrapper({ currentStep: 2, onFinish: onFinish });
      var button = wrapper.find(_semanticUiReact.Button).at(2);
      button.simulate('click');
      expect(onFinish).toHaveBeenCalled();
    });
  });

  describe('when the "showSaveButton" prop is set to "true"', function () {
    it('should render "cancel", "previous", "save" and "next" buttons', function () {
      var wrapper = buildWrapper({ showSaveButton: true });
      expect(wrapper).toMatchSnapshot();
    });

    it('should call the "onSave" prop when the "save" button is clicked', function () {
      var onSave = jest.fn();
      var wrapper = buildWrapper({ showSaveButton: true, onSave: onSave });
      var button = wrapper.find(_semanticUiReact.Button).at(2);
      button.simulate('click');
      expect(onSave).toHaveBeenCalled();
    });
  });

  describe('when the "next" button is clicked', function () {
    it('should call "onChangeStep" with the next step index', function () {
      var onChangeStep = jest.fn();
      var wrapper = buildWrapper({ onChangeStep: onChangeStep });
      var button = wrapper.find(_semanticUiReact.Button).at(2);
      button.simulate('click');
      expect(onChangeStep).toHaveBeenCalledWith(2);
    });
  });

  describe('when the "previous" button is clicked', function () {
    it('should call "onChangeStep" with the previous step index', function () {
      var onChangeStep = jest.fn();
      var wrapper = buildWrapper({ onChangeStep: onChangeStep });
      var button = wrapper.find(_semanticUiReact.Button).at(1);
      button.simulate('click');
      expect(onChangeStep).toHaveBeenCalledWith(0);
    });
  });

  it('should call the "onCancel" prop when the "cancel" button is clicked', function () {
    var onCancel = jest.fn();
    var wrapper = buildWrapper({ onCancel: onCancel });
    var button = wrapper.find(_semanticUiReact.Button).at(0);
    button.simulate('click');
    expect(onCancel).toHaveBeenCalled();
  });
});