"use strict";

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

var _immutable = require("immutable");

var _chai = require("chai");

var _quizzes = _interopRequireDefault(require("../quizzes"));

var _quizzes2 = require("../../actions/quizzes");

describe('quizzes reducer', function () {
  describe('add quiz', function () {
    it('should add quizzes with ADD_QUIZZES action', function () {
      var initialState = (0, _immutable.Map)({});
      var newQuizzes = {
        1: {
          id: '1',
          title: 'econ 231 online test'
        },
        2: {
          id: '2',
          title: 'fin 283 pop quiz'
        }
      };
      var action = (0, _quizzes2.addQuizzes)(newQuizzes);
      var nextState = (0, _quizzes.default)(initialState, action);
      var nextTitle = nextState.get('2').get('title');
      (0, _chai.expect)(nextTitle).to.equal('fin 283 pop quiz');
    });
    it('should add quizzes with ADD_QUIZZES action and array payload', function () {
      var initialState = (0, _immutable.Map)({});
      var newQuizzes = [{
        id: '1',
        title: 'econ 231 online test'
      }, {
        id: '2',
        title: 'fin 283 pop quiz'
      }];
      var action = (0, _quizzes2.addQuizzes)(newQuizzes);
      var nextState = (0, _quizzes.default)(initialState, action);
      var nextTitle = nextState.get('2').get('title');
      (0, _chai.expect)(nextTitle).to.equal('fin 283 pop quiz');
    });
    it('should replace quizzes with ADD_QUIZZES action', function () {
      var initialState = (0, _immutable.fromJS)({
        2: {
          id: '2',
          title: 'some intial title'
        }
      });
      var newQuizzes = {
        1: {
          id: '1',
          title: 'econ 231 online test'
        },
        2: {
          id: '2',
          title: 'some new title'
        }
      };
      var action = (0, _quizzes2.addQuizzes)(newQuizzes);
      var nextState = (0, _quizzes.default)(initialState, action);
      var nextTitle = nextState.get('2').get('title');
      (0, _chai.expect)(nextTitle).to.equal('some new title');
    });
  });
  it('handles ACTIVE_QUIZ_CHANGE', function () {
    var initialState = (0, _immutable.Map)({
      activeQuizId: '8'
    });
    var action = (0, _quizzes2.newActiveQuiz)('12');
    var nextState = (0, _quizzes.default)(initialState, action);
    (0, _chai.expect)(nextState.get('activeQuizId')).to.equal('12');
  });
  describe('assocQuizEntries', function () {
    it('properly associates a list of quizEntries', function () {
      var initialState = (0, _immutable.fromJS)({
        2: {
          id: '2',
          quizEntries: (0, _immutable.List)()
        }
      });
      var newQuizEntries = {
        1: {
          id: '1',
          title: 'econ 231 online test'
        },
        2: {
          id: '2',
          title: 'fin 283 pop quiz'
        }
      };
      var action = (0, _quizzes2.associateQuizEntries)('2', newQuizEntries);
      var nextState = (0, _quizzes.default)(initialState, action);
      var quizEntries = nextState.get('2').get('quizEntries');
      (0, _chai.expect)(quizEntries.toJS()).to.deep.eq(['1', '2']);
    });
  });
  describe('dissocQuizEntry', function () {
    it('properly disassociated quizEntry from quizzes', function () {
      var initialState = (0, _immutable.fromJS)({
        2: {
          id: '2',
          quizEntries: ['1', '2', '3']
        }
      });
      var assocAction = (0, _quizzes2.disassociateQuizEntry)('2', '2');
      var nextState = (0, _quizzes.default)(initialState, assocAction);
      var nextItems = nextState.get('2').get('quizEntries');
      (0, _chai.expect)(nextItems.equals((0, _immutable.fromJS)(['1', '3']))).to.be.true();
    });
  });
});