"use strict";

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

var _immutable = require("immutable");

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

var _DragHandle = _interopRequireDefault(require("../../../../../common/components/shared/drag_and_drop/DragHandle"));

var _QuizEntry = _interopRequireDefault(require("../../../../../common/records/QuizEntry"));

var styles = {
  componentId: 'hXnXu',
  template: function template(theme) {
    return "\n\n.ActionButtons__styles__buttons {\n  flex: 0 0 auto;\n  display: inline-flex;\n  text-align: right;\n  z-index: ".concat(theme.buttonsZIndex || 'inherit', ";\n  color: ").concat(theme.buttonsColor || 'inherit', ";\n  font-size: 1.1rem;\n  padding: 0 ").concat(theme.buttonsPadding || 'inherit', ";\n}\n\n[dir=\"ltr\"] .ActionButtons__styles__buttons {\n  text-align: right;\n}\n\n[dir=\"rtl\"] .ActionButtons__styles__buttons {\n  text-align: right;\n}\n\n.ActionButtons__styles__edit.ActionButtons__styles__hide {\n  display: none;\n}\n");
  },
  'buttons': 'ActionButtons__styles__buttons',
  'edit': 'ActionButtons__styles__edit',
  'hide': 'ActionButtons__styles__hide'
};
describe('ActionButtons', function () {
  var qe1 = new _QuizEntry.default();
  var qe2 = new _QuizEntry.default();
  var props = {
    connectDragSource: sinon.stub(),
    displayPosition: 1,
    onDelete: sinon.stub(),
    quizEntries: (0, _immutable.fromJS)([qe1, qe2]),
    quizEntry: qe1,
    switchOnEditing: sinon.stub()
  };
  var testbed = createTestbed(_presenter.default, props);
  beforeEach(function () {
    props.connectDragSource.resetHistory();
    props.onDelete.resetHistory();
    props.switchOnEditing.resetHistory();
  });

  function findButtons() {
    return testbed.findWhere(function (node) {
      return (node.name() || '').includes('Button');
    });
  }

  it('renders two buttons', function () {
    testbed.renderShallowly();
    expect(findButtons().length).to.eq(2);
  });
  it('renders the dragHandle', function () {
    testbed.renderShallowly({
      connectDragSource: function connectDragSource(C) {
        return C;
      }
    });
    expect(testbed.find(_DragHandle.default).length).to.eq(1);
  });
  it('wraps the dragHandle in a dragSource', function () {
    testbed.renderShallowly();
    expect(props.connectDragSource.calledOnce).to.be.true();
  });
  it('hides the edit button when shouldRenderEdit is false', function () {
    testbed.renderShallowly({
      shouldRenderEdit: false
    });
    expect(testbed.find(".".concat(styles.hide))).to.not.be.empty();
  });
  it('calls the onDelete button when clicked', function () {
    testbed.renderShallowly();
    var deleteButton = findButtons().last();
    deleteButton.simulate('click');
    expect(props.onDelete.calledOnce).to.be.true();
  });
  it('calls the switchOnEditing button when clicked', function () {
    testbed.renderShallowly();
    var editButton = findButtons().first();
    editButton.simulate('click');
    expect(props.switchOnEditing.calledOnce).to.be.true();
  });
  describe('a11y tests', function () {
    it('should meet a11y standards', function (done) {
      testbed.renderShallowly();
      testbed.checkA11yStandards(done, {
        ignores: ['label', 'label-title-only']
      });
    });
  });
});