import React from 'react';
import { render, fireEvent } from '@testing-library/react';
import Switch from '../index';
describe('Switch', function () {
  afterEach(function () {
    jest.restoreAllMocks();
  });
  describe('snapshot', function () {
    it('renders correctly', function () {
      var _render = render( /*#__PURE__*/React.createElement(Switch, null)),
          container = _render.container;

      expect(container).toMatchSnapshot();
    });
    it('defaultChecked', function () {
      var _render2 = render( /*#__PURE__*/React.createElement(Switch, {
        defaultChecked: true
      })),
          container = _render2.container;

      expect(container).toMatchSnapshot();
    });
  });
  describe('behaviour', function () {
    it('should switch on if defaultChecked is true', function () {
      var _render3 = render( /*#__PURE__*/React.createElement(Switch, {
        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 = render( /*#__PURE__*/React.createElement(Switch, {
        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 = render( /*#__PURE__*/React.createElement(Switch, {
        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 = render( /*#__PURE__*/React.createElement(Switch, {
        checked: true,
        onChange: onChange
      })),
          container = _render6.container;

      var input = container.querySelector('input');
      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 = render( /*#__PURE__*/React.createElement(Switch, {
        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');
      fireEvent.click(input);
      expect(onChange).toBeCalledWith(true);
    });
  });
});