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 { MemoryRouter, Route } from "react-router-dom";

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

const renderDetailsTab = async () => {
  const { container } = render(
    <FleetProvider>
      <StatusProvider>
        <UserProvider>
          <MemoryRouter initialEntries={["/testroute/US-TEST"]}>
            <Route path="/testroute/:name">
              <MainForm name="US-TEST" />
            </Route>
          </MemoryRouter>
        </UserProvider>
      </StatusProvider>
    </FleetProvider>
  );
  await waitFor(() => {
    /* render */
  });
  return container;
};

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

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