"use strict";

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

var _chai = require("chai");

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

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

var _SessionItem = _interopRequireDefault(require("../../records/SessionItem"));

var sessionItem = new _SessionItem.default({
  position: '1',
  item: {
    id: '1'
  }
});
describe('taking actions', function () {
  describe('update quiz session status when started', function () {
    it('returns the correct action', function () {
      (0, _chai.expect)((0, _taking.updateQuizSessionStatusOnPageLoad)('in_progress')).to.eql({
        type: _constants.UPDATE_QUIZ_SESSION_STATUS_ON_PAGE_LOAD,
        payload: {
          quizSessionStatusOnPageLoad: 'in_progress'
        }
      });
    });
  });
  describe('set current session item position', function () {
    it('returns the correct action', function () {
      (0, _chai.expect)((0, _taking.setCurrentSessionItemPosition)(5)).to.eql({
        type: _constants.SET_CURRENT_SESSION_ITEM_POSITION,
        payload: {
          position: 5
        }
      });
    });
  });
  describe('update timerMinimized', function () {
    it('returns the correct actions', function () {
      (0, _chai.expect)((0, _taking.updateTimerMinimized)(true)).to.eql({
        type: _constants.UPDATE_TIMER_MINIMIZED,
        payload: {
          timerMinimized: true
        }
      });
      (0, _chai.expect)((0, _taking.updateTimerMinimized)(false)).to.eql({
        type: _constants.UPDATE_TIMER_MINIMIZED,
        payload: {
          timerMinimized: false
        }
      });
    });
  });
  describe('update isTaking', function () {
    it('returns the correct actions', function () {
      (0, _chai.expect)((0, _taking.updateIsTaking)(true)).to.eql({
        type: _constants.UPDATE_IS_TAKING,
        payload: {
          isTaking: true
        }
      });
    });
    describe('previous question', function () {
      it('returns the correct action', function () {
        (0, _chai.expect)((0, _taking.previousQuestion)()).to.eql({
          type: _constants.PREVIOUS_QUESTION,
          payload: {}
        });
      });
    });
    describe('backtracking next question', function () {
      it('returns the correct action', function () {
        (0, _chai.expect)((0, _taking.backtrackingNextQuestion)()).to.eql({
          type: _constants.BACKTRACKING_NEXT_QUESTION,
          payload: {}
        });
      });
    });
    describe('update isTaking', function () {
      it('returns the correct actions', function () {
        (0, _chai.expect)((0, _taking.updateIsTaking)(true)).to.eql({
          type: _constants.UPDATE_IS_TAKING,
          payload: {
            isTaking: true
          }
        });
        (0, _chai.expect)((0, _taking.updateIsTaking)(false)).to.eql({
          type: _constants.UPDATE_IS_TAKING,
          payload: {
            isTaking: false
          }
        });
      });
    });
    describe('updating remaining time', function () {
      it('returns the correct action without timeRecording', function () {
        var timeRemaining = {
          timeLeftInSeconds: 3,
          timerRunning: true
        };
        (0, _chai.expect)((0, _taking.updateTimerInfo)(timeRemaining)).to.eql({
          type: _constants.UPDATE_TIMER_INFO,
          payload: {
            timeLeftInSeconds: 3,
            timerRunning: true,
            timeRecording: false
          }
        });
      });
      it('returns the correct action', function () {
        var timeRemaining = {
          timeLeftInSeconds: 3,
          timerRunning: true,
          timeRecording: true
        };
        (0, _chai.expect)((0, _taking.updateTimerInfo)(timeRemaining)).to.eql({
          type: _constants.UPDATE_TIMER_INFO,
          payload: {
            timeLeftInSeconds: 3,
            timerRunning: true,
            timeRecording: true
          }
        });
      });
    });
    describe('updating submitting flag', function () {
      it('returns the correct action', function () {
        (0, _chai.expect)((0, _taking.updateQuizSubmitFlag)(true)).to.eql({
          type: _constants.UPDATE_QUIZ_SUBMIT_FLAG,
          payload: {
            value: true
          }
        });
        (0, _chai.expect)((0, _taking.updateQuizSubmitFlag)(false)).to.eql({
          type: _constants.UPDATE_QUIZ_SUBMIT_FLAG,
          payload: {
            value: false
          }
        });
        (0, _chai.expect)((0, _taking.updateQuizSubmitFlag)(null)).to.eql({
          type: _constants.UPDATE_QUIZ_SUBMIT_FLAG,
          payload: {
            value: null
          }
        });
      });
    });
    describe('editing a Response action creators', function () {
      it('returns responses keyed by position', function () {
        var editResponseAction = (0, _taking.editResponse)(sessionItem, 'hello');
        (0, _chai.expect)(editResponseAction).to.have.property('type', _constants.RESPONSE);
        (0, _chai.expect)(editResponseAction.payload).to.have.property('position', '1');
        (0, _chai.expect)(editResponseAction.payload).to.have.property('itemId', '1');
        (0, _chai.expect)(editResponseAction.payload.userResponse).to.be.deep.equal({
          value: 'hello'
        });
      });
    });
    describe('load resume data', function () {
      it('can load multiple responses', function () {
        var respOne = {
          position: 1,
          userResponse: {
            value: 'hey'
          },
          itemId: 1
        };
        var respTwo = {
          position: 2,
          userResponse: {
            value: 'hello'
          },
          itemId: 2
        };
        var loadResumeAction = (0, _taking.loadResumeData)([respOne, respTwo]);
        (0, _chai.expect)(loadResumeAction).to.have.property('type', _constants.LOAD_RESUME_DATA);
        (0, _chai.expect)(loadResumeAction.payload).to.include(respOne);
        (0, _chai.expect)(loadResumeAction.payload).to.include(respTwo);
      });
    });
  });
});