"use strict";

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

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

var _enzyme = require("enzyme");

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

var _components = require("../../../../../components");

var _TutorialReferencePicker = _interopRequireDefault(require("../TutorialReferencePicker"));

describe('TutorialReview', function () {
  var node;
  var props;
  beforeEach(function () {
    props = {
      updateTutorial: jest.fn(),
      tutorial: {
        backgroundColor: '#018FF4',
        emoji: '🦉',
        response: '{"success":true}',
        referenceDisplay: ['123'],
        steps: [],
        snippet: {},
        title: 'Tutorial Title',
        description: 'Tutorial Description'
      },
      endpoints: [{
        categoryId: '1',
        title: 'Petstore',
        children: [{
          _id: '123',
          api: {
            apiSetting: '222',
            method: 'get'
          },
          title: 'Get Pets'
        }]
      }]
    };
    node = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_["default"], props));
  });
  it('should display TutorialReview', function () {
    expect(node.find('.TutorialReview')).toHaveLength(1);
  });
  it('should show with minimal data', function () {
    var p2 = {
      updateTutorial: jest.fn(),
      tutorial: {
        response: '',
        referenceDisplay: [],
        steps: [],
        snippet: {},
        title: 'Tutorial Title',
        description: 'Tutorial Description'
      },
      endpoints: []
    };
    var n2 = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_["default"], p2));
    expect(n2.find('.TutorialReview-Fieldset-Avatar_empty')).toHaveLength(2);
  });
  describe('Actions', function () {
    it('should set emoji via picker', function () {
      var pickerButton = node.find(_components.EmojiPicker).find('button').at(4);
      pickerButton.simulate('click', {
        target: {
          value: '😁'
        }
      });
      setTimeout(function () {
        expect(props.tutorial.emoji).toStrictEqual('😁');
      });
    });
    it('should clear tutorial referenceDisplay field on `Clear All`', function () {
      var button = node.find('fieldset').at(1).find(_components.Button).first();
      button.simulate('click');
      setTimeout(function () {
        expect(props.tutorial.referenceDisplay).toHaveLength(0);
      });
    });
    it('should add referenceDisplay selection if not in array', function () {
      var picker = node.find(_TutorialReferencePicker["default"]);
      picker.prop('setReferenceSelection')('12');
      expect(props.updateTutorial).toHaveBeenCalledWith({
        referenceDisplay: ['123', '12']
      });
    });
    it('should remove referenceDisplay selection if in array', function () {
      var picker = node.find(_TutorialReferencePicker["default"]);
      picker.prop('setReferenceSelection')('123');
      expect(props.updateTutorial).toHaveBeenCalledWith({
        referenceDisplay: []
      });
    });
  });
});