"use strict";

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

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

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

var _index = _interopRequireDefault(require("../index"));

describe('MoveImmutableModal', function () {
  var closeModalStub = sinon.stub();
  var setUIStub = sinon.stub();
  var moveImmutableQuizEntryStub = sinon.stub().resolves();
  var quizEntry = new _QuizEntry.default({
    id: '42'
  });
  var defaultProps = {
    closeModal: closeModalStub,
    modalOpen: true,
    moveImmutableQuizEntry: moveImmutableQuizEntryStub,
    position: 5,
    quizEntry: quizEntry,
    quizId: '1',
    setUI: setUIStub,
    stimulusQuizEntryId: '7'
  };
  var testbed = createTestbed(withContext(_presenter.default), defaultProps);
  shouldRenderComponent(testbed, {}, _presenter.default);
  afterEach(function () {
    setUIStub.resetHistory();
    closeModalStub.resetHistory();
    moveImmutableQuizEntryStub.resetHistory();
  });

  var submit = function submit() {
    var button = window.document.querySelectorAll('button')[2];
    expect(button.innerText).to.eq('Clone and Move');
    button.click();
  };

  var close = function close() {
    var button = window.document.querySelectorAll('button')[1];
    expect(button.innerText).to.include('Cancel');
    button.click();
  };

  context('#handleSubmit', function () {
    it('calls all the right functions', function (done) {
      testbed.render();
      submit();
      setTimeout(function () {
        expect(closeModalStub).to.be.called();
        expect(moveImmutableQuizEntryStub).to.be.called();
        expect(setUIStub).to.be.called();
        done();
      });
    });
    it('calls moveImmutableQuizEntry with right args', function (done) {
      testbed.render();
      submit();
      setTimeout(function () {
        expect(moveImmutableQuizEntryStub).to.be.calledWith('1', 5, '7', quizEntry.id);
        done();
      });
    });
  });
  context('#closeAction', function () {
    it('closes the modal', function () {
      testbed.render();
      close();
      expect(closeModalStub).to.be.called();
    });
    it('does not move the item', function () {
      testbed.render();
      close();
      expect(moveImmutableQuizEntryStub).not.to.have.been.called();
    });
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done, {
        ignores: ['label', 'label-title-only']
      });
    });
  });
  describe('test with connect', function () {
    var connectedTestbed = createTestbed(withContext(_index.default), defaultProps);
    shouldRenderComponent(connectedTestbed, {}, _presenter.default);
  });
});