"use strict";

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

var _immutable = require("immutable");

var _featureCheck = require("../../util/featureCheck");

var calculator = _interopRequireWildcard(require("../calculator"));

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

describe('calculator selectors', function () {
  var fakeState = (0, _immutable.fromJS)({
    quizSessions: {
      activeQuizSessionId: '1',
      '1': {
        oneAtATimeType: 'question'
      }
    },
    taking: {
      currentSessionItemPosition: 3
    },
    sessionItems: {
      '1': {
        position: 1,
        quizSessionId: '1',
        calculatorType: 'none',
        id: '1'
      },
      '2': {
        position: 2,
        quizSessionId: '1',
        calculatorType: 'none',
        id: '2'
      },
      '3': {
        position: 3,
        quizSessionId: '1',
        calculatorType: 'basic',
        id: '3'
      },
      '4': {
        position: 4,
        quizSessionId: '1',
        calculatorType: 'none',
        id: '4'
      },
      // calc in wrong session, should not interfere
      '5': {
        position: 2,
        quizSessionId: '2',
        calculatorType: 'basic',
        id: '5'
      }
    }
  });
  describe('hasVisibleQuestionCalculator', function () {
    it('Sould always be false with flag off', function () {
      var result = calculator.hasVisibleQuestionCalculator((0, _immutable.fromJS)({}));
      expect(result).to.eq(false);
    });
    describe('with calculator per question', function () {
      (0, _featureCheck.withTestFeatures)(['calculator_per_question']);
      describe('One question at a time', function () {
        it('returns true when current question has calculator', function () {
          (0, _reduxStore.setFakeStore)(fakeState);
          var result = calculator.hasVisibleQuestionCalculator(fakeState);
          expect(result).to.eq(true);
        });
        it('returns false when current question calculator state is "none"', function () {
          var merged = fakeState.mergeDeep({
            taking: {
              currentSessionItemPosition: 2
            }
          });
          (0, _reduxStore.setFakeStore)(merged);
          var result = calculator.hasVisibleQuestionCalculator(merged);
          expect(result).to.eq(false);
        });
      });
      describe('More than one question at a time', function () {
        it('returns true when any question in current session has a calculator', function () {
          var merged = fakeState.mergeDeep({
            quizSessions: {
              activeQuizSessionId: '1',
              '1': {
                oneAtATimeType: null
              }
            }
          });
          (0, _reduxStore.setFakeStore)(merged);
          var result = calculator.hasVisibleQuestionCalculator(merged);
          expect(result).to.eq(true);
        });
        it('returns false when no questions in current session have a calculator', function () {
          var merged = fakeState.mergeDeep({
            quizSessions: {
              '1': {
                oneAtATimeType: null
              }
            },
            sessionItems: {
              '3': {
                calculatorType: 'none'
              }
            }
          });
          (0, _reduxStore.setFakeStore)(merged);
          expect(merged.getIn(['quizSessions', 'activeQuizSessionId'])).to.eq('1');
          var result = calculator.hasVisibleQuestionCalculator(merged);
          expect(result).to.eq(false);
        });
      });
    });
  });
});