"use strict";

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

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

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

var _Modal = _interopRequireDefault(require("../../../../common/components/Modal"));

describe('AddBankEntryModal', function () {
  var closeModalStub = sinon.stub();
  var focusStub = sinon.stub();
  var createBankItemStub = sinon.stub();
  var getInteractionTypesStub = sinon.stub();
  var navigateToBankEntryStub = sinon.stub();
  var modalProps = {
    modalOpen: true,
    closeModal: closeModalStub,
    createBankItem: createBankItemStub,
    navigateToBankEntry: navigateToBankEntryStub,
    getInteractionTypes: getInteractionTypesStub,
    modalTrigger: {
      focus: focusStub
    }
  };
  var testbed = createTestbed(_presenter.default, modalProps);
  var shallowtestbed = testbed.renderShallowly();
  var connectedTestbed = createTestbed(withContext(_presenter.default), modalProps);
  afterEach(function () {
    closeModalStub.resetHistory();
    focusStub.resetHistory();
  });
  describe('Create AddBankEntryModal', function () {
    it('renders the modal', function () {
      var modal = shallowtestbed.find(_Modal.default);
      expect(modal).to.have.length(1);
    });
  });
  describe('Modal Title', function () {
    it('renders the correct title for the modal', function () {
      var modalheader = shallowtestbed.find('ModalHeader');
      expect(modalheader).to.have.length(1);
      expect(modalheader.render().text()).to.be.equal('New Item');
    });
  });
  describe('Cancel action', function () {
    it('renders cancel button', function () {
      var cancelButton = shallowtestbed.find('Button[variant="default"]');
      expect(cancelButton.render().text()).to.include('Close');
    });
    it('calls the cancel action', function () {
      var cancelButton = shallowtestbed.find('Button[variant="default"]');
      cancelButton.simulate('click');
      expect(closeModalStub).to.be.called();
      expect(focusStub).to.be.called();
    });
  });
  describe('Callback actions', function () {
    it('calls add item', function () {
      connectedTestbed.render();
      var addBankEntryModal = connectedTestbed.findChildrenByType(_presenter.default)[0];
      var type = new _InteractionType.default({
        name: 'Multiple Choice',
        slug: 'choice'
      });
      addBankEntryModal.addItem(type);
      expect(createBankItemStub.called).to.be.true();
      expect(closeModalStub.called).to.be.true();
    });
    it('calls add stimulus', function () {
      connectedTestbed.render();
      var addBankEntryModal = connectedTestbed.findChildrenByType(_presenter.default)[0];
      addBankEntryModal.addStimulus();
      expect(closeModalStub.called).to.be.true();
    });
  });
});