import * as redux from "react-redux";
import store from "../../store";
import { Router } from "react-router-dom";
import { mockState } from "../../mockState";
import { render, screen, fireEvent } from "@testing-library/react";
import history from "../../store/utils/history";
import DayDetailsComponent from "../../components/Schedules/DayDetailsComponent";
import ColorModeProvider from "../../context/ColorModeContext";

const props = {
  selectedDate: "20.12.2023",
  selectionProcesses: mockState.schedule.schedule,
  open: jest.fn(),
  onClose: jest.fn(),
  setCurrentlySelected: jest.fn(),
  setCurrentlySelectedDay: jest.fn(),
  currentlySelectedDay: 1,
  numberOfDaysInMonth: 31,
  history: {
    replace: jest.fn(),
    push: jest.fn(),
    location: {
      pathname: "/schedule",
    },
  },
};

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

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

  it("Should render", () => {
    render(cont);
    expect(screen.getByTestId("day-component-dialog")).toBeDefined();
  });

  it("Should render left arrow as disabled because we set that currenlty selected day is first day of month", () => {
    render(cont);
    expect(screen.getAllByTestId("day-details-left-arrow")[0]).toBeDefined();
  });

  it("Should render right arrow as enabled because we set that currenlty selected day is first day of month", () => {
    render(cont);
    expect(screen.getAllByTestId("day-details-right-arrow")[0]).toBeDefined();
  });

  it("Should show all interviews which we pass to component", () => {
    render(cont);
    expect(screen.getAllByTestId("day-details-component-process").length).toBe(
      mockState.schedule.schedule.length
    );
  });

  it("Should render candidate details page after clicking on candidate name", () => {
    render(cont);
    fireEvent.click(screen.getAllByTestId("day-details-applicant")[0]);
    const arg = { pathname: "/candidates/1" };
    expect(props.history.push).toHaveBeenCalledWith(arg);
  });
});
