"use strict";

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

var _testUtils = _interopRequireDefault(require("react-dom/test-utils"));

var _Popover = _interopRequireDefault(require("@instructure/ui-overlays/lib/components/Popover"));

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

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

describe('AddContentPopover', function () {
  var switchOffEditingStub = sinon.stub();
  var switchOnEditingStub = sinon.stub();
  var clearUiStub = sinon.stub();
  var openAddContentModalStub = sinon.stub();
  var defaultProps = {
    allowStimulusCreation: true,
    appContainer: '#app',
    clearUi: clearUiStub,
    isEditing: true,
    isMobile: false,
    openAddContentModal: openAddContentModalStub,
    parentEntryId: 'parent123',
    position: 5,
    quizId: 'quiz123',
    shouldFocus: false,
    stimulusId: 'stimulus123',
    switchOffEditing: switchOffEditingStub,
    switchOnEditing: switchOnEditingStub,
    useStimulusTrigger: true
  };
  var testbed = createTestbed(withContext(_presenter.default), defaultProps);
  beforeEach(function () {
    switchOffEditingStub.resetHistory();
    switchOnEditingStub.resetHistory();
    clearUiStub.resetHistory();
    openAddContentModalStub.resetHistory();
  });
  it('renders a popover when not on mobile', function () {
    testbed.render();
    var popover = testbed.findChildByType(_Popover.default);
    expect(popover).to.exist();
  });
  it('renders an open modal button when on mobile', function () {
    testbed.render({
      isMobile: true
    });
    var popover = testbed.findChildrenByType(_Popover.default)[0];
    expect(popover).to.not.exist();
    var button = testbed.findChildByTagName('button');

    _testUtils.default.Simulate.click(button);

    expect(openAddContentModalStub.called).to.be.true();
    var args = openAddContentModalStub.firstCall.args;
    expect(args[0]).to.eql({
      allowStimulusCreation: defaultProps.allowStimulusCreation,
      parentEntryId: defaultProps.parentEntryId,
      position: defaultProps.position,
      quizId: defaultProps.quizId,
      stimulusId: defaultProps.stimulusId
    });
  });
  it('focuses correctly', function () {
    var clock = sinon.useFakeTimers();
    testbed.render();
    testbed.render({
      shouldFocus: true
    });
    clock.tick(200);
    expect(clearUiStub.calledWith(_constants.DELETED_QUIZ_ENTRY)).to.be.true();
    expect(document.activeElement).to.exist();
    clock.restore();
  });
  describe('test with connect', function () {
    shouldRenderComponent(testbed, {}, _presenter.default);
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.render();
      testbed.checkA11yStandards(done);
    });
  });
});