"use strict";

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

var _immutable = require("immutable");

var _Button = _interopRequireDefault(require("@instructure/ui-buttons/lib/components/Button"));

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

var _shallowTestbed = _interopRequireDefault(require("../../../../../tests/util/shallowTestbed"));

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

describe('Confirmation Modal', function () {
  var defaultProps = {
    closeModal: function closeModal() {},
    modalOpen: true,
    modalOptions: (0, _immutable.Map)({})
  };
  var testbed = (0, _shallowTestbed.default)(_presenter.default, defaultProps);
  describe('modal header', function () {
    it('renders the given title', function () {
      var customTitle = 'Remove Item?';
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          title: customTitle
        })
      });
      expect(testbed.getText('ModalHeader')).to.include(customTitle);
    });
    it('renders a default title if none given', function () {
      var standardTitle = 'Confirm';
      testbed.render();
      expect(testbed.getText('ModalHeader')).to.include(standardTitle);
    });
    it('renders a close button', function () {
      testbed.render();
      var closeButton = testbed.find('CloseButton');
      expect(closeButton).to.have.length(1);
      expect(closeButton.prop('children')).to.equal('Close');
    });
  });
  describe('modal footer', function () {
    it('renders the cancelText if given', function () {
      var customText = 'Dont do it';
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          cancelText: customText
        })
      });
      expect(testbed.getText('ModalFooter')).to.include('Dont do it');
    });
    it('renders the continueText if given', function () {
      var customText = 'Do It';
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          continueText: customText
        })
      });
      expect(testbed.getText('ModalFooter')).to.include('Do It');
    });
  });
  describe('main content', function () {
    it('renders at the size given', function () {
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          size: 'medium'
        })
      });
      var modal = testbed.find(_Modal.default);
      expect(modal.prop('size')).to.equal('medium');
    });
    it('renders with small size by default', function () {
      testbed.render();
      var modal = testbed.find(_Modal.default);
      expect(modal.prop('size')).to.equal('small');
    });
    it('renders the text given', function () {
      var customText = 'Are you sure you wan\'t to do this?';
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          text: customText
        })
      });
      expect(testbed.getText('ModalBody')).to.equal(customText);
    });
  });
  describe('actions', function () {
    var closeModalStub = sinon.stub();
    afterEach(function () {
      closeModalStub.resetHistory();
    });

    var buttonWithText = function buttonWithText(text) {
      return function (n) {
        return n.type() === _Button.default && n.render().text() === text;
      };
    };

    it('calls cancelCb when you hit the cancel', function () {
      var cancelCbStub = sinon.stub();
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          onCancel: cancelCbStub
        })
      });
      var cancelButton = testbed.findWhere(buttonWithText('Cancel'));
      testbed.click(cancelButton);
      expect(cancelCbStub).to.have.been.called();
    });
    it('calls continueCb when you hit continue', function () {
      var continueCbStub = sinon.stub();
      testbed.render({
        modalOptions: (0, _immutable.Map)({
          onContinue: continueCbStub
        })
      });
      var confirmButton = testbed.findWhere(buttonWithText('Confirm'));
      testbed.click(confirmButton);
      expect(continueCbStub).to.have.been.called();
    });
    it('calls closeModal when you hit the cancel', function () {
      testbed.render({
        closeModal: closeModalStub
      });
      var cancelButton = testbed.findWhere(buttonWithText('Cancel'));
      testbed.click(cancelButton);
      expect(closeModalStub).to.have.been.called();
    });
    it('calls closeModal when you hit continue', function () {
      testbed.render({
        closeModal: closeModalStub
      });
      var continueButton = testbed.findWhere(buttonWithText('Confirm'));
      testbed.click(continueButton);
      expect(closeModalStub).to.have.been.called();
    });
  });
  describe('a11y tests', function () {
    var testbedWithContext = createTestbed(withContext(_presenter.default), defaultProps);
    it('should meet a11y standards', function (done) {
      testbedWithContext.render();
      testbedWithContext.checkA11yStandards(done);
    });
  });
});