jest.mock("../Contexts/UserContext");
jest.mock("../../services/superset");

import { render, screen, waitFor } from "@testing-library/react";
import { BrowserRouter } from "react-router-dom";
import addSnapshotSerializer from "../../utils/snapshot";
import { TEST_AUTH_OBJECT_FISKER, TEST_AUTH_OBJECT_MAGNA } from "../../utils/testing";
import { setToken, UserProvider } from "../Contexts/UserContext";
import SideMenu from "./SideMenu";

const renderMenu = async () => {
  const { container } = render(
    <UserProvider>
      <BrowserRouter>
        <SideMenu />
      </BrowserRouter>
    </UserProvider>
  );
  await waitFor(() => {});
  return container;
};

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

  it("Unauthenticated", async () => {
    setToken({ idToken: { jwtToken: null } });
    const container = await renderMenu();
    expect(container).toMatchSnapshot();
  });

  it("Authenticated", async () => {
    setToken(TEST_AUTH_OBJECT_FISKER);
    const container = await renderMenu();
    await waitFor(() => {
      expect(screen.getByText("Datascope")).toBeInTheDocument();
    });
    expect(container).toMatchSnapshot();
  });

  it("Magna Authenticated", async () => {
    setToken(TEST_AUTH_OBJECT_MAGNA);
    const container = await renderMenu();
    await waitFor(() => {
      expect(screen.getByText("Tools")).toBeInTheDocument();
    });
    expect(container).toMatchSnapshot();
  });
});
