/**
 * @jest-environment jsdom
 */

import React, { useState } from "react";
import { renderWithProviders, fireEvent } from "testUtilities";
import { Tabs, Tab } from ".";
describe("Tabs states", function () {
  it(" * should render uncontrolled", function () {
    var _renderWithProviders = renderWithProviders(/*#__PURE__*/React.createElement(Tabs, null, /*#__PURE__*/React.createElement(Tab, {
        label: "hi"
      }, "Hello"), /*#__PURE__*/React.createElement(Tab, {
        label: "Hi again"
      }, "Hello again"), /*#__PURE__*/React.createElement(Tab, {
        label: "Bye"
      }, "Goodbye"), /*#__PURE__*/React.createElement(Tab, {
        label: "Bye Bye"
      }, "Fairwell"))),
      container = _renderWithProviders.container,
      getByText = _renderWithProviders.getByText,
      queryByText = _renderWithProviders.queryByText;
    var tabs = container.firstChild;
    expect(tabs).toMatchSnapshot();
    expect(getByText("hi")).toHaveStyleRule("font-weight", "bold");
    expect(queryByText("Hello")).toBeInTheDocument();
    expect(queryByText("Hello again")).not.toBeInTheDocument();
    expect(queryByText("Goodbye")).not.toBeInTheDocument();
    expect(queryByText("Fairwell")).not.toBeInTheDocument();
    var tab = getByText("Bye Bye");
    fireEvent.click(tab);
    expect(tab).toHaveStyleRule("font-weight", "bold");
    expect(queryByText("Hello")).not.toBeInTheDocument();
    expect(queryByText("Fairwell")).toBeInTheDocument();
  });
  it(" * should render controlled", function () {
    var onChange = jest.fn();
    var Component = function Component() {
      var _useState = useState(2),
        selected = _useState[0],
        setSelected = _useState[1];
      return /*#__PURE__*/React.createElement(Tabs, {
        selected: selected,
        onChange: onChange.mockImplementation(function (index) {
          return setSelected(index);
        })
      }, /*#__PURE__*/React.createElement(Tab, {
        label: "hi"
      }, "Hello"), /*#__PURE__*/React.createElement(Tab, {
        label: "Hi again"
      }, "Hello again"), /*#__PURE__*/React.createElement(Tab, {
        label: "Bye"
      }, "Goodbye"), /*#__PURE__*/React.createElement(Tab, {
        label: "Bye Bye"
      }, "Fairwell"));
    };
    var _renderWithProviders2 = renderWithProviders(/*#__PURE__*/React.createElement(Component, null)),
      queryByText = _renderWithProviders2.queryByText,
      getByText = _renderWithProviders2.getByText;
    expect(queryByText("Hello")).not.toBeInTheDocument();
    expect(queryByText("Hello again")).not.toBeInTheDocument();
    expect(getByText("Bye")).toHaveStyleRule("font-weight", "bold");
    expect(queryByText("Goodbye")).toBeInTheDocument();
    expect(queryByText("Fairwell")).not.toBeInTheDocument();
    var tab = getByText("Hi again");
    fireEvent.click(tab);
    expect(tab).toHaveStyleRule("font-weight", "bold");
    expect(onChange).toBeCalledWith(1);
    expect(queryByText("Goodbye")).not.toBeInTheDocument();
    expect(queryByText("Hello again")).toBeInTheDocument();
  });
  it(" * should not allow disabled to be selected", function () {
    var Component = function Component() {
      return /*#__PURE__*/React.createElement(Tabs, null, /*#__PURE__*/React.createElement(Tab, {
        label: "hi",
        disabled: true
      }, "Hello"), /*#__PURE__*/React.createElement(Tab, {
        label: "Hi again"
      }, "Hello again"), /*#__PURE__*/React.createElement(Tab, {
        label: "Bye"
      }, "Goodbye"), /*#__PURE__*/React.createElement(Tab, {
        label: "Bye Bye"
      }, "Fairwell"));
    };
    var _renderWithProviders3 = renderWithProviders(/*#__PURE__*/React.createElement(Component, null)),
      queryByText = _renderWithProviders3.queryByText,
      getByText = _renderWithProviders3.getByText;
    expect(queryByText("Hello")).not.toBeInTheDocument();
    expect(getByText("Hi again")).toHaveStyleRule("font-weight", "bold");
    expect(queryByText("Hello again")).toBeInTheDocument();
    var tab = getByText("hi");
    fireEvent.click(tab);
    expect(tab).toHaveStyleRule("font-weight", "normal");
    expect(queryByText("Hello")).not.toBeInTheDocument();
    expect(queryByText("Hello again")).toBeInTheDocument();
  });
});