jest.mock("../../Contexts/CANFiltersContext");
jest.mock("../../Contexts/StatusContext");
jest.mock("../../Contexts/UserContext");
jest.mock("@material-ui/core/utils/unstable_useId", () =>
  jest.fn().mockReturnValue("mui-test-id")
);

import { render, waitFor } from "@testing-library/react";
import routeData from "react-router";
import { BrowserRouter } from "react-router-dom";

import addSnapshotSerializer from "../../../utils/snapshot";
import { TEST_AUTH_OBJECT_FISKER } from "../../../utils/testing";
import { CANFiltersProvider } from "../../Contexts/CANFiltersContext";
import { StatusProvider } from "../../Contexts/StatusContext";
import { setToken, UserProvider } from "../../Contexts/UserContext";
import CarStatus from "./index";

const renderCarStatus = async () => {
  const { container } = render(
    <CANFiltersProvider>
      <StatusProvider>
        <UserProvider>
          <BrowserRouter>
            <CarStatus vin="TESTVIN1234567890" />
          </BrowserRouter>
        </UserProvider>
      </StatusProvider>
    </CANFiltersProvider>
  );
  await waitFor(() => {
    /* render */
  });
  return container;
};

describe("CarStatus", () => {
  beforeAll(() => {
    addSnapshotSerializer(expect);
  });

  beforeEach(() => {
    // Does not work if placed in beforeAll
    jest.spyOn(routeData, 'useParams').mockReturnValue({ vin: "TESTVIN1234567890" })
  })

  it("Render", async () => {
    setToken(TEST_AUTH_OBJECT_FISKER);
    const container = await renderCarStatus();
    expect(container).toMatchSnapshot();
  });
});
