jest.mock("../../Contexts/FleetContext");
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 { BrowserRouter } from "react-router-dom";
import routeData from "react-router";

import { FleetProvider } from "../../Contexts/FleetContext";
import { StatusProvider } from "../../Contexts/StatusContext";
import { UserProvider, setToken } from "../../Contexts/UserContext";
import { TEST_AUTH_OBJECT_FISKER } from "../../../utils/testing";
import FleetStatus from "./index";
import addSnapshotSerializer from "../../../utils/snapshot";

const renderCarStatus = async () => {
  const { container } = render(
    <FleetProvider>
      <StatusProvider>
        <UserProvider>
          <BrowserRouter>
            <FleetStatus />
          </BrowserRouter>
        </UserProvider>
      </StatusProvider>
    </FleetProvider>
  );
  await waitFor(() => {
    /* render */
  });
  return container;
};

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

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

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