forked from Courseography/courseography
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCoursePanel.test.js
More file actions
88 lines (71 loc) · 2.27 KB
/
CoursePanel.test.js
File metadata and controls
88 lines (71 loc) · 2.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import { render, screen, cleanup, waitFor } from "@testing-library/react"
import userEvent from "@testing-library/user-event"
import { CoursePanel } from "../course_panel.js.jsx"
import fetchMock from "fetch-mock"
describe("CoursePanel", () => {
const coursePanelProps = {
selectedCourses: [],
selectedLectures: [],
removeCourse: jest.fn(),
clearCourses: jest.fn(),
hoverLecture: jest.fn(),
unhoverLecture: jest.fn(),
selectLecture: jest.fn(),
}
beforeEach(() => {
cleanup()
fetchMock.restore()
})
afterEach(() => {
fetchMock.restore()
})
it("fetches course sections and updates course info", async () => {
const user = userEvent.setup()
fetchMock.get("/courses", "CSC110Y1\nCSC111H1\nMAT137Y1")
const mockCourseData = {
name: "CSC110Y1",
title: "Foundations of Computer Science I",
description: null,
prereqs: null,
exclusions: null,
breadth: null,
distribution: null,
prereqString: null,
coreqs: null,
allMeetingTimes: [
{
meetData: { session: "F", section: "LEC0101", code: "CSC110Y1" },
timeData: [],
},
],
videoUrls: [],
}
fetchMock.get("/course?name=CSC110Y1", {
status: 200,
body: mockCourseData,
})
render(<CoursePanel {...coursePanelProps} selectedCourses={["CSC110Y1"]} />)
const courseHeader = await screen.findByText("CSC110Y1")
await user.click(courseHeader)
await screen.findByText("L0101")
})
it("handles the case when course is not found", async () => {
const user = userEvent.setup()
const consoleErrorMock = jest.spyOn(console, "error").mockImplementation()
fetchMock.get("/courses", "CSC110Y1\nCSC111H1\nMAT137Y1")
fetchMock.get("/course?name=MISSING110Y1", {
status: 404,
body: {},
})
render(<CoursePanel {...coursePanelProps} selectedCourses={["MISSING110Y1"]} />)
const courseHeader = await screen.findByText("MISSING110Y1")
await user.click(courseHeader)
expect(screen.queryByText("L0101")).toBeNull()
await waitFor(() => {
expect(consoleErrorMock).toHaveBeenCalledWith(
expect.stringContaining("Course with code MISSING110Y1 not found")
)
})
consoleErrorMock.mockRestore()
})
})