"use strict";

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

var _immutable = require("immutable");

var _chai = require("chai");

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

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

describe('Item Record', function () {
  describe('#hasModifications', function () {
    it('returns false if it has no modifications', function () {
      var item = new _Item.default();
      var unmodifiedItem = item.merge({});
      sinon.stub(item, 'getWorkingInstance').returns(unmodifiedItem);
      (0, _chai.expect)(item.hasModifications()).to.be.false();
    });
    it('returns true if modifications exist', function () {
      var item = new _Item.default();
      var unmodifiedItem = item.merge({
        title: 'Some new title'
      });
      sinon.stub(item, 'getWorkingInstance').returns(unmodifiedItem);
      (0, _chai.expect)(item.hasModifications()).to.be.true();
    });
  });
  describe('#getWorkingInstance', function () {
    var fakeState = (0, _immutable.fromJS)({
      modifications: {
        items: {
          4: {
            title: 'some updated title'
          }
        }
      }
    });
    before(function () {
      return (0, _reduxStore.setFakeStore)(fakeState);
    });
    after(function () {
      return (0, _reduxStore.unsetFakeStore)();
    });
    it('merges modifications from state', function () {
      var item = new _Item.default({
        id: '4',
        title: 'some title'
      });
      (0, _chai.expect)(item.getWorkingInstance().title).to.equal('some updated title');
    });
    it('merges passed overrides', function () {
      var item = new _Item.default({
        scoringData: {
          value: 'origValue'
        }
      });
      var overrides = {
        scoringData: {
          value: 'overrideValue'
        }
      };
      (0, _chai.expect)(item.getWorkingInstance(overrides).scoringData.get('value')).to.equal('overrideValue');
    });
  });
  describe('#hasFeedback', function () {
    it('returns false if it has no feedback', function () {
      var item = new _Item.default();
      (0, _chai.expect)(item.hasFeedback()).to.not.be.ok();
    });
    it('returns true if feedback exists', function () {
      var item = new _Item.default().merge({
        feedback: {
          neutral: 'neutral feedback'
        }
      });
      (0, _chai.expect)(item.hasFeedback()).to.be.ok();
    });
  });
  describe('#getChoice', function () {
    it('returns the proper choice', function () {
      var choiceToFindId = '23';
      var choiceToFind = (0, _immutable.fromJS)({
        id: choiceToFindId
      });
      var item = new _Item.default((0, _immutable.fromJS)({
        interactionData: {
          choices: [{
            id: '239'
          }, choiceToFind, {
            id: '34'
          }]
        }
      }));
      (0, _chai.expect)(item.getChoice(choiceToFindId)).to.be.equal(choiceToFind);
    });
  });
});