jest.mock("../../Contexts/ManifestsContext");
jest.mock("../../Contexts/UserContext");

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

import { ManifestsProvider } from "../../Contexts/ManifestsContext";
import { UserProvider, setToken } from "../../Contexts/UserContext";
import { StatusProvider } from "../../Contexts/StatusContext";
import ManifestDetails from ".";
import { TEST_AUTH_OBJECT_FISKER } from "../../../utils/testing";
import addSnapshotSerializer from "../../../utils/snapshot";

const TestComponent = (opened) => (
  <UserProvider>
    <BrowserRouter>
      <StatusProvider>
        <ManifestsProvider>
          <ManifestDetails opened={opened} />
        </ManifestsProvider>
      </StatusProvider>
    </BrowserRouter>
  </UserProvider>
);

describe("Manifest Details Component", () => {
  beforeAll(() => {
    setToken(TEST_AUTH_OBJECT_FISKER);
    addSnapshotSerializer(expect);
  });

  it("Render Hidden", async () => {
    const rendered = render(TestComponent(false));
    await waitFor(() => {
      // pause for render
    });
    expect(rendered).toMatchSnapshot();
  });

  it("Render Shown", async () => {
    const rendered = render(TestComponent(true));
    await waitFor(() => {
      // pause for render
    });
    expect(rendered).toMatchSnapshot();
  });
});
