"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));

var _react = _interopRequireDefault(require("react"));

var _enzyme = require("enzyme");

var _ = _interopRequireDefault(require("."));

var _Button = _interopRequireDefault(require("../../../../components/Button"));

var _Input = _interopRequireDefault(require("../../../../components/Input"));

var _Textarea = _interopRequireDefault(require("../../../../components/Textarea"));

var _2 = require("../..");

var _stepDefaults = require("../../constants/stepDefaults");

function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }

function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { (0, _defineProperty2["default"])(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }

describe('TutorialStep', function () {
  var node;
  var props;
  beforeEach(function () {
    props = {
      step: _stepDefaults.DEFAULT_STEP,
      index: 1,
      lastIndex: 2,
      shiftOrder: jest.fn(),
      navStep: jest.fn(),
      handleClick: jest.fn(),
      deleteStep: jest.fn(),
      updateStep: jest.fn()
    };
    node = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_2.PermissionContext.Provider, {
      value: false
    }, /*#__PURE__*/_react["default"].createElement(_["default"], props)));
  });
  it('should display the TutorialCard component', function () {
    expect(node.find('.TutorialStep').find('header')).toHaveLength(1);
  });
  it('should display a footer in readonly view while open', function () {
    var n2 = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_["default"], props));
    expect(n2.find('.TutorialStep').find('footer')).toHaveLength(1);
  });
  describe('component prop events', function () {
    describe('updateStep()', function () {
      it('should call updateStep with title key on title input', function () {
        var event = {
          target: {
            name: 'test',
            value: true,
            id: 'title-status'
          }
        };
        var input = node.find('.TutorialStep').find(_Input["default"]).find('.Input');
        input.simulate('change', event);
        expect(props.updateStep).toHaveBeenCalledWith({
          status: true
        });
      });
      it('should call updateStep with body key on body input', function () {
        var event = {
          target: {
            name: 'test',
            value: true,
            id: 'body-status'
          }
        };
        var textarea = node.find('.TutorialStep').find(_Textarea["default"]).find('.TextArea');
        textarea.simulate('change', event);
        expect(props.updateStep).toHaveBeenCalledWith({
          status: true
        });
      });
    });
    describe('shiftOrder()', function () {
      it('should be called with -1 when up arrow is selected', function () {
        var button = node.find('.TutorialStep').find(_Button["default"]).find('button').first();
        button.simulate('click');
        expect(props.shiftOrder).toHaveBeenCalledWith(-1);
      });
      it('should be called with 1 when down arrow is selected', function () {
        var button = node.find('.TutorialStep').find(_Button["default"]).find('button').at(1);
        button.simulate('click');
        expect(props.shiftOrder).toHaveBeenCalledWith(1);
      });
      it('should call handleClick while selecting a closed step', function () {
        var props2 = {
          step: _objectSpread(_objectSpread({}, _stepDefaults.DEFAULT_STEP), {}, {
            isOpen: false
          }),
          index: 1,
          lastIndex: 2,
          shiftOrder: jest.fn(),
          navStep: jest.fn(),
          handleClick: jest.fn(),
          deleteStep: jest.fn(),
          updateStep: jest.fn()
        };
        var n2 = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_2.PermissionContext.Provider, {
          value: false
        }, /*#__PURE__*/_react["default"].createElement(_["default"], props2)));
        var event = {
          target: {
            name: 'test',
            value: '',
            nodeName: 'Button'
          }
        };
        var button = n2.find('.TutorialStep').find(_Button["default"]).find('button').first();
        button.simulate('click', event);
        expect(props2.handleClick).toHaveBeenCalled();
      });
    });
    it('should call deleteStep() with index', function () {
      var button = node.find('.TutorialStep').find(_Button["default"]).find('button').at(2);
      button.simulate('click');
      expect(props.deleteStep).toHaveBeenCalledWith(1);
    });
    describe('readonly events', function () {
      var node2;
      beforeEach(function () {
        node2 = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_["default"], props));
      });
      it('should call navStep with 1 while navigating next', function () {
        var button = node2.find('.TutorialStep').find('footer').find('button').last();
        button.simulate('click');
        expect(props.navStep).toHaveBeenCalledWith(1);
      });
    });
  });
});