"use strict";

var _react = _interopRequireDefault(require("react"));
var _enzyme = require("enzyme");
var _enzymeAdapterReact = _interopRequireDefault(require("@wojtekmaj/enzyme-adapter-react-17"));
var _Licit = _interopRequireWildcard(require("./Licit"));
var _RichTextEditor = _interopRequireDefault(require("../ui/RichTextEditor"));
var _licitUiCommands = require("@modusoperandi/licit-ui-commands");
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
/**
 * Configure Jest to use react / enzyme
 */
(0, _enzyme.configure)({
  adapter: new _enzymeAdapterReact.default()
});
describe('<Licit />', () => {
  let wrapper;
  let licit;

  // provide an empty document just to shut up that warning
  const data = {
    type: 'doc',
    content: [{
      type: 'paragraph',
      content: [{
        type: 'text',
        text: ' '
      }]
    }]
  };

  // Mocking the functions used in _onReady
  const fakeEditorView = {
    focus: _licitUiCommands.noop,
    dispatch: _licitUiCommands.noop,
    state: {
      doc: {
        content: {
          size: 10
        },
        resolve: () => ({
          min: () => 0,
          max: () => 10,
          parent: {
            inlineContent: true
          }
        }),
        toJSON: () => data
      },
      tr: {
        setSelection: () => fakeEditorView.state.tr,
        scrollIntoView: _licitUiCommands.noop
      }
    }
  };
  beforeEach(() => {
    wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_Licit.default, {
      data: data
    }));
    licit = wrapper.instance();
  });
  it('should render a <RichTextEditor /> ', () => {
    expect(wrapper.find(_RichTextEditor.default)).toBeTruthy();
  });
  describe('editorView (getter)', () => {
    it('should return the prosemirror view', () => {
      // Using shallow, the underlying RichTexEditor is never really created,
      // and Licit's _onReady method is not called.  Call it here with the fake
      // view created above
      licit._onReady(fakeEditorView);

      // Verify that getter now returns the underlying view.
      expect(licit.editorView).toBe(fakeEditorView);
    });
  });
});
describe('<Licit with HTML input/>', () => {
  let wrapper;
  let licit;
  const HELLO = 'Hello ';
  const WORLD = 'World';
  const data = '<p stylename="None">' + HELLO + '<strong overridden="false">' + WORLD + '</strong></p>';
  beforeEach(() => {
    wrapper = (0, _enzyme.shallow)( /*#__PURE__*/_react.default.createElement(_Licit.default, {
      data: data,
      dataType: _Licit.DataType.HTML
    }));
    licit = wrapper.instance();
  });
  it('should render a <RichTextEditor /> ', () => {
    expect(wrapper.find(_RichTextEditor.default)).toBeTruthy();
  });
  it('should match state text content with the passed in text ', () => {
    expect(licit.state.editorState.doc.textContent).toBe(HELLO + WORLD);
  });
});