"use strict";

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

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

var _ = _interopRequireDefault(require(".."));

var _ExtraHoursMinutes = _interopRequireDefault(require("../../ExtraHoursMinutes"));

var _Select = _interopRequireDefault(require("@instructure/ui-forms/lib/components/Select"));

describe('ExtraTimeSettings', function () {
  var sandbox = sinon.createSandbox();
  var onChangeSpy = sandbox.spy();
  var defaultProps = {
    onChange: onChangeSpy,
    timerSettings: {
      disableTimer: false,
      extraTimeEnabled: false,
      extraTimeInSeconds: null,
      extraTimeUnit: null,
      extraTimeValue: null,
      increaseTimeAllowance: false,
      timerMultiplierEnabled: false,
      timerMultiplierValue: null
    },
    maxTimeInSeconds: 72000,
    maxMultiplier: 20,
    minMultiplier: 1
  };
  var testbed = createTestbed(_.default, defaultProps);

  var changeToAnswerType = function changeToAnswerType(testbed, newType) {
    var selectComponent = testbed.findChildrenByType(_Select.default)[0];
    selectComponent.props.onChange({
      target: {
        value: newType
      }
    }, {
      value: newType
    });
  };

  var getLabelByText = function getLabelByText(testbed, labelText) {
    var labels = testbed.findChildrenByTagName('label');
    var label = labels.filter(function (el) {
      return testbed.getText(el).indexOf(labelText) > -1;
    });
    return label[0];
  };

  beforeEach(function () {
    sandbox.resetHistory();
  });
  it('renders a Select', function () {
    testbed.render();
    expect(getLabelByText(testbed, 'Time adjustments')).to.exist();
  });
  it('should render an extra time dialog', function () {
    testbed.render({
      timerSettings: (0, _objectSpread2.default)({}, defaultProps.timerSettings, {
        extraTimeEnabled: true
      })
    });
    expect(getLabelByText(testbed, 'Hours')).to.exist();
    expect(getLabelByText(testbed, 'Minutes')).to.exist();
  });
  it('should render a time multiplier dialog', function () {
    testbed.render({
      timerSettings: (0, _objectSpread2.default)({}, defaultProps.timerSettings, {
        timerMultiplierEnabled: true
      })
    });
    expect(getLabelByText(testbed, 'Multiplier')).to.exist();
  });
  it('should call back values from inputs', function () {
    testbed.render();
    changeToAnswerType(testbed, 'timerMultiplierEnabled');
    expect(onChangeSpy).to.have.been.calledWithMatch({
      timerMultiplierEnabled: true
    });
  });
  it('should call back values from children', function () {
    testbed.render({
      timerSettings: (0, _objectSpread2.default)({}, defaultProps.timerSettings, {
        extraTimeEnabled: true
      })
    });
    var child = testbed.findChildByType(_ExtraHoursMinutes.default);
    child.props.onChange(180);
    expect(onChangeSpy).to.have.been.calledWithMatch({
      extraTimeInSeconds: 180
    });
  });
  it('should be accessible', function (done) {
    testbed.render();
    testbed.checkA11yStandards(done);
  });
});