"use strict";

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

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

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

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

var _shallowTestbed = _interopRequireDefault(require("../../../../../tests/util/shallowTestbed"));

var _Page = _interopRequireDefault(require("../../../../common/components/layout/Page"));

var _PaginatedCollection = _interopRequireDefault(require("../../../../common/components/shared/PaginatedCollection"));

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

describe('Banks', function () {
  var ConnectedBanks = withContext(_presenter.default);
  var openModalStub = sinon.stub();
  var createBankStub = sinon.stub();
  var props = {
    getBanks: function getBanks() {},
    openModal: openModalStub,
    navigateToBank: function navigateToBank() {},
    createBank: createBankStub,
    userToken: 'token'
  };
  var testbed = createTestbed(ConnectedBanks, props);
  var shallow = (0, _shallowTestbed.default)(_presenter.default, props);
  it('renders a Page component', function () {
    testbed.render();
    expect(testbed.findChildrenByType(_Page.default)).to.have.length(1);
  });
  it('renders Banks app navigation', function () {
    testbed.render();
    expect(testbed.getText()).to.include('Item Banks');
  });
  it('renders the create bank button', function () {
    testbed.render();
    var createBankButton = testbed.findChildByType(_Button.default);
    expect(createBankButton).to.not.be.undefined();
  });
  it('opens the modal when create bank button is clicked', function () {
    var subject = shallow.render({}, {
      locale: 'es'
    });
    var createBankButton = subject.find('Button').first();
    createBankButton.props().onClick();
    expect(createBankStub).to.have.been.calledWith({
      language: 'es'
    });
    expect(openModalStub.called).to.be.true();
  });
  it('renders a return-to-build button when passed a navigateToBuild prop', function () {
    testbed.render({
      navigateToBuild: function navigateToBuild() {}
    });
    var buttons = testbed.findChildrenByType(_Button.default);
    var texts = buttons.map(function (button) {
      return _reactDom.default.findDOMNode(button).innerText;
    });
    expect(texts.join()).to.include('Return');
  });
  it('does not render a return-to-build button when not passed a navigateToBuild prop', function () {
    testbed.render({
      navigateToBuild: null
    });
    var buttons = testbed.findChildrenByType(_Button.default);
    var texts = buttons.map(function (button) {
      return _reactDom.default.findDOMNode(button).innerText;
    });
    expect(texts.join()).to.not.include('Return');
  });
  it("renders a paginated collection keyed on ".concat(_constants.BANKS_BANK_PAGINATION), function () {
    var wrapper = testbed.mount();
    var paginatedCollection = wrapper.find(_PaginatedCollection.default);
    expect(paginatedCollection).to.have.length(1);
    expect(paginatedCollection.prop('stateKey')).to.equal(_constants.BANKS_BANK_PAGINATION);
  });
  it('should meet a11y standards', function (done) {
    testbed.render();
    testbed.checkA11yStandards(done);
  });
});