"use strict";

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

var _immutable = require("immutable");

var _presenter = _interopRequireDefault(require("../presenter"));

var _PositionBox = _interopRequireDefault(require("../../../positionBox/PositionBox"));

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

var _SessionItemResult = _interopRequireDefault(require("../../../../../records/SessionItemResult"));

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

var styles = {
  componentId: 'eIOvL',
  template: function template(theme) {
    return "\n\n.SessionItemResult__styles__sessionItemResult {\n  padding: ".concat(theme.sessionItemResultPadding || 'inherit', ";\n}\n\n.SessionItemResult__styles__topBorder {\n  border-top: solid ").concat(theme.topBorderWidth || 'inherit', " ").concat(theme.topBorderColor || 'inherit', ";\n}\n\n.SessionItemResult__styles__result {\n  margin: ").concat(theme.resultMargin || 'inherit', ";\n}\n\n.SessionItemResult__styles__points {\n  color: ").concat(theme.pointsColor || 'inherit', ";\n  font-size: ").concat(theme.pointFontSize || 'inherit', ";\n}\n\n.SessionItemResult__styles__question {\n  font-size: ").concat(theme.questionFontSize || 'inherit', ";\n}\n\n.SessionItemResult__styles__sessionItemResultHeader {\n  display: flex;\n  align-items: center;\n}\n\n.SessionItemResult__styles__itemFeedbackWrapper {\n  margin-top: ").concat(theme.itemFeedbackWrapperMargin || 'inherit', ";\n  padding: ").concat(theme.itemFeedbackWrapperPadding || 'inherit', ";\n  background-color: ").concat(theme.itemFeedbackWrapperBackgroundColor || 'inherit', ";\n  border-radius: ").concat(theme.itemFeedbackWrapperBorderRadius || 'inherit', ";\n  font-size: ").concat(theme.itemFeedbackWrapperFontSize || 'inherit', ";\n  white-space: pre-wrap;\n}\n\n.SessionItemResult__styles__itemFeedbackLabel {\n  color: ").concat(theme.itemFeedbackLabelColor || 'inherit', ";\n  font-size: ").concat(theme.itemFeedbackLabelFontSize || 'inherit', ";\n  margin-bottom: ").concat(theme.itemFeedbackMargin || 'inherit', ";\n}\n\n.SessionItemResult__styles__itemFeedbackText {\n  margin-top: ").concat(theme.itemFeedbackTextMargin || 'inherit', ";\n}\n");
  },
  'sessionItemResult': 'SessionItemResult__styles__sessionItemResult',
  'topBorder': 'SessionItemResult__styles__topBorder',
  'result': 'SessionItemResult__styles__result',
  'points': 'SessionItemResult__styles__points',
  'question': 'SessionItemResult__styles__question',
  'sessionItemResultHeader': 'SessionItemResult__styles__sessionItemResultHeader',
  'itemFeedbackWrapper': 'SessionItemResult__styles__itemFeedbackWrapper',
  'itemFeedbackLabel': 'SessionItemResult__styles__itemFeedbackLabel',
  'itemFeedbackText': 'SessionItemResult__styles__itemFeedbackText'
};
describe('SessionItemResult', function () {
  var stubbedItem = new _Item.default({
    itemBody: '<div>foo</div>'
  });

  stubbedItem.getInteractionType = function () {
    return {
      slug: 'foo'
    };
  };

  var props = {
    sessionItem: new _SessionItem.default({
      item: stubbedItem,
      position: 1
    }),
    sessionItemResult: new _SessionItemResult.default()
  };
  var testbed = createTestbed(_presenter.default, props);
  shouldRenderComponent(testbed, {}, _presenter.default);
  describe('#result', function () {
    context('with SessionItemResult', function () {
      it('returns a sessionItemResult with given properties', function () {
        testbed.render({
          sessionItemResult: new _SessionItemResult.default({
            score: 1
          })
        });
        expect(testbed.subject.points).to.eq(1);
      });
    });
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
    it('reads regrade alert when question number gets screenreader focus', function () {
      testbed.render({
        sessionItemResult: new _SessionItemResult.default({
          regradeInfo: (0, _immutable.fromJS)({
            regraded: true
          })
        })
      });
      var positionBox = testbed.findChildByType(_PositionBox.default);
      expect(positionBox.props.headingText).to.include('question has been regraded');
    });
  });
  describe('points display', function () {
    it('should display score and points possible when both are present', function () {
      testbed.render({
        sessionItemResult: new _SessionItemResult.default({
          score: 10
        }),
        sessionItem: new _SessionItem.default({
          pointsPossible: 20
        })
      });
      var pointsDisplay = testbed.findChildrenByClass(styles.points)[0];
      expect(testbed.getText(pointsDisplay)).to.include('10 / 20 points');
    });
    it('should only display score when score is present and points possible is not present', function () {
      testbed.render({
        sessionItemResult: new _SessionItemResult.default({
          score: 10
        }),
        sessionItem: new _SessionItem.default()
      });
      var pointsDisplay = testbed.findChildrenByClass(styles.points)[0];
      expect(testbed.getText(pointsDisplay)).to.include('10 points earned');
    });
    it('should only display points possible when points possible is present and score is not present', function () {
      testbed.render({
        sessionItemResult: new _SessionItemResult.default(),
        sessionItem: new _SessionItem.default({
          pointsPossible: 20
        })
      });
      var pointsDisplay = testbed.findChildrenByClass(styles.points)[0];
      expect(testbed.getText(pointsDisplay)).to.include('20 points possible');
    });
    it('should not display anything when score and points possible are both missing', function () {
      testbed.render({
        sessionItemResult: new _SessionItemResult.default(),
        sessionItem: new _SessionItem.default()
      });
      var pointsDisplay = testbed.findChildrenByClass(styles.points)[0];
      expect(testbed.getText(pointsDisplay)).to.not.include('points');
    });
  });
  describe('feedback tests', function () {
    var feedbackTestbed = createTestbed(withContext(_presenter.default), props);
    it('should render feedback if it exists', function () {
      var sessionItemResult = new _SessionItemResult.default({
        itemId: 1,
        feedback: {
          itemFeedback: {
            correct: 'correct',
            neutral: 'general'
          }
        }
      });
      feedbackTestbed.render({
        sessionItemResult: sessionItemResult
      });
      expect(feedbackTestbed.getText()).to.have.string('General Feedback');
      expect(feedbackTestbed.getText()).to.have.string('Correct Feedback');
      expect(feedbackTestbed.getText()).to.not.have.string('Incorrect Feedback');
    });
    it('should not render feedback section if no feedback', function () {
      feedbackTestbed.render();
      expect(feedbackTestbed.getText()).to.not.have.string('Correct Feedback');
      expect(feedbackTestbed.getText()).to.not.have.string('Incorrect Feedback');
      expect(feedbackTestbed.getText()).to.not.have.string('General Feedback');
    });
    it('should render grader feedback if it exists', function () {
      var sessionItemResult = new _SessionItemResult.default({
        itemId: 1,
        feedback: {
          graderFeedback: {
            content: 'content'
          }
        }
      });
      feedbackTestbed.render({
        sessionItemResult: sessionItemResult
      });
      expect(feedbackTestbed.getText()).to.have.string('Grader Feedback');
    });
    it('should not render grader feedback if no feedback', function () {
      feedbackTestbed.render();
      expect(feedbackTestbed.getText()).to.not.have.string('Grader Feedback');
    });
    it('should not render grader feedback with hideGraderFeedback', function () {
      var sessionItemResult = new _SessionItemResult.default({
        feedback: {
          graderFeedback: {
            content: 'content'
          }
        }
      });
      feedbackTestbed.render({
        sessionItemResult: sessionItemResult,
        hideGraderFeedback: true
      });
      expect(feedbackTestbed.getText()).to.not.have.string('Grader Feedback');
    });
  });
});