"use strict";

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

var _Tray = _interopRequireDefault(require("@instructure/ui-overlays/lib/components/Tray"));

var _Portal = _interopRequireDefault(require("@instructure/ui-portal/lib/components/Portal"));

var _constants = require("@instructure/quiz-common/lib/constants");

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

describe('Banks Tray', function () {
  var clearStub = sinon.stub();
  var focusStub = sinon.stub();
  var newActiveBankStub = sinon.stub();
  var newActiveBankEntryStub = sinon.stub();
  var setUiStub = sinon.stub();
  var testbed = createTestbed(withContext(_presenter.default), {
    activeBankId: '4',
    activeBankEntryId: '3',
    clear: clearStub,
    newActiveBank: newActiveBankStub,
    newActiveBankEntry: newActiveBankEntryStub,
    trayOpen: true,
    setUI: setUiStub,
    trayTrigger: {
      focus: focusStub
    }
  });
  afterEach(function () {
    clearStub.resetHistory();
    focusStub.resetHistory();
    newActiveBankStub.resetHistory();
    newActiveBankEntryStub.resetHistory();
    setUiStub.resetHistory();
  });
  shouldRenderComponent(testbed, {}, _presenter.default);
  it('renders tray', function () {
    testbed.render();
    var tray = testbed.findChildByType(_Tray.default);
    expect(tray.props.open).to.be.true();
  });
  it('sets focus and clears UI when closing the bank tray', function () {
    testbed.render();
    var tray = testbed.findChildByType(_presenter.default);
    tray.closeTray();
    expect(focusStub).to.be.called();
    expect(setUiStub).to.be.called();
  });
  it('renders with a BankEntry component', function () {
    testbed.render({
      activeBankId: '4',
      activeBankEntryId: '3'
    });
    var tray = testbed.findChildByType(_Tray.default);
    expect(tray.props.children.type.displayName).to.equal('Connect(BankEntry)');
  });
  it('renders with a Bank component', function () {
    testbed.render({
      activeBankId: '4',
      activeBankEntryId: null
    });
    var tray = testbed.findChildByType(_Tray.default);
    expect(tray.props.children.type.displayName).to.equal('Connect(Bank)');
  });
  it('renders with a Banks component', function () {
    testbed.render({
      activeBankId: null,
      activeBankEntryId: null
    });
    var tray = testbed.findChildByType(_Tray.default);
    expect(tray.props.children.type.displayName).to.equal('Connect(Banks)');
  });
  describe('trayAlert', function () {
    it('renders the tray alert when the prop is set', function () {
      testbed.render({
        trayAlertOpen: true
      });
      var portals = testbed.findChildrenByType(_Portal.default);
      expect(portals.every(function (portal) {
        return portal.props.open;
      })).to.be.true();
    });
    it('refreshes the bank tray when closed', function () {
      testbed.render();
      var tray = testbed.findChildByType(_presenter.default);
      tray.handleCloseAlert();
      expect(setUiStub).to.have.been.calledWith(_constants.TRAY_ALERT_OPEN, false);
      expect(clearStub).to.have.been.calledWith(_constants.BANKS_BANK_PAGINATION);
      expect(newActiveBankStub).to.have.been.calledWith(void 0);
      expect(newActiveBankEntryStub).to.have.been.calledWith(void 0);
    });
  });
  it('should meet a11y standards', function (done) {
    testbed.render();
    testbed.checkA11yStandards(done);
  });
});