import { fireEvent, render, screen } from "@testing-library/react";
import * as redux from "react-redux";
import SelectionProcessPage from "../../pages/selectionProcessPage/selectionProcessPage"
import store from "../../store";
import "../../i18n";
import { mockState } from "../../mockState";
import { Router } from "react-router-dom";
import history from "../../store/utils/history";

describe("SelectionProcessPage render tests", () => {
  const cont = (
    <redux.Provider store={store}>
      <Router history={history}>
        <SelectionProcessPage />
      </Router>
    </redux.Provider>
  );

  let spyOnUseSelector;

  beforeEach(() => {
    // Mock useSelector hook
    spyOnUseSelector = jest.spyOn(redux, "useSelector");
    spyOnUseSelector.mockReturnValueOnce(mockState.selections).mockReturnValueOnce(mockState.selections.processes).mockReturnValueOnce(mockState.selections.statuses);
    // spyOnUseSelector.mockReturnValue(mockState.selections);

  });

  afterEach(() => {
    jest.restoreAllMocks();
  });

  it("Should render", () => {
    render(cont);
    expect(screen.getByTestId("selections-page")).toBeDefined();
  });

  it("Should render a card foreach mocked level", () => {
    const { container } = render(cont);
    expect(container.getElementsByClassName("selection-card").length).toBe(4);
  });

  it("Should render a button with specific class for an enabled user", () => {
    const { container } = render(cont);
    expect(container.getElementsByClassName("td-btn").length).toBe(0);
  });

  it("Should render filter buttonn", () => {
    const { container } = render(cont);
    expect(container.getElementsByClassName("userPageBtn").length).toBe(1);
  });

  it("Drag and drop", () => {
    const { container } = render(cont);
    fireEvent.drop(container.getElementsByClassName("selection-card")[0], {
      dataTransfer: {
        getData: (type) => '{"id":32,"name":"random","status":"Kandidat primljen","date":null,"link":"link","applicant":{"applicantId":6,"firstName":"Safet","lastName":"Purkovic","position":"React Developer","dateOfApplication":"2021-05-05T00:00:00","cv":"dasdas","email":"safet@gmail.com","phoneNumber":"2313123","linkedlnLink":"sda","githubLink":null,"bitBucketLink":null,"experience":2,"applicationChannel":null,"typeOfEmployment":"Posao","technologyApplicants":[],"comments":[],"ads":[],"selectionProcesses":[{"status":"Kandidat primljen","date":null,"link":"link","scheduler":{"id":7,"firstName":"Safet","lastName":"Purkovic","email":"safet.purkovic@dilig.net","isEnabled":true},"selectionLevel":{"id":4,"name":"Konacna odluka"}}]},"selectionLevelId":4}'
      },
    })
  });
})