Skip to content

Commit aa4e1eb

Browse files
committed
Fix conflict
2 parents 43a9c9c + 0c89965 commit aa4e1eb

File tree

19 files changed

+239
-83
lines changed

19 files changed

+239
-83
lines changed

frontend/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ const config: Config = {
142142
// setupFiles: [],
143143

144144
// A list of paths to modules that run some code to configure or set up the testing framework before each test
145-
// setupFilesAfterEnv: [],
145+
setupFilesAfterEnv: ["<rootDir>/setupTest.ts"],
146146

147147
// The number of seconds after which a test is considered as slow and reported as such in the results.
148148
// slowTestThreshold: 5,

frontend/setupTest.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import "@testing-library/jest-dom";

frontend/src/App.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import LogIn from "./pages/LogIn";
1313
import Matched from "./pages/Matched";
1414
import Timeout from "./pages/Timeout";
1515
import ProtectedRoutes from "./components/ProtectedRoutes";
16+
import Matching from "./pages/Matching";
1617
import Layout from "./components/Layout";
1718
import AuthProvider from "./contexts/AuthContext";
1819
import ProfileContextProvider from "./contexts/ProfileContext";
@@ -43,14 +44,14 @@ function App() {
4344
}
4445
/>
4546
<Route path="matching" element={<ProtectedRoutes />}>
46-
<Route index element={<div>Matching...</div>} />
47+
<Route index element={<Matching />} />
4748
<Route path="matched" element={<Matched />} />
4849
<Route path="timeout" element={<Timeout />} />
4950
</Route>
5051
<Route path="*" element={<PageNotFound />} />
5152
</Route>
52-
<Route path="/signup" element={<SignUp />}></Route>
53-
<Route path="/login" element={<LogIn />}></Route>
53+
<Route path="signup" element={<SignUp />} />
54+
<Route path="login" element={<LogIn />} />
5455
</Routes>
5556
</AuthProvider>
5657
);

frontend/src/assets/matching.svg

Lines changed: 9 additions & 0 deletions
Loading

frontend/src/components/Navbar/Navbar.test.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { fireEvent, render, screen } from "@testing-library/react";
2-
import "@testing-library/jest-dom";
32
import axios from "axios";
43
import { faker } from "@faker-js/faker";
54
import * as hooks from "../../contexts/AuthContext";
@@ -46,6 +45,7 @@ describe("Navigation routes", () => {
4645
signup: jest.fn(),
4746
login: jest.fn(),
4847
logout: jest.fn(),
48+
setUser: jest.fn(),
4949
loading: false,
5050
user: {
5151
id: "1",
@@ -76,6 +76,7 @@ describe("Unauthenticated user", () => {
7676
login: jest.fn(),
7777
logout: jest.fn(),
7878
loading: false,
79+
setUser: jest.fn(),
7980
user: null,
8081
}));
8182
render(
@@ -92,6 +93,7 @@ describe("Unauthenticated user", () => {
9293
signup: jest.fn(),
9394
login: jest.fn(),
9495
logout: jest.fn(),
96+
setUser: jest.fn(),
9597
loading: false,
9698
user: null,
9799
}));
@@ -133,6 +135,7 @@ describe("Authenticated user", () => {
133135
signup: jest.fn(),
134136
login: jest.fn(),
135137
logout: jest.fn(),
138+
setUser: jest.fn(),
136139
loading: false,
137140
user: {
138141
id: "1",
@@ -182,6 +185,7 @@ describe("Authenticated user", () => {
182185
signup: jest.fn(),
183186
login: jest.fn(),
184187
logout: jest.fn(),
188+
setUser: jest.fn(),
185189
loading: false,
186190
user: {
187191
id: "1",
@@ -235,6 +239,7 @@ describe("Authenticated user", () => {
235239
signup: jest.fn(),
236240
login: jest.fn(),
237241
logout: jest.fn(),
242+
setUser: jest.fn(),
238243
loading: false,
239244
user: {
240245
id: "1",
@@ -287,6 +292,7 @@ describe("Authenticated user", () => {
287292
login: jest.fn(),
288293
logout: jest.fn(),
289294
loading: false,
295+
setUser: jest.fn(),
290296
user: {
291297
id: "1",
292298
username,

frontend/src/components/Navbar/index.tsx

Lines changed: 63 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import { useNavigate, useLocation } from "react-router-dom";
1818
import { useAuth } from "../../contexts/AuthContext";
1919
import { useState } from "react";
2020
import { USE_AUTH_ERROR_MESSAGE } from "../../utils/constants";
21+
import { isMatchingPage } from "../../utils/url";
2122

2223
type NavbarItem = { label: string; link: string; needsLogin: boolean };
2324

@@ -62,63 +63,76 @@ const Navbar: React.FC<NavbarProps> = (props) => {
6263
}}
6364
>
6465
<AppMargin>
65-
<Toolbar sx={{ padding: 0 }}>
66+
<Toolbar sx={{ padding: 0, justifyContent: "space-between" }}>
6667
<Typography
6768
component={Box}
6869
variant="h5"
69-
sx={[{ flexGrow: 1, "&:hover": { cursor: "pointer" } }]}
70+
sx={{ "&:hover": { cursor: "pointer" } }}
7071
onClick={() => navigate("/")}
7172
>
7273
PeerPrep
7374
</Typography>
74-
<Stack direction={"row"} alignItems={"center"} spacing={2}>
75-
{navbarItems
76-
.filter((item) => !item.needsLogin || (item.needsLogin && user))
77-
.map((item) => (
78-
<Link
79-
key={item.label}
80-
href={item.link}
81-
underline="none"
82-
sx={{ color: "common.black" }}
83-
>
84-
{path == item.link ? <b>{item.label}</b> : item.label}
85-
</Link>
86-
))}
87-
{user ? (
88-
<>
89-
<Tooltip title={"Account settings"}>
90-
<IconButton onClick={handleClick} data-testid="profile">
91-
<Avatar src={user.profilePictureUrl}/>
92-
</IconButton>
93-
</Tooltip>
94-
<Menu
95-
anchorEl={anchorEl}
96-
open={!!anchorEl}
97-
onClose={handleClose}
98-
onClick={handleClose}
99-
>
100-
<MenuItem
101-
onClick={() => {
102-
handleClose();
103-
navigate(`/profile/${user.id}`);
104-
}}
75+
{!isMatchingPage(path) ? (
76+
<Stack direction={"row"} alignItems={"center"} spacing={2}>
77+
{navbarItems
78+
.filter((item) => !item.needsLogin || (item.needsLogin && user))
79+
.map((item) => (
80+
<Link
81+
key={item.label}
82+
href={item.link}
83+
underline="none"
84+
sx={{ color: "common.black" }}
10585
>
106-
Profile
107-
</MenuItem>
108-
<MenuItem onClick={logout}>Logout</MenuItem>
109-
</Menu>
110-
</>
111-
) : (
112-
<>
113-
<Button variant="contained" onClick={() => navigate("/signup")}>
114-
Sign up
115-
</Button>
116-
<Button variant="outlined" onClick={() => navigate("/login")}>
117-
Log in
118-
</Button>
119-
</>
120-
)}
121-
</Stack>
86+
{path == item.link ? <b>{item.label}</b> : item.label}
87+
</Link>
88+
))}
89+
{user ? (
90+
<>
91+
<Tooltip title={"Account settings"}>
92+
<IconButton onClick={handleClick} data-testid="profile">
93+
<Avatar src={user.profilePictureUrl} />
94+
</IconButton>
95+
</Tooltip>
96+
<Menu
97+
anchorEl={anchorEl}
98+
open={!!anchorEl}
99+
onClose={handleClose}
100+
onClick={handleClose}
101+
>
102+
<MenuItem
103+
onClick={() => {
104+
handleClose();
105+
navigate(`/profile/${user.id}`);
106+
}}
107+
>
108+
Profile
109+
</MenuItem>
110+
<MenuItem onClick={logout}>Logout</MenuItem>
111+
</Menu>
112+
</>
113+
) : (
114+
<>
115+
<Button
116+
variant="contained"
117+
onClick={() => navigate("/signup")}
118+
>
119+
Sign up
120+
</Button>
121+
<Button variant="outlined" onClick={() => navigate("/login")}>
122+
Log in
123+
</Button>
124+
</>
125+
)}
126+
</Stack>
127+
) : (
128+
<Button
129+
variant="outlined"
130+
color="error"
131+
onClick={() => navigate("/home")}
132+
>
133+
Stop matching
134+
</Button>
135+
)}
122136
</Toolbar>
123137
</AppMargin>
124138
</AppBar>

frontend/src/components/ProfileDetails/ProfileDetailstest.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render, screen } from "@testing-library/react";
2-
import "@testing-library/jest-dom";
32
import { faker } from "@faker-js/faker";
43

54
import ProfileDetails from ".";

frontend/src/components/QuestionCategoryAutoComplete/QuestionCategoryAutoComplete.test.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
2-
import "@testing-library/jest-dom";
32
import QuestionCategoryAutoComplete from ".";
43

54
jest.mock("../../utils/api", () => ({

frontend/src/components/QuestionDetail/QuestionDetail.test.tsx

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { render, screen } from "@testing-library/react";
2-
import "@testing-library/jest-dom";
32
import QuestionDetail from ".";
43

54
jest.mock("@uiw/react-md-editor", () => ({
@@ -25,7 +24,7 @@ describe("Question details", () => {
2524
complexity={complexity}
2625
categories={categories}
2726
description={description}
28-
/>,
27+
/>
2928
);
3029
expect(screen.getByText(title)).toBeInTheDocument();
3130
});
@@ -41,7 +40,7 @@ describe("Question details", () => {
4140
complexity={complexity}
4241
categories={categories}
4342
description={description}
44-
/>,
43+
/>
4544
);
4645
expect(screen.getByText(complexity)).toBeInTheDocument();
4746
});
@@ -57,7 +56,7 @@ describe("Question details", () => {
5756
complexity={complexity}
5857
categories={categories}
5958
description={description}
60-
/>,
59+
/>
6160
);
6261
expect(screen.getByText(categories[0])).toBeInTheDocument();
6362
expect(screen.getByText(categories[1])).toBeInTheDocument();

frontend/src/components/QuestionImage/QuestionImage.test.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import { fireEvent, render, screen } from "@testing-library/react";
2-
import "@testing-library/jest-dom";
32
import QuestionImage from ".";
43

54
Object.assign(navigator, {
@@ -27,7 +26,7 @@ describe("Question Image", () => {
2726
fireEvent.click(copyButton);
2827

2928
expect(navigator.clipboard.writeText).toHaveBeenCalledWith(
30-
`![image](${url})`,
29+
`![image](${url})`
3130
);
3231
});
3332

0 commit comments

Comments
 (0)