"use strict";

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

var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));

var _immutable = require("immutable");

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

var _Stimulus = _interopRequireDefault(require("../../../../../records/Stimulus"));

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

var _Collection = _interopRequireDefault(require("../Collection"));

var _Title = _interopRequireDefault(require("../Title"));

var _Summary = _interopRequireDefault(require("../Summary"));

describe('Common Stimulus Sidebar Presenter', function () {
  var stimulus = new _Stimulus.default({
    title: '<div>Hello</div>'
  });
  stimulus.items = (0, _immutable.fromJS)([{}, {}, {}]);
  var renderSidebarItemStub = sinon.stub();
  var scrollToItemStub = sinon.stub();
  var stimulusParent = new _QuizEntry.default({
    id: '5'
  });
  sinon.stub(stimulusParent, 'getEntry').returns(stimulus);
  var props = {
    childEntries: (0, _immutable.fromJS)([]),
    displayPosition: 1,
    isDragging: false,
    isShowingItems: false,
    itemId: '1',
    sidebarOpen: true,
    renderSidebarItem: renderSidebarItemStub,
    scrollToItem: scrollToItemStub,
    stimulus: stimulus,
    stimulusParent: stimulusParent
  };
  afterEach(function () {
    renderSidebarItemStub.resetHistory();
  });
  var testbed = createTestbed(withContext(_presenter.default), props);
  shouldRenderComponent(testbed, {}, _presenter.default);
  describe('#scrollToItem', function () {
    it('should call scrollToItem with the quizEntry id', function () {
      testbed.render();
      var sidebarItem = testbed.findChildren(function (el) {
        return el.type === 'button' && testbed.getText(el).includes('Scroll to stimulus');
      })[0];
      testbed.click(sidebarItem);
      expect(scrollToItemStub).to.be.calledWith('5');
    });
    it('should call scrollToItem with the quizEntry id on space or enter', function () {
      testbed.render();
      var sidebarItem = testbed.findChildren(function (el) {
        return el.type === 'button' && testbed.getText(el).includes('Scroll to stimulus');
      })[0];

      _testUtils.default.Simulate.keyDown(sidebarItem, {
        keyCode: 13
      });

      expect(scrollToItemStub).to.be.calledWith('5');
    });
  });
  describe('#renderTitle', function () {
    it('renders a title', function () {
      testbed.render();
      expect(testbed.findChildrenByType(_Title.default)).to.not.be.empty();
    });
  });
  describe('#renderCollection', function () {
    context('isDragging', function () {
      it('does not render the collection', function () {
        testbed.render({
          isDragging: true
        });
        expect(testbed.findChildrenByType(_Collection.default)).to.be.empty();
      });
    });
    it('renders the collection', function () {
      testbed.render({
        isDragging: false
      });
      expect(testbed.findChildrenByType(_Collection.default)).to.not.be.empty();
    });
  });
  describe('#renderSummary', function () {
    it('renders the summary', function () {
      testbed.render();
      expect(testbed.findChildrenByType(_Summary.default)).to.not.be.empty();
    });
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
  });
});