"use strict";

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

var _immutable = require("immutable");

var _constants = require("@instructure/quiz-common/lib/constants");

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

var _QuizEntry = _interopRequireDefault(require("../../../../../records/QuizEntry"));

var _withContext = _interopRequireDefault(require("../../../../../../../tests/util/withContext"));

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

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

describe('ItemOverride', function () {
  var itemAttributes = {
    id: '1',
    interactionType: '1',
    title: 'Pizza',
    itemBody: 'Pineapple on pizza is:',
    interactionData: {
      choices: [{
        id: 'id1',
        itemBody: 'an abomination',
        position: 1
      }, {
        id: 'id2',
        itemBody: 'fine, I guess',
        position: 2
      }, {
        id: 'id3',
        itemBody: 'delicious',
        position: 3
      }]
    },
    scoringData: {
      value: 'id2'
    }
  };
  var quizEntryAttributes = {
    id: '3',
    entryType: 'BankEntry',
    entry: {
      id: '2'
    }
  };
  var itemOverrides = {
    properties: {
      varyPointsByAnswer: true
    },
    scoringAlgorithm: 'VaryPointsByAnswer',
    scoringData: {
      values: [{
        value: 'id1',
        points: 3
      }, {
        value: 'id2',
        points: 1
      }, {
        value: 'id2',
        points: 0
      }]
    }
  };
  var quizId = '1';
  var state = {
    quizzes: {
      activeQuizId: quizId
    },
    interactionTypes: {
      1: {
        id: '1',
        name: 'Multiple Choice',
        slug: 'choice'
      }
    },
    items: {
      1: itemAttributes
    },
    bankEntries: {
      2: {
        id: '2',
        entryType: 'Item',
        entry: {
          id: '1'
        }
      }
    },
    quizEntries: {
      3: quizEntryAttributes
    },
    modifications: {
      quizEntries: {
        3: {
          properties: {
            itemOverrides: itemOverrides
          }
        }
      }
    }
  };
  var item = new _Item.default((0, _immutable.fromJS)(itemAttributes));
  var quizEntry = new _QuizEntry.default((0, _immutable.fromJS)(quizEntryAttributes));
  var testbed = createTestbed((0, _withContext.default)(_index.default, state), {
    entry: item,
    guid: '1',
    handleQuizEntryPointsChange: function handleQuizEntryPointsChange() {},
    parentId: quizId,
    parentType: _constants.PARENT_TYPE_QUIZ,
    quizEntry: quizEntry
  });
  beforeEach(function () {
    return (0, _reduxStore.setFakeStore)((0, _immutable.fromJS)(state));
  });
  afterEach(function () {
    return (0, _reduxStore.unsetFakeStore)();
  });
  it('passes property overrides through to the interaction component', function () {
    testbed.render();
    var labels = testbed.findChildrenByTagName('label');
    var varyPointsLabel = labels.find(function (label) {
      return label.innerText.includes('Vary points by answer');
    });
    var varyPointsCheckbox = document.getElementById(varyPointsLabel.htmlFor);
    expect(varyPointsCheckbox.checked).to.be.true();
  });
  it('passes scoringData overrides through to the interaction component', function () {
    testbed.render();
    var numberInputs = testbed.findChildrenByTagNameAndAttribute('input', 'inputmode', 'numeric');
    expect(numberInputs.map(function (input) {
      return input.value;
    })).to.deep.equal(itemOverrides.scoringData.values.map(function (override) {
      return override.points.toString();
    }));
  });
});