"use strict";

require("@testing-library/jest-dom");
var _react = require("@testing-library/react");
var _userEvent = _interopRequireDefault(require("@testing-library/user-event"));
var _RadioItem = _interopRequireDefault(require("../RadioItem"));
var _jsxRuntime = require("react/jsx-runtime");
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
describe('RadioItem', function () {
  test('should support adding text as children', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      children: "Hello RadioItem"
    }));
    var textField = _react.screen.getByRole('checkbox').lastElementChild;
    var expected = 'Hello RadioItem';
    expect(textField).toHaveTextContent(expected);
  });
  test('should render correct icon when not selected', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      children: "Hello RadioItem"
    }));
    var expected = 983071; // decimal converted charCode of Unicode 'circle' character used by agate
    var actual = _react.screen.getByRole('checkbox').firstElementChild.textContent.codePointAt();
    expect(actual).toBe(expected);
  });
  test('should render correct icon when selected', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      selected: true,
      children: "Hello RadioItem"
    }));
    var expected = 983071; // decimal converted charCode of Unicode 'circle' character used by agate
    var actual = _react.screen.getByRole('checkbox').firstElementChild.textContent.codePointAt();
    expect(actual).toBe(expected);
  });
  test('should support custom icon', function () {
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      icon: "check",
      children: "Hello RadioItem"
    }));
    var checkbox = _react.screen.getByRole('checkbox').firstElementChild;
    var expected = '✓';
    expect(checkbox).toHaveTextContent(expected);
  });
  test('should toggle selected prop when clicked', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleToggle = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      onToggle: handleToggle,
      children: "Hello RadioItem"
    }));
    var checkbox = _react.screen.getByRole('checkbox').firstElementChild;
    yield user.click(checkbox);
    var expected = true;
    var actual = handleToggle.mock.calls[0][0].selected;
    expect(actual).toBe(expected);
  }));
  test('should toggle selected prop to false when initiated as selected', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleToggle = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      onToggle: handleToggle,
      selected: true,
      children: "Hello RadioItem"
    }));
    var checkbox = _react.screen.getByRole('checkbox').firstElementChild;
    yield user.click(checkbox);
    var expected = false;
    var actual = handleToggle.mock.calls[0][0].selected;
    expect(actual).toBe(expected);
  }));
  test('should not toggle selected prop when initiated as disabled', /*#__PURE__*/_asyncToGenerator(function* () {
    var handleToggle = jest.fn();
    var user = _userEvent["default"].setup();
    (0, _react.render)( /*#__PURE__*/(0, _jsxRuntime.jsx)(_RadioItem["default"], {
      disabled: true,
      onToggle: handleToggle,
      children: "Hello RadioItem"
    }));
    var checkbox = _react.screen.getByRole('checkbox').firstElementChild;
    yield user.click(checkbox);
    expect(handleToggle).not.toHaveBeenCalled();
  }));
});