"use strict";

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

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

var _keys = _interopRequireDefault(require("lodash/keys"));

var _makeEditable = _interopRequireDefault(require("../makeEditable"));

var _editing = require("../../../../actions/editing");

var _PlainComponent = _interopRequireDefault(require("../../../../../../tests/util/PlainComponent"));

describe('makeEditable', function () {
  var fakeGuid = 'fakeGUIDValue';
  var dispatchStub = sinon.stub();
  var EditableComponent = (0, _makeEditable.default)(_PlainComponent.default);
  var EditableComponentWithContext = withContext(EditableComponent, {
    dispatchStub: dispatchStub
  });
  var testbed = createTestbed(EditableComponentWithContext, {
    guid: fakeGuid
  });

  var getComponents = function getComponents(testbed) {
    var composedComponent = testbed.findChildByType(_PlainComponent.default);
    var editableComponent = testbed.findChildByType(EditableComponent);
    return [composedComponent, editableComponent];
  };

  afterEach(function () {
    dispatchStub.resetHistory();
  });
  it('should render a child component', function () {
    testbed.render();
    var composedComponent = getComponents(testbed)[0];
    expect(composedComponent).to.not.be.undefined();
  });
  it('the composed component has the proper state passed via props', function () {
    testbed.render();
    var composedComponent = getComponents(testbed)[0];
    expect((0, _keys.default)(composedComponent.props)).to.include('isEditing');
  });
  it('the composed component has the proper actions', function () {
    testbed.render();
    var composedComponent = getComponents(testbed)[0];
    expect((0, _keys.default)(composedComponent.props)).to.include('switchOnEditing');
    expect((0, _keys.default)(composedComponent.props)).to.include('switchOffEditing');
  });
  it('switchOnEditing props dispatches well-formed event', function () {
    testbed.render();

    var _getComponents = getComponents(testbed),
        _getComponents2 = (0, _slicedToArray2.default)(_getComponents, 1),
        composedComponent = _getComponents2[0];

    var startAction = (0, _editing.startEdit)(fakeGuid);
    expect(dispatchStub.calledWith(startAction)).to.be.false();
    composedComponent.props.switchOnEditing();
    expect(dispatchStub.calledWith(startAction)).to.be.true();
  });
  it('switchOffEditing props dispatches well-formed event', function () {
    testbed.render();

    var _getComponents3 = getComponents(testbed),
        _getComponents4 = (0, _slicedToArray2.default)(_getComponents3, 1),
        composedComponent = _getComponents4[0];

    var endAction = (0, _editing.endEdit)(fakeGuid);
    expect(dispatchStub.calledWith(endAction)).to.be.false();
    composedComponent.props.switchOffEditing();
    expect(dispatchStub.calledWith(endAction)).to.be.true();
  });
  context('with editing true', function () {
    var ComponentWithEditingOn = withContext(EditableComponent, {
      editing: {
        foo: true
      }
    });
    var testbedWithEditing = createTestbed(ComponentWithEditingOn, {
      guid: fakeGuid
    });
    describe('a11y tests', function () {
      it('should meet a11y standards', function (done) {
        testbedWithEditing.render();
        testbedWithEditing.checkA11yStandards(done);
      });
    });
  });
});