"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 dcmrK_dFUU{to{opacity:1;transform:translateZ(0)}}\n\n.dcmrK_caGd{animation-duration:0.3s;animation-fill-mode:forwards;animation-name:dcmrK_dFUU;opacity:0.01;transform:translateZ(0)}\n\n.dcmrK_caGd td,.dcmrK_caGd th{border-bottom-color:".concat(theme.contentCellBorderColor || 'inherit', ";padding-left:0.35rem;padding-right:0.35rem}\n\n.dcmrK_ddmB td,.dcmrK_ddmB th{padding-bottom:").concat(theme.answerRowCellPadding || 'inherit', ";padding-top:").concat(theme.answerRowCellPadding || 'inherit', ";white-space:nowrap}\n\n.dcmrK_dOeq{background-color:").concat(theme.answerRowCorrectBackgroundColor || 'inherit', "}\n\n.dcmrK_dOeq .dcmrK_cLIq{color:").concat(theme.answerRowAnswerIconColor || 'inherit', "}\n\n.dcmrK_dOeq .dcmrK_ccwL,.dcmrK_dOeq .dcmrK_bFWU{font-weight:").concat(theme.answerRowCorrectTextFieldFontWeight || 'inherit', "}\n\n.dcmrK_dOeq .dcmrK_fKwc{background:").concat(theme.answerRowCorrectBarBackgroundColor || 'inherit', "}\n\ntd.dcmrK_cLIq{color:").concat(theme.answerIconColor || 'inherit', ";font-size:").concat(theme.answerIconFontSize || 'inherit', ";width:1%}\n\nth.dcmrK_bFWU{font-weight:").concat(theme.answerTextfieldFontWeight || 'inherit', ";max-width:12rem;overflow:hidden}\n\n.dcmrK_fTiR{text-align:right;width:1%}\n\n[dir=ltr] .dcmrK_fTiR,[dir=rtl] .dcmrK_fTiR{text-align:right}\n\ntd.dcmrK_fTiR{color:").concat(theme.respondentLinkColor || 'inherit', "}\n\ntd.dcmrK_lHsH{color:").concat(theme.respondentLinkPresentColor || 'inherit', "}\n\n.dcmrK_ccwL{text-align:right;width:1%}\n\n[dir=ltr] .dcmrK_ccwL,[dir=rtl] .dcmrK_ccwL{text-align:right}\n\ntd.dcmrK_ccwL{padding-left:").concat(theme.answerRatioPaddingLeft || 'inherit', "}\n\ntd.dcmrK_dEZf{border-bottom-color:transparent;height:2.3rem;min-width:7rem;padding:0;width:7rem}\n\n.dcmrK_fKwc{background:").concat(theme.barBackgroundColor || 'inherit', ";height:100%;min-width:").concat(theme.barMinWidth || 'inherit', ";position:relative;transition:width 0.5s}\n\n@media screen and (--phoneBreakPoint){th.dcmrK_bFWU{max-width:0}th.dcmrK_fTiR{max-width:3rem;overflow:hidden;text-overflow:ellipsis}}");
  },
  'content': 'dcmrK_caGd',
  'contentAnimation': 'dcmrK_dFUU',
  'answerRow': 'dcmrK_ddmB',
  'answerRowCorrect': 'dcmrK_dOeq',
  'answerIcon': 'dcmrK_cLIq',
  'answerRatio': 'dcmrK_ccwL',
  'answerTextfield': 'dcmrK_bFWU',
  'bar': 'dcmrK_fKwc',
  'respondentLink': 'dcmrK_fTiR',
  'respondentLinkPresent': 'dcmrK_lHsH',
  'answerDistributionCell': 'dcmrK_dEZf'
};
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%']);
  });
});