"use strict";

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

var _immutable = require("immutable");

var _InteractionType = _interopRequireDefault(require("quiz-interactions/lib/records/InteractionType"));

var _Button = _interopRequireDefault(require("@instructure/ui-buttons/lib/components/Button"));

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

describe('InteractionTypes', function () {
  var addItemStub = sinon.stub();
  var addStimulusStub = sinon.stub();
  var testbed = createTestbed(_presenter.default, {
    addItem: addItemStub,
    addStimulus: addStimulusStub,
    types: (0, _immutable.List)([]),
    columns: 2,
    stimulusOn: true,
    stimulusBankingOn: true
  });

  var fakeInteractionType = function fakeInteractionType() {
    var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'choice';
    return new _InteractionType.default({
      name: name
    });
  };

  var types = (0, _immutable.List)([fakeInteractionType(), fakeInteractionType('multi-answer'), fakeInteractionType('hotspot')]);
  var ShallowTestbed = testbed.renderShallowly({
    allowStimulusCreation: false,
    types: types
  });
  it('should show one button per interactionType', function () {
    var buttons = ShallowTestbed.find(_Button.default);
    expect(buttons.length).to.be.equal(3);
  });
  it('should pass fluidWidth to each button', function () {
    ShallowTestbed.find(_Button.default).forEach(function (button) {
      expect(button.prop('fluidWidth')).to.eq(true);
    });
  });
  it('should show a button when stimulus creation is allowed', function () {
    var ShallowTestbed = testbed.renderShallowly({
      allowStimulusCreation: true,
      types: types
    });
    var buttons = ShallowTestbed.find(_Button.default);
    expect(buttons.length).to.be.equal(4);
  });
  it('should call add item on click', function () {
    var buttons = ShallowTestbed.find(_Button.default);
    buttons.first().simulate('click');
    expect(addItemStub.called).to.be.true();
  });
  it('should call add stimulus on click', function () {
    var ShallowTestbed = testbed.renderShallowly({
      allowStimulusCreation: true,
      types: types
    });
    var buttons = ShallowTestbed.find(_Button.default);
    buttons.last().simulate('click');
    expect(addStimulusStub.called).to.be.true();
  });
});