import React from "react";
import "@testing-library/jest-dom/extend-expect";
import { render } from "@testing-library/react";
import Pagination from "../pagination";

test("shows disabled state if current page is first", () => {
  const item1 = render(<Pagination itemCount={50} currentPageIndex={0} />);
  expect(item1.queryByTestId("honeyui-pagination-item-0")).toHaveClass("active");
  item1.unmount();

  const item2 = render(<Pagination itemCount={50} currentPageIndex={1} />);
  expect(item2.queryByTestId("honeyui-pagination-item-0")).not.toHaveClass("active");
  item2.unmount();
});

test("shows disabled state if current page is first", () => {
  const item1 = render(<Pagination itemCount={50} currentPageIndex={0} />);
  expect(item1.queryByTestId("honeyui-pagination-item-back")).toHaveClass("disabled");
  item1.unmount();

  const item2 = render(<Pagination itemCount={50} currentPageIndex={1} />);
  expect(item2.queryByTestId("honeyui-pagination-item-back")).not.toHaveClass("disabled");
  item2.unmount();
});

test("shows disabled state if current page is last", () => {
  const item1 = render(<Pagination itemCount={50} currentPageIndex={0} />);
  expect(item1.queryByTestId("honeyui-pagination-item-forward")).not.toHaveClass("disabled");
  item1.unmount();

  const item2 = render(<Pagination itemCount={50} currentPageIndex={3} />);
  expect(item2.queryByTestId("honeyui-pagination-item-forward")).toHaveClass("disabled");
  item2.unmount();
});

test("shows disabled state", () => {
  const item1 = render(<Pagination itemCount={50} disabled={false} currentPageIndex={1} />);
  expect(item1.queryByTestId("honeyui-pagination-item-back")).not.toHaveClass("disabled");
  expect(item1.queryByTestId("honeyui-pagination-item-forward")).not.toHaveClass("disabled");
  item1.unmount();

  const item2 = render(<Pagination itemCount={50} disabled={true} currentPageIndex={1} />);
  expect(item2.queryByTestId("honeyui-pagination-item-back")).toHaveClass("disabled");
  expect(item2.queryByTestId("honeyui-pagination-item-forward")).toHaveClass("disabled");
  item2.unmount();
});
