diff --git a/frontend2/src/components/sidebar/__test__/Sidebar.test.tsx b/frontend2/src/components/sidebar/__test__/Sidebar.test.tsx index 1925573b8..4d93cff1f 100644 --- a/frontend2/src/components/sidebar/__test__/Sidebar.test.tsx +++ b/frontend2/src/components/sidebar/__test__/Sidebar.test.tsx @@ -2,7 +2,35 @@ import React from "react"; import { render, screen } from "@testing-library/react"; import Sidebar from "../"; import { EpisodeIdContext } from "../../../contexts/EpisodeContext"; +import { CurrentUserContext } from "../../../contexts/CurrentUserContext"; +import { + CurrentTeamContext, + TeamStateEnum, +} from "../../../contexts/CurrentTeamContext"; import { MemoryRouter } from "react-router-dom"; +import { Status526Enum } from "../../../utils/types"; + +const mem = { + id: 123, + username: "theuser", + is_staff: false, +}; +const faketeam = { + id: 123, + episode: "bc23", + name: "theteam", + members: [mem], + join_key: "abc", + status: Status526Enum.O, +}; +const fakeuser = { + id: 123, + username: "theuser", + email: "user@gmail.com", + first_name: "the", + last_name: "user", + is_staff: false, +}; test("UI: should collapse sidebar", () => { render( @@ -10,7 +38,24 @@ test("UI: should collapse sidebar", () => { undefined }} > - + + { + console.log(); + }, + logout: () => { + console.log(); + }, + }} + > + + + , ); @@ -23,7 +68,24 @@ test("UI: should link to episode in surrounding context", () => { undefined }} > - + + { + console.log(); + }, + logout: () => { + console.log(); + }, + }} + > + + + , ); diff --git a/frontend2/src/components/sidebar/index.tsx b/frontend2/src/components/sidebar/index.tsx index d2d14c6ca..f2d364b16 100644 --- a/frontend2/src/components/sidebar/index.tsx +++ b/frontend2/src/components/sidebar/index.tsx @@ -3,6 +3,8 @@ import SidebarSection from "./SidebarSection"; import SidebarItem from "./SidebarItem"; import { useEpisodeId } from "../../contexts/EpisodeContext"; import { type IconName } from "../elements/Icon"; +import { useCurrentUser } from "../../contexts/CurrentUserContext"; +import { useCurrentTeam } from "../../contexts/CurrentTeamContext"; interface SidebarProps { collapsed?: boolean; @@ -90,7 +92,28 @@ export const generateSidebarItems = ( const Sidebar: React.FC = ({ collapsed }) => { collapsed = collapsed ?? false; const { episodeId } = useEpisodeId(); + const { user } = useCurrentUser(); + const { team } = useCurrentTeam(); + let teamManage; + // construct teamManage if needed + if (user !== undefined) { + if (team !== undefined) { + teamManage = ( + + {generateSidebarItems(6, 8, episodeId)} + + ); + } else { + teamManage = ( + + {generateSidebarItems(6, 6, episodeId)} + + ); + } + } + + // generate sidebar return collapsed ? null : ( ); };