"use strict";

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

var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));

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

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

var _Avatar = _interopRequireDefault(require("@instructure/ui-elements/lib/components/Avatar"));

var _uiTestUtils = require("@instructure/ui-test-utils");

var _Spinner = _interopRequireDefault(require("../../../../../common/components/shared/spinner/Spinner"));

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

var _ModerateTableRow = _interopRequireDefault(require("../../ModerateTableRow"));

describe('ModerateTable presenter', function () {
  var props = {
    isFetching: false,
    openTray: false,
    tableData: [{
      avatar: 'zomgModerateTablePresenter',
      id: '42',
      name: 'lolwut',
      quizSessionIds: ['1']
    }, {
      avatar: 'lulzModerateTablePresenter',
      id: '77',
      name: 'wutlol',
      quizSessionIds: ['2']
    }],
    onModerateButtonClick: function onModerateButtonClick() {},
    onModerateLogClick: function onModerateLogClick() {}
  };
  var ContextTable = withContext(_presenter.default, {});
  var testbed = createTestbed(ContextTable, props);
  shouldRenderComponent(testbed, {}, _presenter.default);
  stubComponent(_Avatar.default);
  it('renders accommodations column when callback is provided',
  /*#__PURE__*/
  (0, _asyncToGenerator2.default)(
  /*#__PURE__*/
  _regenerator.default.mark(function _callee() {
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            _context.next = 2;
            return (0, _uiTestUtils.mount)(_react.default.createElement(ContextTable, Object.assign({}, props, {
              onAccommodationsClick: Function.prototype
            })));

          case 2:
            _context.t0 = _uiTestUtils.expect;
            _context.next = 5;
            return (0, _uiTestUtils.findWithText)('Accommodations');

          case 5:
            _context.t1 = _context.sent;
            (0, _context.t0)(_context.t1).to.exist();

          case 7:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  it('does not render accommodations column when collback is not provided',
  /*#__PURE__*/
  (0, _asyncToGenerator2.default)(
  /*#__PURE__*/
  _regenerator.default.mark(function _callee2() {
    return _regenerator.default.wrap(function _callee2$(_context2) {
      while (1) {
        switch (_context2.prev = _context2.next) {
          case 0:
            _context2.next = 2;
            return (0, _uiTestUtils.mount)(_react.default.createElement(ContextTable, props));

          case 2:
            _context2.t0 = _uiTestUtils.expect;
            _context2.next = 5;
            return (0, _uiTestUtils.findWithText)('Accommodations', {
              expectEmpty: true
            });

          case 5:
            _context2.t1 = _context2.sent;
            (0, _context2.t0)(_context2.t1).not.to.exist();

          case 7:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  it('renders a spinner while fetching', function () {
    testbed.render({
      isFetching: true
    });
    var result = testbed.findChildByType(_Spinner.default);
    (0, _uiTestUtils.expect)(result).to.be.ok();
  });
  it('includes a helpful caption', function () {
    testbed.render();
    var output = testbed.getText();
    (0, _uiTestUtils.expect)(output).to.include('Moderation Table');
  });
  it('includes a helpful message without table data', function () {
    testbed.render({
      tableData: []
    });
    var output = testbed.getText();
    (0, _uiTestUtils.expect)(output).to.include('There is no moderation information');
  });
  it('allows for providing a custom emptyMessage via props', function () {
    testbed.render({
      tableData: [],
      emptyMessage: 'quizzin aint easy'
    });
    var output = testbed.getText();
    (0, _uiTestUtils.expect)(output).to.include('quizzin aint easy');
  });
  it('renders ModerateTableRow children as expected', function () {
    testbed.render();
    var result = testbed.findChildrenByType(_ModerateTableRow.default);
    (0, _uiTestUtils.expect)(result).to.have.length(2);
  });
  it('passes onModerateLogClick to table row children', function () {
    testbed.render();
    var onModerateLogClick = testbed.findChildrenByType(_ModerateTableRow.default)[0].props.onModerateLogClick;
    (0, _uiTestUtils.expect)(onModerateLogClick).to.eq(props.onModerateLogClick);
  });
});