Skip to content

Commit

Permalink
test(frontend): fix tests #21
Browse files Browse the repository at this point in the history
  • Loading branch information
alexstojda committed Jul 24, 2023
1 parent 1f655df commit 070b5a0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 5 deletions.
6 changes: 2 additions & 4 deletions web/app/src/layouts/auth/index.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {PropsWithChildren} from "react";
import {Avatar, Box, Flex, Heading, Stack} from "@chakra-ui/react";
import ColorToggle from "../../components/ColorToggle";
import Alert, {AlertData} from "../../components/Alert";
import Footer from "../footer";

type AuthLayoutProps = PropsWithChildren & {
title?: string;
Expand Down Expand Up @@ -41,9 +41,7 @@ export default function AuthLayout(props: AuthLayoutProps) {
{props.children}
</Box>
</Stack>
<Box>
<ColorToggle/>
</Box>
<Footer/>
</Flex>
)
}
15 changes: 15 additions & 0 deletions web/app/src/layouts/footer/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import ColorToggle from "../../components/ColorToggle";
import {Text, HStack, Spacer, Link} from "@chakra-ui/react";

export default function Footer() {
return (
<HStack my={4} >
<Spacer/>
<Text fontSize="sm" color="gray.500">
© {new Date().getFullYear()} - PinMan | <Link href={"https://github.com/alexstojda/pinman"}>GitHub</Link>
</Text>
<ColorToggle/>
<Spacer/>
</HStack>
);
}
2 changes: 2 additions & 0 deletions web/app/src/pages/AuthTest/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {Button} from "@chakra-ui/react";
import {Api, useAuth} from "../../api";
import {useNavigate} from "react-router-dom";
import Footer from "../../layouts/footer";

export default function AuthTest() {
const {user} = useAuth({requireAuth: true});
Expand All @@ -18,6 +19,7 @@ export default function AuthTest() {
}}>
Logout
</Button>
<Footer/>
</>
)
}
6 changes: 5 additions & 1 deletion web/app/src/pages/Leagues/index.test.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {render} from "@testing-library/react";
import React from "react";
import LeaguesPage from "./index";
import {Api, LeaguesApi} from "../../api";
import {Api, LeaguesApi, useAuth} from "../../api";
import {fake} from "../../test";
import {MemoryRouter} from "react-router-dom";

Expand Down Expand Up @@ -87,6 +87,10 @@ describe('LeaguesPage', () => {
expect(error).toBeInTheDocument()
})
it('navigates to create league page when button is pressed', async () => {
jest.mocked(useAuth).mockReturnValue({
user: fake.user()
})

jest.mocked(LeaguesApi).prototype.leaguesGet.mockResolvedValue({
config: {},
data: {
Expand Down
2 changes: 2 additions & 0 deletions web/app/src/pages/Leagues/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {useNavigate} from "react-router-dom";
import {AxiosError} from "axios";
import Alert, {AlertData} from "../../components/Alert";
import LeagueForm from "./Form";
import Footer from "../../layouts/footer";

const api: Api = new Api();

Expand Down Expand Up @@ -120,6 +121,7 @@ export default function LeaguesPage(props: LeagueListPageProps) {
}
</HStack>
{renderList()}
<Footer/>
</Container>
</>
)
Expand Down

0 comments on commit 070b5a0

Please sign in to comment.