jest.mock("../../../Contexts/FleetContext");
jest.mock("../../../Contexts/StatusContext");
jest.mock("../../../Contexts/UserContext");

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 MainForm from "./index";
import addSnapshotSerializer from "../../../../utils/snapshot";

const renderFleetDetailsTab = async () => {
  const { container } = render(
    <FleetProvider>
      <StatusProvider>
        <UserProvider>
          <BrowserRouter>
            <MainForm name="Test Fleet"/>
          </BrowserRouter>
        </UserProvider>
      </StatusProvider>
    </FleetProvider>
  );
  await waitFor(() => {
    /* render */
  });
  return container;
};

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

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

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