Skip to content

Commit

Permalink
update sidebar tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sri240 committed Oct 21, 2023
1 parent b3c45ab commit 6d38203
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 5 deletions.
66 changes: 64 additions & 2 deletions frontend2/src/components/sidebar/__test__/Sidebar.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,60 @@ 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: "[email protected]",
first_name: "the",
last_name: "user",
is_staff: false,
};

test("UI: should collapse sidebar", () => {
render(
<MemoryRouter>
<EpisodeIdContext.Provider
value={{ episodeId: "something", setEpisodeId: (_) => undefined }}
>
<Sidebar collapsed={true} />
<CurrentTeamContext.Provider
value={{ teamState: TeamStateEnum.IN_TEAM, team: faketeam }}
>
<CurrentUserContext.Provider
value={{
authState: "loading",
user: fakeuser,
login: (_) => {
console.log();
},
logout: () => {
console.log();
},
}}
>
<Sidebar collapsed={true} />
</CurrentUserContext.Provider>
</CurrentTeamContext.Provider>
</EpisodeIdContext.Provider>
</MemoryRouter>,
);
Expand All @@ -23,7 +68,24 @@ test("UI: should link to episode in surrounding context", () => {
<EpisodeIdContext.Provider
value={{ episodeId: "something", setEpisodeId: (_) => undefined }}
>
<Sidebar />
<CurrentTeamContext.Provider
value={{ teamState: TeamStateEnum.IN_TEAM, team: faketeam }}
>
<CurrentUserContext.Provider
value={{
authState: "loading",
user: fakeuser,
login: (_) => {
console.log();
},
logout: () => {
console.log();
},
}}
>
<Sidebar />
</CurrentUserContext.Provider>
</CurrentTeamContext.Provider>
</EpisodeIdContext.Provider>
</MemoryRouter>,
);
Expand Down
5 changes: 2 additions & 3 deletions frontend2/src/components/sidebar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import SidebarItem from "./SidebarItem";
import { useEpisodeId } from "../../contexts/EpisodeContext";
import { type IconName } from "../elements/Icon";
import { useCurrentUser } from "../../contexts/CurrentUserContext";
import { isNull } from "lodash";
import { useCurrentTeam } from "../../contexts/CurrentTeamContext";

interface SidebarProps {
Expand Down Expand Up @@ -98,8 +97,8 @@ const Sidebar: React.FC<SidebarProps> = ({ collapsed }) => {
let teamManage;

// construct teamManage if needed
if (!isNull(user) && user !== undefined) {
if (!isNull(team) && team !== undefined) {
if (user !== undefined) {
if (team !== undefined) {
teamManage = (
<SidebarSection title="team management">
{generateSidebarItems(6, 8, episodeId)}
Expand Down

0 comments on commit 6d38203

Please sign in to comment.