"use strict";

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

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

var _Bank = _interopRequireDefault(require("../../../../common/records/Bank"));

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

describe('EditBankModal', function () {
  var updateBankStub = sinon.stub();
  var closeModalStub = sinon.stub();
  var focusStub = sinon.stub();
  var modalProps = {
    modalOpen: true,
    workingBank: {
      isValid: function isValid() {
        return true;
      }
    },
    displayError: false,
    updateBank: updateBankStub,
    changeBank: function changeBank() {},
    clearModifications: function clearModifications() {},
    hideError: function hideError() {},
    showError: function showError() {},
    closeModal: closeModalStub,
    modalTrigger: {
      focus: focusStub
    }
  };
  var testbed = createTestbed(_presenter.default, modalProps);
  var shallowtestbed = testbed.renderShallowly();
  describe('EditBankModal', 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('Edit Item Bank');
    });
  });
  describe('Bank Title input', function () {
    it('renders text input for bank title', function () {
      var bankInput = shallowtestbed.find('TextInput');
      expect(bankInput.render().text()).to.include('Bank Name');
    });
  });
  describe('Cancel action', function () {
    it('renders cancel button', function () {
      var cancelButton = shallowtestbed.find('Button[variant="default"]');
      expect(cancelButton.render().text()).to.include('Cancel');
    });
    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('Update Bank action', function () {
    it('renders the Save Changes button', function () {
      var modalfooter = shallowtestbed.find('ModalFooter');
      var createButton = modalfooter.shallow().find('Button[variant="primary"]');
      expect(createButton.render().text()).to.include('Save Changes');
    });
    it('does not create the bank when the name is blank', function () {
      var errortestbed = testbed.renderShallowly({
        workingBank: new _Bank.default({
          id: 'temp_id'
        }),
        errorKey: 'temp_id_create_bank',
        displayError: true
      });
      var createButton = errortestbed.find('Button[variant="primary"]');
      createButton.simulate('click');
      var bankInput = errortestbed.find('TextInput');
      expect(bankInput.render().text()).to.include('cannot be blank');
      expect(updateBankStub.called).to.be.false();
    });
    it('updates the bank when the name is entered', function () {
      var createButton = shallowtestbed.find('Button[variant="primary"]');
      var bankInput = shallowtestbed.find('TextInput');
      bankInput.simulate('change', {
        target: {
          value: 'After Change'
        }
      });
      createButton.simulate('click');
      expect(updateBankStub.called).to.be.true();
    });
  });
});