"use strict";

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

var _react = _interopRequireDefault(require("react"));

var _react2 = require("@testing-library/react");

var _index = _interopRequireDefault(require("../index"));

describe('Switch', function () {
  afterEach(function () {
    jest.restoreAllMocks();
  });
  describe('snapshot', function () {
    it('renders correctly', function () {
      var _render = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, null)),
          container = _render.container;

      expect(container).toMatchSnapshot();
    });
    it('defaultChecked', function () {
      var _render2 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
        defaultChecked: true
      })),
          container = _render2.container;

      expect(container).toMatchSnapshot();
    });
  });
  describe('behaviour', function () {
    it('should switch on if defaultChecked is true', function () {
      var _render3 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
        defaultChecked: true
      })),
          container = _render3.container;

      var inputWrapper = container.querySelector('input');
      expect(inputWrapper.disabled).toBeFalsy();
      expect(inputWrapper.value).toEqual('on');
      expect(inputWrapper.defaultChecked).toBeTruthy();
    });
    it('should switch off and disabled', function () {
      var _render4 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
        disabled: true
      })),
          container = _render4.container;

      var inputWrapper = container.querySelector('input');
      expect(inputWrapper.disabled).toBeTruthy();
      expect(inputWrapper.value).toEqual('off');
      expect(inputWrapper.checked).toBeFalsy();
    });
    it('should switch on and disabled', function () {
      var _render5 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
        defaultChecked: true,
        disabled: true
      })),
          container = _render5.container;

      var inputWrapper = container.querySelector('input');
      expect(inputWrapper.disabled).toBeTruthy();
      expect(inputWrapper.value).toEqual('on');
      expect(inputWrapper.defaultChecked).toBeTruthy();
    });
    it('should handle change event without updating state', function () {
      var onChange = jest.fn();

      var _render6 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
        checked: true,
        onChange: onChange
      })),
          container = _render6.container;

      var input = container.querySelector('input');

      _react2.fireEvent.click(input);

      expect(onChange).toBeCalledWith(false);
      expect(input === null || input === void 0 ? void 0 : input.value).toEqual('on');
    });
    it('should handle change event and update state if props.checked is not existed', function () {
      var _container$querySelec;

      var onChange = jest.fn();

      var _render7 = (0, _react2.render)( /*#__PURE__*/_react.default.createElement(_index.default, {
        onChange: onChange
      })),
          container = _render7.container;

      expect((_container$querySelec = container.querySelector('input')) === null || _container$querySelec === void 0 ? void 0 : _container$querySelec.value).toEqual('off');
      var input = container.querySelector('input');

      _react2.fireEvent.click(input);

      expect(onChange).toBeCalledWith(true);
    });
  });
});