text: function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
  
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
  
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
  
  function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
  
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
  
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
  
  function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
  
  function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
  
  /**
   * Copyright IBM Corp. 2016, 2018
   *
   * This source code is licensed under the Apache-2.0 license found in the
   * LICENSE file in the root directory of this source tree.
   */
  import React from 'react';
  import Checkbox from '../Checkbox';
  import CheckboxSkeleton from '../Checkbox/Checkbox.Skeleton';
  import { mount } from 'enzyme';
  import { settings } from 'carbon-components';
  var prefix = settings.prefix;
  describe('Checkbox', function () {
    describe('Renders as expected', function () {
      var wrapper = mount(React.createElement(Checkbox, {
        id: "testing",
        labelText: "testingLabel",
        className: "extra-class"
      }));
      var label = wrapper.find('label');
      describe('label', function () {
        it('renders a label', function () {
          expect(label.length).toEqual(1);
        });
        it('has the expected classes', function () {
          expect(label.hasClass("".concat(prefix, "--checkbox-label"))).toEqual(true);
        });
        it('has the expected htmlFor value', function () {
          expect(label.props().htmlFor).toEqual('testing');
        });
        it('applies extra classes to label', function () {
          expect(label.hasClass('extra-class')).toEqual(true);
        });
        describe('input', function () {
          var input = function input() {
            return wrapper.find('input');
          };
  
          it('has id set as expected', function () {
            expect(input().props().id).toEqual('testing');
          });
          it('defaultChecked prop sets defaultChecked on input', function () {
            expect(input().props().defaultChecked).toBeUndefined();
            wrapper.setProps({
              defaultChecked: true
            });
            expect(input().props().defaultChecked).toEqual(true);
          });
        });
      });
    });
    it('disabled prop on component sets disabled prop on input', function () {
      var wrapper = mount(React.createElement(Checkbox, {
        id: "test",
        labelText: "testlabel",
        disabled: true
      }));
  
      var input = function input() {
        return wrapper.find('input');
      };
  
      expect(input().props().disabled).toEqual(true);
      wrapper.setProps({
        disabled: false
      });
      expect(input().props().disabled).toEqual(false);
    });
    it('checked prop on component sets checked prop on input', function () {
      var wrapper = mount(React.createElement(Checkbox, {
        id: "test",
        labelText: "testlabel",
        checked: true
      }));
  
      var input = function input() {
        return wrapper.find('input');
      };
  
      expect(input().props().checked).toEqual(true);
      wrapper.setProps({
        checked: false
      });
      expect(input().props().checked).toEqual(false);
    });
    it('hideLabel hides the label visually', function () {
      var wrapper = mount(React.createElement(Checkbox, {
        id: "test",
        labelText: "testlabel",
        hideLabel: true
      }));
      var label = wrapper.find('label');
      expect(label.length).toEqual(1);
      var span = wrapper.find('span');
      expect(span.hasClass("".concat(prefix, "--visually-hidden"))).toEqual(true);
    });
    describe('events', function () {
      it('should invoke onChange with expected arguments', function () {
        var onChange = jest.fn();
        var id = 'test-input';
        var wrapper = mount(React.createElement(Checkbox, {
          labelText: "testlabel",
          id: id,
          onChange: onChange
        }));
        var input = wrapper.find('input');
        var inputElement = input.instance();
        inputElement.checked = true;
        wrapper.find('input').simulate('change');
        var call = onChange.mock.calls[0];
        expect(call[0]).toEqual(true);
        expect(call[1]).toEqual(id);
        expect(call[2].target).toBe(inputElement);
      });
    });
  });
  describe('refs', function () {
    it('should accept refs', function () {
      var MyComponent =
      /*#__PURE__*/
      function (_React$Component) {
        _inherits(MyComponent, _React$Component);
  
        function MyComponent(props) {
          var _this;
  
          _classCallCheck(this, MyComponent);
  
          _this = _possibleConstructorReturn(this, _getPrototypeOf(MyComponent).call(this, props));
          _this.myRef = React.createRef();
          _this.focus = _this.focus.bind(_assertThisInitialized(_this));
          return _this;
        }
  
        _createClass(MyComponent, [{
          key: "focus",
          value: function focus() {
            this.myRef.current.focus();
          }
        }, {
          key: "render",
          value: function render() {
            return React.createElement(Checkbox, {
              id: "test",
              labelText: "testlabel",
              hideLabel: true,
              ref: this.myRef
            });
          }
        }]);
  
        return MyComponent;
      }(React.Component);
  
      var wrapper = mount(React.createElement(MyComponent, null));
      expect(document.activeElement.type).toBeUndefined();
      wrapper.instance().focus();
      expect(document.activeElement.type).toEqual('checkbox');
    });
    it('should set indeterminate when accepting refs', function () {
      var MyComponent =
      /*#__PURE__*/
      function (_React$Component2) {
        _inherits(MyComponent, _React$Component2);
  
        function MyComponent(props) {
          var _this2;
  
          _classCallCheck(this, MyComponent);
  
          _this2 = _possibleConstructorReturn(this, _getPrototypeOf(MyComponent).call(this, props));
          _this2.myRef = React.createRef();
          return _this2;
        }
  
        _createClass(MyComponent, [{
          key: "render",
          value: function render() {
            return React.createElement(Checkbox, {
              indeterminate: true,
              ref: this.myRef
            });
          }
        }]);
  
        return MyComponent;
      }(React.Component);
  
      var wrapper = mount(React.createElement(MyComponent, null));
      expect(wrapper.find('input').getDOMNode().indeterminate).toBe(true);
    });
  });
  describe('CheckboxSkeleton', function () {
    describe('Renders as expected', function () {
      var wrapper = mount(React.createElement(CheckboxSkeleton, null));
      var label = wrapper.find('label');
      describe('label', function () {
        it('renders a label', function () {
          expect(label.length).toEqual(1);
        });
        it('has the expected classes', function () {
          expect(label.hasClass("".concat(prefix, "--checkbox-label"))).toEqual(true);
          expect(label.hasClass("".concat(prefix, "--skeleton"))).toEqual(true);
        });
      });
    });
  });