Skip to content

Commit 45383bf

Browse files
authored
Merge pull request #500 from janong24/FrontendTesting
Frontend testing
2 parents 99cb8c1 + 61c8356 commit 45383bf

File tree

62 files changed

+12403
-8932
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+12403
-8932
lines changed

client/app/aboutUs/aboutUs.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import { render } from '@testing-library/react';
2+
import { useRouter } from 'next/router';
3+
import { useAuth } from '../contexts/AuthContext';
4+
import GetAboutUs from './page.tsx';
5+
6+
jest.mock("../contexts/PropContext", () => ({
7+
__esModule: true,
8+
useProp: jest.fn(() => ({
9+
handlePopUp: jest.fn(),
10+
})),
11+
}));
12+
13+
const fakeUser = {
14+
uid: "1"
15+
}
16+
17+
jest.mock('../contexts/AuthContext', () => {
18+
return {
19+
useAuth: () => {
20+
return {
21+
user : fakeUser
22+
}
23+
}
24+
}
25+
});
26+
27+
const mockRouter= jest.fn();
28+
29+
jest.mock("next/navigation", () => ({
30+
useRouter: () => {
31+
return {
32+
push: mockRouter
33+
}
34+
}
35+
}));
36+
37+
jest.mock("../contexts/UserContext", () => {
38+
return {
39+
useUser: () =>{
40+
return {
41+
userInfo: {
42+
uid: '1',
43+
}
44+
}
45+
}
46+
};
47+
});
48+
49+
describe('GetAboutUs', () => {
50+
it('returns GetAboutUsPage component', () => {
51+
const { container } = render(<GetAboutUs />);
52+
53+
expect(container.textContent).toContain('Compass is a medical wellness app');
54+
});
55+
});
Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,73 @@
11
import '@testing-library/jest-dom';
2+
import userEvent from '@testing-library/user-event';
3+
import { useRouter } from 'next/router';
4+
import { useAuth } from '../contexts/AuthContext';
25
import { render, screen } from '@testing-library/react';
6+
import AboutUsPage from './aboutUsPage';
7+
8+
9+
jest.mock("../contexts/PropContext", () => ({
10+
__esModule: true,
11+
useProp: jest.fn(() => ({
12+
handlePopUp: jest.fn(),
13+
})),
14+
}));
15+
16+
const fakeUser = {
17+
uid: "1"
18+
}
19+
20+
jest.mock('../contexts/AuthContext', () => {
21+
return {
22+
useAuth: () => {
23+
return {
24+
user : fakeUser
25+
}
26+
}
27+
}
28+
});
29+
30+
const mockRouter= jest.fn();
31+
32+
jest.mock("next/navigation", () => ({
33+
useRouter: () => {
34+
return {
35+
push: mockRouter
36+
}
37+
}
38+
}));
39+
40+
jest.mock("../contexts/UserContext", () => {
41+
return {
42+
useUser: () =>{
43+
return {
44+
userInfo: {
45+
uid: '1',
46+
}
47+
}
48+
}
49+
};
50+
});
351

452
test("data is displayed correctly", async () => {
5-
render(<aboutUsPage/>);
53+
render(<AboutUsPage/>);
654
setTimeout(() => {
755
expect(screen.getByText("Compass is a medical wellness app that targets specifically people above 40 years old who might be interested in having some type of assistance to keep their healthy habits and lifestyles. Compass offers features of managing medical reminders, booking appointments,tracking user’s medications and treatments all in one consolidated application. In addition, having features of medical journals such as diabetic journals allows some patients to easily note their daily doses and treatment details making them able to follow the history of their treatments and use it as a reference for themselves or to show to their medical professional. Additionally,with the speed dial fast option to contact relatives during some emergency situations patients would be able to contact their relatives in a faster and easier way. With many features compass aims for users to be healthier and function hassle free.")).toBeInTheDocument();
856
}, 1000);
957
})
1058

1159
test("data is displayed correctly", async () => {
12-
render(<aboutUsPage/>);
60+
render(<AboutUsPage/>);
1361
setTimeout(() => {
1462
expect(screen.getByText("About Compass")).toBeInTheDocument();
1563

1664
}, 1000);
1765
})
66+
67+
test("Back button redirects to settings page", async () => {
68+
render(<AboutUsPage/>);
69+
const backButton = screen.getAllByRole('button')[0];
70+
await userEvent.click(backButton);
71+
await mockRouter;
72+
expect(mockRouter).toHaveBeenCalledWith('/settings');
73+
})

client/app/aboutUs/page.tsx

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,9 @@ import React from "react";
44
import { useAuth } from "../contexts/AuthContext";
55
import AboutUsPage from "./aboutUsPage";
66

7-
export default function GetFoodJournals() {
7+
export default function GetAboutUs() {
88
const router = useRouter();
99
const { user } = useAuth();
1010

11-
// React.useEffect(() => {
12-
// if (!user) router.push("/login");
13-
// }, [user]);
14-
15-
// if (!user) {
16-
// return <div><Custom403/></div>
17-
// }
18-
1911
return <AboutUsPage />;
2012
}

client/app/createActivityJournal/createActivityJournal.test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,3 +182,11 @@ describe("Activity Journal tests", () => {
182182
expect(mockRouter).toHaveBeenCalledWith("/getActivityJournals");
183183
});
184184
});
185+
186+
test("Back button redirects to getActivityJournals page", async () => {
187+
render(<CreateActivityJournalPage/>);
188+
const backButton = screen.getAllByRole('button')[0];
189+
await userEvent.click(backButton);
190+
await mockRouter;
191+
expect(mockRouter).toHaveBeenCalledWith('/getActivityJournals');
192+
});
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { render } from '@testing-library/react';
2+
import { useRouter } from 'next/router';
3+
import { useAuth } from '../contexts/AuthContext';
4+
import { createActivityJournal } from '../http/activityJournalAPI.ts';
5+
import CreateActivityJournal from './page.tsx';
6+
7+
jest.mock("../contexts/PropContext", () => ({
8+
__esModule: true,
9+
useProp: jest.fn(() => ({
10+
handlePopUp: jest.fn(),
11+
})),
12+
}));
13+
14+
const fakeUser = {
15+
uid: "1"
16+
}
17+
18+
jest.mock('../contexts/AuthContext', () => {
19+
return {
20+
useAuth: () => {
21+
return {
22+
user : fakeUser
23+
}
24+
}
25+
}
26+
});
27+
28+
jest.mock('../http/activityJournalAPI.ts', () => {
29+
return {
30+
createActivityJournal: jest.fn(),
31+
}
32+
});
33+
34+
const mockRouter= jest.fn();
35+
36+
jest.mock("next/navigation", () => ({
37+
useRouter: () => {
38+
return {
39+
push: mockRouter
40+
}
41+
}
42+
}));
43+
44+
jest.mock("../contexts/UserContext", () => {
45+
return {
46+
useUser: () =>{
47+
return {
48+
userInfo: {
49+
uid: '1',
50+
}
51+
}
52+
}
53+
};
54+
});
55+
56+
describe('CreateActivityJournal', () => {
57+
it('returns CreateActivityJournalPage component', () => {
58+
const { container } = render(<CreateActivityJournal />);
59+
60+
expect(container.textContent).toContain('Create Activity Journal');
61+
});
62+
});

client/app/createActivityJournal/page.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,5 @@ export default function CreateActivityJournal() {
88
const router = useRouter();
99
const { user } = useAuth();
1010

11-
// React.useEffect(() => {
12-
// if (!user) router.push("/login");
13-
// }, [user]);
14-
15-
// if (!user) {
16-
// return <div><Custom403/></div>
17-
// }
18-
1911
return <CreateActivityJournalPage />;
2012
}

client/app/createBloodPressureJournal/createBloodPressureJournal.test.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,3 +171,10 @@ describe("Blood Pressure Journal tests", () => {
171171
});
172172
});
173173

174+
test("Back button redirects to getBloodPressureJournals page", async () => {
175+
render(<CreateBloodPressureJournalPage/>);
176+
const backButton = screen.getAllByRole('button')[0];
177+
await userEvent.click(backButton);
178+
await mockRouter;
179+
expect(mockRouter).toHaveBeenCalledWith('/getBloodPressureJournals');
180+
})
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { render } from '@testing-library/react';
2+
import { useRouter } from 'next/router';
3+
import { useAuth } from '../contexts/AuthContext';
4+
import { createBloodPressureJournal } from '../http/bloodPressureJournalAPI.ts';
5+
import CreateBloodPressureJournalPage from './page.tsx';
6+
7+
jest.mock("../contexts/PropContext", () => ({
8+
__esModule: true,
9+
useProp: jest.fn(() => ({
10+
handlePopUp: jest.fn(),
11+
})),
12+
}));
13+
14+
const fakeUser = {
15+
uid: "1"
16+
}
17+
18+
jest.mock('../contexts/AuthContext', () => {
19+
return {
20+
useAuth: () => {
21+
return {
22+
user : fakeUser
23+
}
24+
}
25+
}
26+
});
27+
28+
jest.mock('../http/bloodPressureJournalAPI.ts', () => {
29+
return {
30+
createBloodPressureJournal: jest.fn(),
31+
}
32+
});
33+
34+
const mockRouter= jest.fn();
35+
36+
jest.mock("next/navigation", () => ({
37+
useRouter: () => {
38+
return {
39+
push: mockRouter
40+
}
41+
}
42+
}));
43+
44+
jest.mock("../contexts/UserContext", () => {
45+
return {
46+
useUser: () =>{
47+
return {
48+
userInfo: {
49+
uid: '1',
50+
}
51+
}
52+
}
53+
};
54+
});
55+
56+
describe('CreateBloodPressureJournal', () => {
57+
it('returns CreateBloodPressureJournalPage component', () => {
58+
const { container } = render(<CreateBloodPressureJournalPage />);
59+
60+
expect(container.textContent).toContain('Add an Entry - Blood Pressure');
61+
});
62+
});

client/app/createBloodPressureJournal/page.tsx

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,5 @@ export default function CreateBloodPressureJournal() {
88
const router = useRouter();
99
const { user } = useAuth();
1010

11-
// React.useEffect(() => {
12-
// if (!user) router.push("/login");
13-
// }, [user]);
14-
15-
// if (!user) {
16-
// return <div><Custom403/></div>
17-
// }
18-
1911
return <CreateBloodPressureJournalPage />;
2012
}

client/app/createFoodJournal/createFoodJournal.test.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,19 @@ import userEvent from "@testing-library/user-event";
44
import { auth } from "../config/firebase";
55
import { createFoodIntakeJournal } from "../http/foodJournalAPI";
66
import CreateFoodJournalPage from "./createFoodJournalPage";
7+
78
const fakeUser = {
89
uid: "1",
910
};
11+
12+
jest.mock('next/navigation', () => ({
13+
useSearchParams: () =>{
14+
return {
15+
get: useSearchParams
16+
}
17+
}
18+
}));
19+
1020
jest.mock("../contexts/AuthContext", () => {
1121
return {
1222
useAuth: () => {
@@ -196,3 +206,11 @@ describe("Food journal tests", () => {
196206
expect(mockRouter).toHaveBeenCalledWith("/getFoodJournals");
197207
});
198208
});
209+
210+
test("Back button redirects to getFoodJournals page", async () => {
211+
render(<CreateFoodJournalPage/>);
212+
const backButton = screen.getAllByRole('button')[0];
213+
await userEvent.click(backButton);
214+
await mockRouter;
215+
expect(mockRouter).toHaveBeenCalledWith('/getFoodJournals');
216+
})

0 commit comments

Comments
 (0)