"use strict";

var _react = _interopRequireWildcard(require("react"));
var _testUtilities = require("testUtilities");
var _ = require(".");
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, "default": e }; if (null === e || "object" != typeof e && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); } /**
 * @jest-environment jsdom
 */
var MockedToggle = function MockedToggle(props) {
  var _useState = (0, _react.useState)(false),
    checked = _useState[0],
    setChecked = _useState[1];
  var handleChange = function handleChange(e) {
    setChecked(e.currentTarget.checked);
  };
  return /*#__PURE__*/_react["default"].createElement(_.Toggle, _extends({
    onChange: handleChange,
    checked: checked
  }, props));
};
describe("Toggle test", function () {
  it(" * should render with required props", function () {
    var _renderWithProviders = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(MockedToggle, null)),
      container = _renderWithProviders.container,
      getByRole = _renderWithProviders.getByRole;
    var checkbox = container.querySelectorAll("input")[0];
    expect(checkbox).toBeInTheDocument();
    var toggle = getByRole("switch");
    expect(toggle).toHaveStyleRule("background", "#F6F7F7");
    expect(toggle).toHaveStyleRule("background-color", "#35414A", {
      modifier: ":after"
    });
    expect(container).toMatchSnapshot();
  });
  it(" * should render with labels", function () {
    var _renderWithProviders2 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(MockedToggle, {
        labelRight: "Light theme",
        labelLeft: "Dark theme"
      })),
      container = _renderWithProviders2.container,
      getByText = _renderWithProviders2.getByText;
    expect(getByText(/Light theme/)).toBeInTheDocument();
    expect(getByText(/Dark theme/)).toBeInTheDocument();
    expect(container).toMatchSnapshot();
  });
  it(" * should be disabled", function () {
    var _renderWithProviders3 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(MockedToggle, {
        disabled: true
      })),
      container = _renderWithProviders3.container,
      getByRole = _renderWithProviders3.getByRole;
    var checkbox = container.querySelectorAll("input")[0];
    expect(checkbox).toBeDisabled();
    var toggle = getByRole("switch");
    expect(toggle).toHaveStyleRule("background-color", "#35414A", {
      modifier: ":after"
    });
  });
  it(" * should be colored", function () {
    var _renderWithProviders4 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(MockedToggle, {
        colored: true
      })),
      container = _renderWithProviders4.container,
      getByRole = _renderWithProviders4.getByRole;
    var toggle = getByRole("switch");
    expect(toggle).toHaveStyleRule("background-color", "#DB162F", {
      modifier: ":after"
    });
    var checkbox = container.querySelectorAll("input")[0];
    _testUtilities.fireEvent.click(checkbox);
    expect(toggle).toHaveStyleRule("background-color", "#00AB44", {
      modifier: ":after"
    });
  });
  it(" * should check the checkbox on interaction", function () {
    var _renderWithProviders5 = (0, _testUtilities.renderWithProviders)(/*#__PURE__*/_react["default"].createElement(MockedToggle, null)),
      container = _renderWithProviders5.container;
    var checkbox = container.querySelectorAll("input")[0];
    _testUtilities.fireEvent.click(checkbox);
    expect(checkbox.checked).toBe(true);
    _testUtilities.fireEvent.click(checkbox);
    expect(checkbox.checked).toBe(false);
  });
});