"use strict";

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

var _reactDom = _interopRequireDefault(require("react-dom"));

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

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

var _mouseEventOn = _interopRequireDefault(require("../../../../../../../../tests/util/mouseEventOn"));

var _editableFieldTests = _interopRequireDefault(require("../../../__tests__/editableFieldTests"));

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

describe('QuizInstructionsEdit', function () {
  // shared tests with QuizTitleEdit
  (0, _editableFieldTests.default)(_presenter.default);
  var saveAndPreviewStub = sinon.stub();
  var endEditingStub = sinon.stub();
  var testbed = createTestbed(withContext(_presenter.default), {
    endEditing: endEditingStub,
    inputValue: 'foo',
    onInputChange: function onInputChange() {},
    quizId: '42',
    saveAndPreview: saveAndPreviewStub,
    appContainer: '.root'
  });
  afterEach(function () {
    saveAndPreviewStub.resetHistory();
    endEditingStub.resetHistory();
  });
  it('calls saveAndPreview on click outside', function () {
    testbed.render();
    var outerElement = document.createElement('div');
    outerElement.className = 'root';
    document.body.appendChild(outerElement);
    (0, _mouseEventOn.default)(outerElement, 'click');
    expect(saveAndPreviewStub).to.have.been.calledOnce();
  });
  it('calls saveAndPreview when clicked Done', function () {
    testbed.render();

    var doneButton = _reactDom.default.findDOMNode(testbed.findChildrenByType(_Button.default)[2]);

    expect(doneButton.innerText).to.include('Done');

    _testUtils.default.Simulate.click(doneButton);

    expect(saveAndPreviewStub).to.have.been.called();
  });
  it('calls endEditing when clicked Cancel', function () {
    testbed.render();

    var cancelButton = _reactDom.default.findDOMNode(testbed.findChildrenByType(_Button.default)[1]);

    expect(cancelButton.innerText).to.include('Cancel');

    _testUtils.default.Simulate.click(cancelButton);

    expect(endEditingStub).to.have.been.called();
    expect(saveAndPreviewStub).to.have.not.been.called();
  });
});