import * as redux from "react-redux";
import store from "../../store";
import { Router } from "react-router-dom";
import history from "../../store/utils/history";
import { mockState } from "../../mockState";
import { render, screen, fireEvent, waitFor } from "@testing-library/react";
import RegisterPage from "../../pages/RegisterPage/RegisterPage";
import { FormProvider } from "../../context/FormContext";

const token =''
const mail = "";

const mockHistoryPush = jest.fn();

jest.mock("react-router-dom", () => ({
...jest.requireActual("react-router-dom"),
useHistory: () => ({
  push: mockHistoryPush,
}),
useLocation: () => ({
  search: `/register?token=${token}&email=${mail}`,
}),
}));

describe("Register page tests", () => {
  var props = {
    history: {
      replace: jest.fn(),
      push: jest.fn(),
      location: {
        pathname: "",
      },
    },
  };
  const cont = (
    <FormProvider>
      <redux.Provider store={store}>
        <Router history={history}>
          <RegisterPage {...props} />
        </Router>
      </redux.Provider>
    </FormProvider>
  );

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

  it("Should render error message", () => {
    render(cont);
    expect(screen.getByTestId("error-h")).toBeDefined();
  });
});
