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 StatsAd from "../../components/Ads/StatsAd";

describe("StatsAd render tests", () => {
  var props = {
    className: "some class",
    count: 2,
    title: ".NET",
    minimumExperience: 1,
    createdAt: "20.12.2023",
    expiredAt: "28.12.2023",
    onShowAdDetails: jest.fn(),
  };
  const cont = (
    <redux.Provider store={store}>
      <Router history={history}>
        <StatsAd {...props} />
      </Router>
    </redux.Provider>
  );

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

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

  it("Should render title", () => {
    const { container } = render(cont);
    expect(
      container.getElementsByClassName("archive-ad-title")[0]
    ).toBeDefined();
  });

  it("Should render date", () => {
    const { container } = render(cont);
    expect(
      container.getElementsByClassName("archive-ad-date")[0]
    ).toBeDefined();
  });

  it("Should render that experience is required because minimumExperience is greater than 0", () => {
    const { container } = render(cont);
    expect(
      container
        .getElementsByClassName("archive-ad-experience")[0]
        .getElementsByTagName("p")[0].textContent
    ).toBe("1+ common.experience");
  });
});
