"use strict";

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

var _immutable = require("immutable");

var _ItemAnalysis = _interopRequireDefault(require("../../../../../common/records/ItemAnalysis"));

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

var styles = {
  componentId: 'dcmrK',
  template: function template(theme) {
    return "\n\n@keyframes AnswerFrequencySummary__styles__contentAnimation {\n  to {\n    opacity: 1;\n    transform: translate3d(0, 0, 0);\n  }\n}\n\n.AnswerFrequencySummary__styles__content {\n  opacity: 0.01;\n  transform: translate3d(0, 0, 0);\n  animation-name: AnswerFrequencySummary__styles__contentAnimation;\n  animation-fill-mode: forwards;\n  animation-duration: 0.3s;\n}\n\n.AnswerFrequencySummary__styles__content th,\n  .AnswerFrequencySummary__styles__content td {\n    border-bottom-color: ".concat(theme.contentCellBorderColor || 'inherit', ";\n    padding-left: 0.35rem;\n    padding-right: 0.35rem;\n  }\n\n.AnswerFrequencySummary__styles__answerRow th,\n  .AnswerFrequencySummary__styles__answerRow td {\n    padding-top: ").concat(theme.answerRowCellPadding || 'inherit', ";\n    padding-bottom: ").concat(theme.answerRowCellPadding || 'inherit', ";\n    white-space: nowrap;\n  }\n\n.AnswerFrequencySummary__styles__answerRowCorrect {\n  background-color: ").concat(theme.answerRowCorrectBackgroundColor || 'inherit', ";\n}\n\n.AnswerFrequencySummary__styles__answerRowCorrect .AnswerFrequencySummary__styles__answerIcon {\n    color: ").concat(theme.answerRowAnswerIconColor || 'inherit', ";\n  }\n\n.AnswerFrequencySummary__styles__answerRowCorrect .AnswerFrequencySummary__styles__answerTextfield,\n  .AnswerFrequencySummary__styles__answerRowCorrect .AnswerFrequencySummary__styles__answerRatio {\n    font-weight: ").concat(theme.answerRowCorrectTextFieldFontWeight || 'inherit', ";\n  }\n\n.AnswerFrequencySummary__styles__answerRowCorrect .AnswerFrequencySummary__styles__bar {\n    background: ").concat(theme.answerRowCorrectBarBackgroundColor || 'inherit', ";\n  }\n\ntd.AnswerFrequencySummary__styles__answerIcon {\n  font-size: ").concat(theme.answerIconFontSize || 'inherit', ";\n  color: ").concat(theme.answerIconColor || 'inherit', ";\n  width: 1%;\n}\n\nth.AnswerFrequencySummary__styles__answerTextfield {\n  font-weight: ").concat(theme.answerTextfieldFontWeight || 'inherit', ";\n  overflow: hidden;\n  max-width: 12rem;\n}\n\n.AnswerFrequencySummary__styles__respondentLink {\n  text-align: right;\n  width: 1%;\n}\n\n[dir=\"ltr\"] .AnswerFrequencySummary__styles__respondentLink {\n  text-align: right;\n}\n\n[dir=\"rtl\"] .AnswerFrequencySummary__styles__respondentLink {\n  text-align: right;\n}\n\ntd.AnswerFrequencySummary__styles__respondentLink {\n  color: ").concat(theme.respondentLinkColor || 'inherit', ";\n}\n\ntd.AnswerFrequencySummary__styles__respondentLinkPresent {\n  color: ").concat(theme.respondentLinkPresentColor || 'inherit', ";\n}\n\n.AnswerFrequencySummary__styles__answerRatio {\n  text-align: right;\n  width: 1%;\n}\n\n[dir=\"ltr\"] .AnswerFrequencySummary__styles__answerRatio {\n  text-align: right;\n}\n\n[dir=\"rtl\"] .AnswerFrequencySummary__styles__answerRatio {\n  text-align: right;\n}\n\ntd.AnswerFrequencySummary__styles__answerRatio {\n  padding-left: ").concat(theme.answerRatioPaddingLeft || 'inherit', ";\n}\n\ntd.AnswerFrequencySummary__styles__answerDistributionCell {\n  border-bottom-color: transparent;\n  padding: 0;\n  width: 7rem;\n  min-width: 7rem;\n  height: 2.3rem;\n}\n\n.AnswerFrequencySummary__styles__bar {\n  background: ").concat(theme.barBackgroundColor || 'inherit', ";\n  transition: width 0.5s;\n  position: relative;\n  min-width: ").concat(theme.barMinWidth || 'inherit', ";\n  height: 100%;\n}\n\n@media screen and (--phoneBreakPoint) {\n  th.AnswerFrequencySummary__styles__answerTextfield {\n    max-width: 0;\n  }\n\n  th.AnswerFrequencySummary__styles__respondentLink {\n    max-width: 3rem;\n    overflow: hidden;\n    text-overflow: ellipsis;\n  }\n}\n");
  },
  'content': 'AnswerFrequencySummary__styles__content',
  'contentAnimation': 'AnswerFrequencySummary__styles__contentAnimation',
  'answerRow': 'AnswerFrequencySummary__styles__answerRow',
  'answerRowCorrect': 'AnswerFrequencySummary__styles__answerRowCorrect',
  'answerIcon': 'AnswerFrequencySummary__styles__answerIcon',
  'answerTextfield': 'AnswerFrequencySummary__styles__answerTextfield',
  'answerRatio': 'AnswerFrequencySummary__styles__answerRatio',
  'bar': 'AnswerFrequencySummary__styles__bar',
  'respondentLink': 'AnswerFrequencySummary__styles__respondentLink',
  'respondentLinkPresent': 'AnswerFrequencySummary__styles__respondentLinkPresent',
  'answerDistributionCell': 'AnswerFrequencySummary__styles__answerDistributionCell'
};
describe('AnswerFrequencySummary', function () {
  var standardItemAnalysis = new _ItemAnalysis.default((0, _immutable.fromJS)({
    itemId: '3',
    itemAnalysis: {
      scoreInfo: {
        resultSum: 5,
        resultCount: 1
      },
      unansweredInfo: 1,
      choiceInfo: [{
        choiceCount: 2,
        id: 'id',
        itemBody: '<p>Item&gt;Body</p>',
        correct: true
      }, {
        choiceCount: 3,
        id: 'not_id',
        itemBody: 'choice Item Body not correct',
        correct: false
      }, {
        choiceCount: 4,
        id: 'not_id_again',
        itemBody: 'choice Item Body not correct still',
        correct: false
      }]
    }
  }));
  var testbed = createTestbed(_index.default, {
    itemAnalysis: standardItemAnalysis
  });
  shouldRenderComponent(testbed, {}, _index.default);
  it('should render the choice chart', function () {
    testbed.render();
    var output = testbed.getText(); // Add more stuff here when we render an overview

    expect(output).to.include('Item>Body');
    expect(output).to.include('Respondents');
  });
  it('should render the choice chart with the body html stripped', function () {
    testbed.render();
    var output = testbed.getText();
    expect(output).to.include('Item>Body');
    expect(output).to.not.include('<p>');
  });
  it('should render correct label when choice body has no text content', function () {
    testbed.render({
      itemAnalysis: standardItemAnalysis.setIn(['itemAnalysis', 'choiceInfo'], (0, _immutable.fromJS)([{
        choiceCount: 2,
        id: 'id',
        itemBody: '<p><strong></strong></p>',
        correct: true
      }]))
    });
    var cell = testbed.findChildrenByClass(styles.answerTextfield)[0];
    var output = testbed.getText(cell);
    expect(output).to.include('Correct Answer');
  });
  it('should render the correct row w/ correct labeling', function () {
    testbed.render();
    var rowText = testbed.rootNode.getElementsByClassName(styles.bar)[0].parentNode.parentNode.innerText;
    expect(rowText).to.include('Correct Answer');
    expect(rowText).to.include('Item>Body');
  });
  it('should render the unanswered row', function () {
    testbed.render();
    var row = testbed.findChildrenBySelector('tbody tr:last-child')[0];
    var colTexts = testbed.findChildrenBySelector('th, td', row).map(function (c) {
      return c.innerText;
    });
    expect(colTexts.slice(0, 4).map(function (s) {
      return s.trim();
    })).to.eql(['Incorrect Answer', '(No answer)', '1', '10%']);
  });
  it('should render the bar graph', function () {
    testbed.render();
    var widths = testbed.findChildrenByClass(styles.bar).map(function (b) {
      return b.style.width;
    });
    expect(widths).to.eql(['50%', '75%', '100%', '25%']);
  });
});