"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _reactDom = _interopRequireDefault(require("react-dom"));

var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));

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

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

var _Breadcrumb = _interopRequireDefault(require("@instructure/ui-breadcrumb/lib/components/Breadcrumb"));

var _BreadcrumbLink = _interopRequireDefault(require("@instructure/ui-breadcrumb/lib/components/Breadcrumb/BreadcrumbLink"));

var _renderChecks = require("../../../../../tests/util/renderChecks");

var _index = _interopRequireDefault(require("../index"));

describe('NavWrapper', function () {
  var closeTrayStub = sinon.stub();
  var navigateToBanksStub = sinon.stub();
  var navigateToBuildStub = sinon.stub();
  var renderHeaderMenuStub = sinon.stub();
  var testbed = createTestbed(_index.default, {
    closeTray: closeTrayStub,
    navigateToBanks: navigateToBanksStub,
    navigateToBuild: navigateToBuildStub,
    renderHeaderMenu: renderHeaderMenuStub
  });
  afterEach(function () {
    navigateToBanksStub.resetHistory();
    navigateToBuildStub.resetHistory();
    renderHeaderMenuStub.resetHistory();
  });
  (0, _renderChecks.shouldRenderComponent)(testbed, {}, _index.default);
  it('renders a single BreadcrumbLink by default', function () {
    testbed.render();
    var breadcrumb = testbed.findChildByType(_Breadcrumb.default);
    expect(_react.default.Children.count(breadcrumb.props.children)).to.equal(1);
  });
  it('renders additional BreadcumbLink children when passed', function () {
    testbed.render({
      children: [_react.default.createElement(_BreadcrumbLink.default, {
        key: "0"
      })]
    });
    var breadcrumb = testbed.findChildByType(_Breadcrumb.default);
    expect(_react.default.Children.count(breadcrumb.props.children)).to.equal(2);
  });
  it('renders a close button when passed a closeTray prop', function () {
    testbed.render();
    var closeButtons = testbed.findChildrenByType(_CloseButton.default);
    expect(closeButtons.length).to.equal(1);
  });
  it('does not render a close button when no closeTray prop', function () {
    testbed.render({
      closeTray: null
    });
    var closeButtons = testbed.findChildrenByType(_CloseButton.default);
    expect(closeButtons.length).to.equal(0);
  });
  describe('return button', function () {
    it('renders a return-to-build button when passed a navigateToBuild prop', function () {
      testbed.render();
      var buttons = testbed.findChildrenByType(_Button.default);
      var lastButton = buttons[buttons.length - 1];
      expect(_reactDom.default.findDOMNode(lastButton).innerText).to.equal('Return');
    });
    it('does not render a return button when no navigateToBuild prop', function () {
      testbed.render({
        navigateToBuild: null
      });
      var buttons = testbed.findChildrenByType(_Button.default); // At the time of this writing, there were 0 buttons on the page, so there's no actual loop
      // here. In the future, if any buttons do show up, we want to make sure 'Return' is not one of
      // them

      buttons.forEach(function (btn) {
        expect(_reactDom.default.findDOMNode(btn).innerText).to.not.equal('Return');
      });
    });
    it('calls navigateToBuild prop when clicked', function () {
      testbed.render();
      var buttons = testbed.findChildrenByType(_Button.default);
      var lastButton = buttons[buttons.length - 1];

      _testUtils.default.Simulate.click(_reactDom.default.findDOMNode(lastButton));

      expect(navigateToBuildStub).to.have.been.called();
    });
  });
  it('calls renderHeaderMenu during render', function () {
    testbed.render();
    expect(renderHeaderMenuStub).to.have.been.called();
  });
  it('calls navigateToBanks when the first breadcrumb is clicked', function () {
    testbed.render();
    var breadcrumbLink = testbed.findChildByType(_BreadcrumbLink.default);
    testbed.click(breadcrumbLink);
    expect(navigateToBanksStub).to.have.been.called();
  });
  it('should meet a11y standards', function (done) {
    testbed.render();
    testbed.checkA11yStandards(done, {
      ignores: ['aria-allowed-role' // TODO: remove this when instui fixes Select
      ]
    });
  });
});