"use strict";

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

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

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

describe('BuildingButtons', function () {
  var testbed = createTestbed(_presenter.default, {
    quizSaving: false
  });

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

  it('shows saving if quizSaving is true', function () {
    testbed.render({
      quizSaving: true
    });
    var buttonsText = testbed.getText(testbed.rootNode);
    expect(buttonsText).to.include('Saving...');
  });
  context('popover menu', function () {
    it('shows when in a building app context', function () {
      testbed.render({
        app: 'building',
        hasQtiImport: true
      });
      var menu = testbed.findChildByType(_Menu.default);
      expect(menu).to.exist();
    });
    it('shows when in a settings app context', function () {
      testbed.render({
        app: 'settings',
        hasQtiImport: true
      });
      var menu = testbed.findChildByType(_Menu.default);
      expect(menu).to.exist();
    });
    it('disables when in a reporting app context', function () {
      testbed.render({
        app: 'reporting',
        hasQtiImport: true
      });
      expect(function () {
        return testbed.findChildByType(_Menu.default);
      }).to.throw();
    });
  });
  context('QTI import menu', function () {
    it('shows when in a building app context', function () {
      testbed.render({
        app: 'building',
        canImport: true,
        hasQtiImport: true
      });
      var importItem = getShallowMenuItemByKey('import');
      expect(importItem.props.disabled).to.be.false();
    });
    it('disables import menu item when canImport is false', function () {
      testbed.render({
        app: 'building',
        hasQtiImport: true
      });
      var importItem = getShallowMenuItemByKey('import');
      expect(importItem.props.disabled).to.be.true();
    });
  });
  context('Manage banks menu', function () {
    it('shows when in a building app context', function () {
      testbed.render({
        app: 'building'
      });
      var menu = testbed.findChildByType(_Menu.default);
      expect(menu).to.exist();
    });
    it('does not show when disabled via props', function () {
      testbed.render({
        app: 'building',
        enableItemBanking: false
      });
      var banksItem = getShallowMenuItemByKey('banks');
      expect(banksItem).to.be.undefined();
    });
    it('passes the specified navigation callback to the underlying menu item', function () {
      var navigateToBanks = function navigateToBanks() {};

      testbed.render({
        app: 'building',
        navigateToBanks: navigateToBanks
      });
      var menu = testbed.findChildByType(_Menu.default);
      expect(menu).to.exist();
      var banksItem = getShallowMenuItemByKey('banks');
      expect(banksItem.props.onSelect).to.eq(navigateToBanks);
    });
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render({});
      testbed.checkA11yStandards(done);
    });
  });
});