"use strict";

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

var _Menu = _interopRequireDefault(require("@instructure/ui-menu/lib/components/Menu"));

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

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

var _QtiImport = _interopRequireDefault(require("../../../../common/records/QtiImport"));

describe('HeaderMenuBanks', function () {
  var openModalStub = sinon.stub();
  var ConnectedHeaderMenu = withContext(_presenter.default, {
    calls: {}
  });
  var qtiImport = new _QtiImport.default({
    message: 'test message'
  });
  var testbed = createTestbed(ConnectedHeaderMenu, {
    openImportModal: openModalStub
  });

  function getShallowMenuItemByKey(key) {
    // shallow render menu, since items are rendered in a portal
    var popoverMenu = testbed.subject.refs.composedComponent.renderMenu();
    var children = popoverMenu.props.children;
    return (Array.isArray(children) ? children : [children]).find(function (child) {
      return child.key === key;
    });
  }

  it('should render header menu without Import Content', function () {
    var bank = new _Bank.default();
    sinon.stub(bank, 'getLatestImport').returns(qtiImport);
    testbed.render({
      bank: bank
    });
    var menu = testbed.findChildByType(_Menu.default);
    expect(menu).to.exist();
    var importItem = getShallowMenuItemByKey('import');
    expect(importItem.props.disabled).to.be.true();
  });
  it('should include Import Content', function () {
    var bank = new _Bank.default({
      status: 'waiting'
    });
    sinon.stub(bank, 'getLatestImport').returns(qtiImport);
    testbed.render({
      bank: bank
    });
    var menu = testbed.findChildByType(_Menu.default);
    expect(menu).to.exist();
    var importItem = getShallowMenuItemByKey('import');
    expect(importItem.props.disabled).to.be.false();
  });
});