jest.mock("../../Contexts/StatusContext");
jest.mock("../../Contexts/UserContext");
jest.mock("../../../services/suppliersAPI");
jest.mock("@material-ui/core/utils/unstable_useId", () =>
  jest.fn().mockReturnValue("mui-test-id")
);
jest.mock("react-router-dom", () => ({
  BrowserRouter: ({ children }) => (
    <div id="mock-browserrouter">{children}</div>
  ),
  useParams: () => ({ email: "test@supplier.com" }),
}));
import { render, waitFor } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom";
import { SupplierProvider } from "../../Contexts/SupplierContext";
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 renderSupplierDetailsPage = async () => {
  const { container } = render(
    <SupplierProvider>
      <StatusProvider>
        <UserProvider>
          <BrowserRouter>
            <MainForm />
          </BrowserRouter>
        </UserProvider>
      </StatusProvider>
    </SupplierProvider>
  );
  await waitFor(() => {
    /* render */
  });
  return container;
};

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

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