"use strict";

var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");

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

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

require("regenerator-runtime/runtime");

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

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

var _LearnosityCalculator = _interopRequireDefault(require("quiz-interactions/lib/components/common/components/LearnosityCalculator"));

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

var _withContext = _interopRequireDefault(require("../../../../../../../tests/util/withContext"));

var _taking = require("../../../../../../taking/api/taking");

var _reduxStore = require("../../../../../../reduxStore");

var _immutable = require("immutable");

var _ui = require("../../../../../../common/actions/ui");

describe('Calculator', function () {
  var calculatorType = 'basic';
  var activeQuizId = '42';
  var quizSessionId = 24;
  var activeCalculatorId = 'abc';
  var state = {
    quizzes: (0, _defineProperty2.default)({
      activeQuizId: activeQuizId
    }, activeQuizId, {
      id: activeQuizId,
      calculatorType: calculatorType
    }),
    quizSessions: {
      activeQuizSessionId: quizSessionId
    },
    ui: {
      activeCalculatorId: activeCalculatorId
    }
  };
  var testbed = createTestbed((0, _withContext.default)(_index.default, state));
  beforeEach(function () {
    (0, _reduxStore.setFakeStore)((0, _immutable.fromJS)(state));
  });
  afterEach(function () {
    (0, _reduxStore.unsetFakeStore)();
  });
  it('correctly maps props from state',
  /*#__PURE__*/
  (0, _asyncToGenerator2.default)(
  /*#__PURE__*/
  _regenerator.default.mark(function _callee() {
    var learnosityCalculator;
    return _regenerator.default.wrap(function _callee$(_context) {
      while (1) {
        switch (_context.prev = _context.next) {
          case 0:
            testbed.render();
            learnosityCalculator = testbed.findChildByType(_LearnosityCalculator.default);
            expect(learnosityCalculator.props).to.contain({
              activeCalculatorId: activeCalculatorId,
              calculatorType: calculatorType,
              quizSessionId: quizSessionId
            });

          case 3:
          case "end":
            return _context.stop();
        }
      }
    }, _callee);
  })));
  describe('mapDispatchToState', function () {
    it('correctly passes authenticateLearnosity',
    /*#__PURE__*/
    (0, _asyncToGenerator2.default)(
    /*#__PURE__*/
    _regenerator.default.mark(function _callee2() {
      var props;
      return _regenerator.default.wrap(function _callee2$(_context2) {
        while (1) {
          switch (_context2.prev = _context2.next) {
            case 0:
              props = (0, _index.mapDispatchToProps)(sinon.stub());
              expect(props.authenticateLearnosity).to.eq(_taking.authenticateLearnosity);

            case 2:
            case "end":
              return _context2.stop();
          }
        }
      }, _callee2);
    })));
    it('correctly maps setUI to setActiveCalculatorId', function () {
      var dispatch = sinon.stub();
      var props = (0, _index.mapDispatchToProps)(dispatch);
      props.setActiveCalculatorId('abc');
      expect(dispatch).to.have.been.called.with((0, _ui.setActiveCalculatorId)('abc'));
    });
  });
});