"use strict";

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

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

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

var _immutable = require("immutable");

var _Item = _interopRequireDefault(require("../../../../../records/Item"));

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

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

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

describe('ItemEdit', function () {
  var ConnectedItemEdit = withContext(_index.default);
  var item = new _Item.default({
    id: '666',
    title: 'Tough Color Question',
    itemBody: 'Which color is happiest?',
    scoringData: {
      value: 'id'
    }
  });
  sinon.stub(item, 'getWorkingInstance').returns(item);
  var defaultProps = {
    entry: item,
    errorsShowing: (0, _immutable.Map)(),
    isValid: true,
    isEditing: true,
    editable: true,
    errors: {},
    stemErrors: {},
    handleOutcomeAlignmentSetChange: sinon.stub()
  };
  var testbed = createTestbed(ConnectedItemEdit, defaultProps);
  useFakeFetching({
    dispatchStub: sinon.stub(),
    getStateStub: sinon.stub(),
    fetchStub: sinon.stub()
  });
  shouldRenderComponent(testbed, {}, _index.default);
  describe('mapStateToProps', function () {
    var state = (0, _immutable.fromJS)({
      outcomes: {
        contextUuid: 'from state'
      },
      quizzes: {
        activeQuizId: '5',
        5: {
          id: '5',
          oneAtATimeType: 'question'
        }
      }
    });
    beforeEach(function () {
      (0, _reduxStore.setFakeStore)(state);
    });
    afterEach(function () {
      (0, _reduxStore.unsetFakeStore)();
    });
    (0, _featureCheck.withTestFeatures)(['calculator_per_question']);
    it('uses showCalculator value from state', function () {
      var newProps = (0, _index.mapStateToProps)(state, defaultProps);
      expect(newProps.showCalculator).to.be.true();
    });
    it('uses oneQuestionAtATime value from state', function () {
      var newProps = (0, _index.mapStateToProps)(state, defaultProps);
      expect(newProps.oneQuestionAtATime).to.be.true();
    });
    it('uses contextUuid value from state', function () {
      var newProps = (0, _index.mapStateToProps)(state, defaultProps);
      expect(newProps.contextUuid).to.equal('from state');
    });
    it('allows overriding contextUuid via props', function () {
      var props = (0, _objectSpread2.default)({}, defaultProps, {
        contextUuid: 'from props'
      });
      var newProps = (0, _index.mapStateToProps)(state, props);
      expect(newProps.contextUuid).to.equal('from props');
    });
    it('allows overriding contextUuid with null', function () {
      var props = (0, _objectSpread2.default)({}, defaultProps, {
        contextUuid: null
      });
      var newProps = (0, _index.mapStateToProps)(state, props);
      expect(newProps.contextUuid).to.equal(null);
    });
  });
});