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
 */

import React, { useState } from "react";
import { renderWithProviders, fireEvent } from "testUtilities";
import { Toggle } from ".";
var MockedToggle = function MockedToggle(props) {
  var _useState = useState(false),
    checked = _useState[0],
    setChecked = _useState[1];
  var handleChange = function handleChange(e) {
    setChecked(e.currentTarget.checked);
  };
  return /*#__PURE__*/React.createElement(Toggle, _extends({
    onChange: handleChange,
    checked: checked
  }, props));
};
describe("Toggle test", function () {
  it(" * should render with required props", function () {
    var _renderWithProviders = renderWithProviders( /*#__PURE__*/React.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 = renderWithProviders( /*#__PURE__*/React.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 = renderWithProviders( /*#__PURE__*/React.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 = renderWithProviders( /*#__PURE__*/React.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];
    fireEvent.click(checkbox);
    expect(toggle).toHaveStyleRule("background-color", "#00AB44", {
      modifier: ":after"
    });
  });
  it(" * should check the checkbox on interaction", function () {
    var _renderWithProviders5 = renderWithProviders( /*#__PURE__*/React.createElement(MockedToggle, null)),
      container = _renderWithProviders5.container;
    var checkbox = container.querySelectorAll("input")[0];
    fireEvent.click(checkbox);
    expect(checkbox.checked).toBe(true);
    fireEvent.click(checkbox);
    expect(checkbox.checked).toBe(false);
  });
});