"use strict";

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

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

var _enzyme = require("enzyme");

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

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

var getClientRectSpy = jest.fn(function () {
  return {
    width: 100
  };
});
Range.prototype.getBoundingClientRect = getClientRectSpy;
Range.prototype.getClientRects = getClientRectSpy;
describe('TutorialResponse', function () {
  var node;
  var props;
  beforeEach(function () {
    props = {
      snippet: {
        response: 'console.log("Response here")'
      },
      updateTutorial: jest.fn()
    };
    node = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_2.PermissionContext.Provider, {
      value: false
    }, /*#__PURE__*/_react["default"].createElement(_["default"], props)));
  });
  it('should display tutorial response editor', function () {
    expect(node.find('.CodeEditor').first().exists()).toStrictEqual(true);
  });
  it('should show runmode view in readonly state', function () {
    var readOnlyNode = (0, _enzyme.mount)( /*#__PURE__*/_react["default"].createElement(_2.PermissionContext.Provider, {
      value: true
    }, /*#__PURE__*/_react["default"].createElement(_["default"], props)));
    var opts = readOnlyNode.find('.CodeEditor').first().props();
    expect(!!opts.children).toStrictEqual(true);
  });
  it('should call updateTutorial when the response is changed', function () {
    var cm = node.find('.CodeEditor').first();
    var cmProps = cm.props();
    cmProps.onChange(cm, {
      origin: '+input'
    }, '{success: true}');
    expect(props.updateTutorial).toHaveBeenCalled();
  });
  it('should NOT call updateTutorial when origin prop is invalid', function () {
    var cm = node.find('.CodeEditor').first();
    var cmProps = cm.props();
    cmProps.onChange(cm, {
      origin: ''
    }, '{success: true}');
    expect(props.updateTutorial).toHaveBeenCalledTimes(0);
  });
});