"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 _uiTestUtils = require("@instructure/ui-test-utils");

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

describe('Accommodations Modal', function () {
  var props = {
    studentName: 'Test Student'
  };
  var closeStub;
  var saveStub;
  var cancelStub;
  beforeEach(function () {
    closeStub = (0, _uiTestUtils.stub)();
    saveStub = (0, _uiTestUtils.stub)();
    cancelStub = (0, _uiTestUtils.stub)();
    props.closeModal = closeStub;
    props.onSubmit = saveStub;
    props.onDismiss = cancelStub;
  });
  it('displays when open',
  /*#__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(_index.default, Object.assign({}, props, {
              open: true
            })));

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

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

          case 7:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  it('does not display when closed',
  /*#__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(_index.default, Object.assign({}, props, {
              open: false
            })));

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

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

          case 7:
          case "end":
            return _context2.stop();
        }
      }
    }, _callee2);
  })));
  describe('callbacks', function () {
    it('calls closeModal to close',
    /*#__PURE__*/
    (0, _asyncToGenerator2.default)(
    /*#__PURE__*/
    _regenerator.default.mark(function _callee3() {
      var closeButton;
      return _regenerator.default.wrap(function _callee3$(_context3) {
        while (1) {
          switch (_context3.prev = _context3.next) {
            case 0:
              _context3.next = 2;
              return (0, _uiTestUtils.mount)(_react.default.createElement(_index.default, Object.assign({}, props, {
                open: true
              })));

            case 2:
              _context3.next = 4;
              return (0, _uiTestUtils.findWithLabel)('Close');

            case 4:
              closeButton = _context3.sent;
              _context3.next = 7;
              return closeButton.click();

            case 7:
              _context3.next = 9;
              return (0, _uiTestUtils.wait)(function () {
                (0, _uiTestUtils.expect)(closeStub).to.have.been.calledOnce();
              });

            case 9:
            case "end":
              return _context3.stop();
          }
        }
      }, _callee3);
    })));
    it('calls onSubmit and closeModal when Save is clicked',
    /*#__PURE__*/
    (0, _asyncToGenerator2.default)(
    /*#__PURE__*/
    _regenerator.default.mark(function _callee4() {
      var saveButton;
      return _regenerator.default.wrap(function _callee4$(_context4) {
        while (1) {
          switch (_context4.prev = _context4.next) {
            case 0:
              _context4.next = 2;
              return (0, _uiTestUtils.mount)(_react.default.createElement(_index.default, Object.assign({}, props, {
                open: true
              })));

            case 2:
              _context4.next = 4;
              return (0, _uiTestUtils.findWithLabel)('Save');

            case 4:
              saveButton = _context4.sent;
              _context4.next = 7;
              return saveButton.click();

            case 7:
              _context4.next = 9;
              return (0, _uiTestUtils.wait)(function () {
                (0, _uiTestUtils.expect)(closeStub).to.have.been.calledOnce();
                (0, _uiTestUtils.expect)(saveStub).to.have.been.calledOnce();
              });

            case 9:
            case "end":
              return _context4.stop();
          }
        }
      }, _callee4);
    })));
    it('calls onDismiss and closeModal when Cancel is clicked',
    /*#__PURE__*/
    (0, _asyncToGenerator2.default)(
    /*#__PURE__*/
    _regenerator.default.mark(function _callee5() {
      var cancelButton;
      return _regenerator.default.wrap(function _callee5$(_context5) {
        while (1) {
          switch (_context5.prev = _context5.next) {
            case 0:
              _context5.next = 2;
              return (0, _uiTestUtils.mount)(_react.default.createElement(_index.default, Object.assign({}, props, {
                open: true
              })));

            case 2:
              _context5.next = 4;
              return (0, _uiTestUtils.findWithLabel)('Cancel');

            case 4:
              cancelButton = _context5.sent;
              _context5.next = 7;
              return cancelButton.click();

            case 7:
              _context5.next = 9;
              return (0, _uiTestUtils.wait)(function () {
                (0, _uiTestUtils.expect)(closeStub).to.have.been.calledOnce();
                (0, _uiTestUtils.expect)(cancelStub).to.have.been.calledOnce();
              });

            case 9:
            case "end":
              return _context5.stop();
          }
        }
      }, _callee5);
    })));
  });
});