'use strict';

Object.defineProperty(exports, "__esModule", {
  value: true
});

exports.default = function (Component, label, props, stubbedFunc) {
  var checkboxIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;

  var testbed = createTestbed(Component, props);

  var findCheckbox = function findCheckbox() {
    return testbed.findChildrenByTagNameAndAttribute('input', 'type', 'checkbox')[checkboxIndex];
  };

  return describe(label + ' acts as an option', function () {
    it('should show a toggle for option', function () {
      testbed.render();
      var output = testbed.getText();
      expect(output).to.include(label);
      var checkbox = findCheckbox();
      expect(checkbox).to.exist();
      expect(checkbox.checked).to.be.true();
    });

    it('should show a checked toggle for option when enabled', function () {
      testbed.render();
      var checkbox = findCheckbox();
      expect(checkbox).to.exist();
      expect(checkbox.checked).to.be.true();
    });

    it('should toggle option when clicked', function () {
      testbed.render();
      var checkbox = findCheckbox();

      _testUtils2.default.Simulate.change(checkbox, { target: { checked: false } });

      expect(stubbedFunc.calledWith('1', false)).to.be.true();

      _testUtils2.default.Simulate.change(checkbox, { target: { checked: true } });

      expect(stubbedFunc.calledWith('1', true)).to.be.true();
    });

    describe('a11y tests', function () {
      it('should meet a11y standards', function (done) {
        testbed.render();
        testbed.checkA11yStandards(done, {
          ignores: ['aria-allowed-role', // TODO: remove this when instui fixes Select
          'listitem']
        });
      });
    });
  });
};

exports.actsAsTextInput = actsAsTextInput;

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

var _testUtils2 = _interopRequireDefault(_testUtils);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

function actsAsTextInput(Component, label, value, props) {
  var inputIndex = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : 0;

  var testbed = createTestbed(Component, props);

  var findInput = function findInput() {
    return testbed.findChildrenByTagNameAndAttribute('input', 'type', 'text')[inputIndex];
  };

  return describe(label + ' acts as a textbox', function () {
    it('should show a field for input', function () {
      testbed.render();
      var output = testbed.getText();
      expect(output).to.include(label);
      var input = findInput();
      expect(input).to.exist();
      expect(input.value).to.equal(value);
    });

    describe('a11y tests', function () {
      it('should meet a11y standards', function (done) {
        testbed.render();
        testbed.checkA11yStandards(done, { ignores: ['listitem'] });
      });
    });
  });
}