import { _ as _slicedToArray } from '../../slicedToArray-BB-AwwkK.js';
import React__default, { useState } from 'react';
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import CheckboxField from '../index.js';
import useForm, { Form } from '../../use-form/index.js';
import '../../checkbox/index.js';
import '../../extends-C4cduGrv.js';
import '../../defineProperty-CEd-kZQW.js';
import '../../objectWithoutProperties-TXwlfNxG.js';
import 'prop-types';
import 'classnames';
import '../../index-qSfOyGhk.js';
import '../../typeof-CgC7Bq6K.js';
import '../../auto-id.esm-Cly76abB.js';
import '../../utils.esm-CKyxlHOy.js';
import '../../warning-s9zGJbnw.js';
import '../../_commonjsHelpers-_1FafXWI.js';
import '../../use-progress/index.js';
import '../../use-trailing-debounce/index.js';

var ExampleField = function ExampleField() {
  var _useState = useState(false),
      _useState2 = _slicedToArray(_useState, 2),
      value = _useState2[0],
      setvalue = _useState2[1];

  return /*#__PURE__*/React__default.createElement(CheckboxField, {
    label: "Optimize",
    name: "optimize",
    onChange: function onChange(event) {
      return setvalue(event.target.checked);
    },
    value: value
  });
};

var ExampleFieldInForm = function ExampleFieldInForm() {
  var form = useForm({
    initialData: {
      optimize: false
    }
  });
  return /*#__PURE__*/React__default.createElement(Form, {
    form: form
  }, /*#__PURE__*/React__default.createElement(CheckboxField, {
    label: "Optimize",
    name: "optimize"
  }));
};

describe("CheckboxField", function () {
  test("using outside of a form", function () {
    render( /*#__PURE__*/React__default.createElement(ExampleField, null));
    var input = screen.getByLabelText("Optimize");
    expect(input.checked).toEqual(false);
    userEvent.click(input);
    expect(input.checked).toEqual(true);
  });
  test("using inside of a form", function () {
    render( /*#__PURE__*/React__default.createElement(ExampleFieldInForm, null));
    var input = screen.getByLabelText("Optimize");
    expect(input.checked).toEqual(false);
    userEvent.click(input);
    expect(input.checked).toEqual(true);
  });
});
