"use strict";

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

var _immutable = require("immutable");

var _InteractionType = _interopRequireDefault(require("quiz-interactions/lib/records/InteractionType"));

var _SidebarItem = _interopRequireDefault(require("../../../../../../common/components/layout/sidebar/SidebarItem"));

var _DragHandle = _interopRequireDefault(require("../../../../../../common/components/shared/drag_and_drop/DragHandle"));

var _QuizEntry = _interopRequireDefault(require("../../../../../../common/records/QuizEntry"));

var _presenter = _interopRequireDefault(require("../presenter"));

var _Item = _interopRequireDefault(require("../../../../../../common/records/Item"));

describe('SidebarItem Building Presenter', function () {
  var item = new _Item.default({
    id: '22',
    itemBody: '<div>Hello</div>'
  });
  var intType = new _InteractionType.default({
    slug: 'choice',
    name: 'Multiple Choice'
  });
  item.getInteractionType = sinon.stub().returns(intType);
  var quizEntry = new _QuizEntry.default({
    position: 2
  });
  var props = {
    item: item,
    quizEntry: quizEntry,
    quizEntries: (0, _immutable.List)([quizEntry]),
    pointsPossible: 2,
    sidebarOpen: false,
    sidebarActions: {},
    itemsCollectionSize: 3
  };
  var testbed = createTestbed(wrapInDragAndDropTestContext(withContext(_presenter.default)), props);
  shouldRenderComponent(testbed, {}, _presenter.default);
  it('renders common sidebarItem', function () {
    testbed.render();
    expect(testbed.findChildrenByType(_SidebarItem.default).length).to.eq(1);
  });
  it('should include a drag handle if draggable', function () {
    testbed.render({
      sidebarOpen: true,
      connectDragSource: function connectDragSource(C) {
        return C;
      },
      connectDragPreview: function connectDragPreview(C) {
        return C;
      }
    });
    var dragHandles = testbed.findChildrenByType(_DragHandle.default);
    expect(dragHandles).to.have.length(1);
  });
  it('should not include a drag handle not draggable', function () {
    testbed.render({
      sidebarOpen: false
    });
    var dragHandles = testbed.findChildrenByType(_DragHandle.default);
    expect(dragHandles).to.have.length(0);
  }); // TODO - reenable these once a better testing strategy is discovered.

  xdescribe('building sidebar drag and drop', function () {
    var dragAndTestWithMonitor = function dragAndTestWithMonitor(testCb) {
      testbed.render();
      var rootElement = testbed.subject;
      var sidebarItem = testbed.findChildrenByType(_SidebarItem.default)[0];
      var handlerID = sidebarItem.getHandlerId();
      var manager = rootElement.getManager();
      var dndBackend = manager.getBackend();
      var monitor = manager.getMonitor();
      dndBackend.simulateBeginDrag([handlerID], {
        clientOffset: {
          x: 0,
          y: 100
        },
        getSourceClientOffset: function getSourceClientOffset() {
          return {
            x: 0,
            y: 50
          };
        }
      });
      testCb(monitor);
      dndBackend.simulateEndDrag([handlerID]);
    };

    it('should getItem that is being dragged', function () {
      dragAndTestWithMonitor(function (monitor) {
        var draggedItem = monitor.getItem();
        expect(draggedItem.id).to.be.equal('3');
      });
    });
    it('should get location of item dropped', function () {
      dragAndTestWithMonitor(function (monitor) {
        expect(monitor.getClientOffset()).to.be.deep.equal({
          x: 0,
          y: 100
        });
      });
    });
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
  });
});