Skip to content

Commit 25c725b

Browse files
committed
Add test cases for timer component and fix existing test cases
1 parent f082a20 commit 25c725b

File tree

13 files changed

+58
-32
lines changed

13 files changed

+58
-32
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/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/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

frontend/src/components/QuestionImageContainer/QuestionImageContainer.test.tsx

Lines changed: 11 additions & 12 deletions
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 QuestionImageContainer from ".";
43
import { questionClient } from "../../utils/api";
54

@@ -27,7 +26,7 @@ describe("Question Image Container", () => {
2726
Object.defineProperty(window, "localStorage", {
2827
value: mockLocalStorage,
2928
writable: true,
30-
}),
29+
})
3130
);
3231

3332
it("Question Image Container is rendered with no uploaded images", () => {
@@ -38,11 +37,11 @@ describe("Question Image Container", () => {
3837
<QuestionImageContainer
3938
uploadedImagesUrl={uploadedImagesUrl}
4039
setUploadedImagesUrl={setUploadedImagesUrl}
41-
/>,
40+
/>
4241
);
4342

4443
const uploadImageMessage = screen.getByText(
45-
"Click to upload images. The maximum image size accepted is 5MB.",
44+
"Click to upload images. The maximum image size accepted is 5MB."
4645
);
4746
expect(uploadImageMessage).toBeInTheDocument();
4847
});
@@ -55,7 +54,7 @@ describe("Question Image Container", () => {
5554
<QuestionImageContainer
5655
uploadedImagesUrl={uploadedImagesUrl}
5756
setUploadedImagesUrl={setUploadedImagesUrl}
58-
/>,
57+
/>
5958
);
6059

6160
const images = screen.getAllByAltText("question image");
@@ -70,7 +69,7 @@ describe("Question Image Container", () => {
7069
<QuestionImageContainer
7170
uploadedImagesUrl={uploadedImagesUrl}
7271
setUploadedImagesUrl={setUploadedImagesUrl}
73-
/>,
72+
/>
7473
);
7574

7675
const image = screen.getByAltText("question image");
@@ -110,7 +109,7 @@ describe("Question Image Container", () => {
110109
<QuestionImageContainer
111110
uploadedImagesUrl={uploadedImagesUrl}
112111
setUploadedImagesUrl={setUploadedImagesUrl}
113-
/>,
112+
/>
114113
);
115114

116115
const file = new File(["file"], "file.png", { type: "image/png" });
@@ -126,7 +125,7 @@ describe("Question Image Container", () => {
126125
Authorization: `Bearer ${mockLocalStorage.getItem("token")}`,
127126
"Content-Type": "multipart/form-data",
128127
},
129-
}),
128+
})
130129
);
131130

132131
expect(setUploadedImagesUrl).toHaveBeenCalled();
@@ -141,7 +140,7 @@ describe("Question Image Container", () => {
141140
<QuestionImageContainer
142141
uploadedImagesUrl={uploadedImagesUrl}
143142
setUploadedImagesUrl={setUploadedImagesUrl}
144-
/>,
143+
/>
145144
);
146145

147146
const file = new File(["file"], "file.txt", { type: "text/plain" });
@@ -159,7 +158,7 @@ describe("Question Image Container", () => {
159158
<QuestionImageContainer
160159
uploadedImagesUrl={uploadedImagesUrl}
161160
setUploadedImagesUrl={setUploadedImagesUrl}
162-
/>,
161+
/>
163162
);
164163

165164
const input = screen.getByTestId("file-input");
@@ -185,7 +184,7 @@ describe("Question Image Container", () => {
185184
<QuestionImageContainer
186185
uploadedImagesUrl={uploadedImagesUrl}
187186
setUploadedImagesUrl={setUploadedImagesUrl}
188-
/>,
187+
/>
189188
);
190189

191190
const file = new File(["file"], "file.png", { type: "image/png" });
@@ -205,7 +204,7 @@ describe("Question Image Container", () => {
205204
<QuestionImageContainer
206205
uploadedImagesUrl={uploadedImagesUrl}
207206
setUploadedImagesUrl={setUploadedImagesUrl}
208-
/>,
207+
/>
209208
);
210209

211210
const input = screen.getByTestId("file-input");

frontend/src/components/QuestionImageDialog/QuestionImageDialog.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 QuestionImageDialog from ".";
43

54
describe("Question Image Dialog", () => {
@@ -12,7 +11,7 @@ describe("Question Image Dialog", () => {
1211
value={url}
1312
open={true}
1413
handleClose={mockHandleClose}
15-
/>,
14+
/>
1615
);
1716

1817
const image = screen.getByAltText("question image enlarged");
@@ -27,7 +26,7 @@ describe("Question Image Dialog", () => {
2726
value={url}
2827
open={false}
2928
handleClose={mockHandleClose}
30-
/>,
29+
/>
3130
);
3231

3332
expect(screen.queryByRole("dialog")).not.toBeInTheDocument();
@@ -39,7 +38,7 @@ describe("Question Image Dialog", () => {
3938
value={url}
4039
open={true}
4140
handleClose={mockHandleClose}
42-
/>,
41+
/>
4342
);
4443

4544
const closeButton = screen.getByRole("button", { name: "close" });

frontend/src/components/QuestionMarkdown/QuestionMarkdown.test.tsx

Lines changed: 3 additions & 4 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 QuestionMarkdown from ".";
43

54
jest.mock("@uiw/react-md-editor", () => ({
@@ -29,7 +28,7 @@ describe("Question Markdown", () => {
2928
<QuestionMarkdown
3029
markdownText={markdownText}
3130
setMarkdownText={setMarkdownText}
32-
/>,
31+
/>
3332
);
3433

3534
const textarea = screen.getByPlaceholderText("Description");
@@ -44,7 +43,7 @@ describe("Question Markdown", () => {
4443
<QuestionMarkdown
4544
markdownText={markdownText}
4645
setMarkdownText={setMarkdownText}
47-
/>,
46+
/>
4847
);
4948

5049
const textarea = screen.getByPlaceholderText("Description");
@@ -58,7 +57,7 @@ describe("Question Markdown", () => {
5857
<QuestionMarkdown
5958
markdownText={markdownText}
6059
setMarkdownText={setMarkdownText}
61-
/>,
60+
/>
6261
);
6362

6463
const textarea = screen.getByPlaceholderText("Description");

0 commit comments

Comments
 (0)