import * as redux from "react-redux";
import store from "../../store";
import { Router } from "react-router-dom";
import { render } from "@testing-library/react";
import history from "../../store/utils/history";
import NotFoundPage from "../../pages/ErrorPages/NotFoundPage";

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

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

  it("Should render", () => {
    const { container } = render(cont);
    expect(container.getElementsByClassName("not-found-page")[0]).toBeDefined();
  });

  it("Should render status code 404", () => {
    const { container } = render(cont);
    expect(
      container.getElementsByClassName("c-error-page__title")[0].textContent
    ).toBe("404");
  });

  it("Should render text", () => {
    const { container } = render(cont);
    expect(
      container.getElementsByClassName("c-error-page__text")[0]
    ).toBeDefined();
  });

  it("Should render button for going back to previous page", () => {
    const { container } = render(cont);
    expect(
      container.getElementsByClassName("c-error-page__button")[0]
    ).toBeDefined();
  });
});
