forked from MarkUsProject/Markus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstructor_table.test.jsx
More file actions
93 lines (85 loc) · 2.64 KB
/
instructor_table.test.jsx
File metadata and controls
93 lines (85 loc) · 2.64 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
89
90
91
92
93
import {render, screen} from "@testing-library/react";
import {InstructorTable} from "../instructor_table";
global.fetch = jest.fn(() =>
Promise.resolve({
ok: true,
json: () =>
Promise.resolve({
data: [],
counts: {},
}),
})
);
describe("For the InstructorTable's display of instructors", () => {
let instructors_sample;
describe("when some instructors are fetched", () => {
const instructors_in_one_row = instructor => {
const rows = screen.getAllByRole("row");
for (let row of rows) {
const cells = Array.from(row.childNodes).map(c => c.textContent);
if (cells[0] === instructor.user_name) {
expect(cells[1]).toEqual(instructor.first_name);
expect(cells[2]).toEqual(instructor.last_name);
if (instructor.email) {
expect(cells[3]).toEqual(instructor.email);
}
return;
}
}
// If the loop ends without finding the instructor, raise an error
throw `Could not find row for ${instructor.user_name}`;
};
beforeAll(async () => {
instructors_sample = [
{
id: 1,
user_name: "a",
first_name: "David",
last_name: "Liu",
email: "example@gmail.com",
hidden: false,
},
{
id: 2,
user_name: "reid",
first_name: "Karen",
last_name: "Reid",
email: null,
hidden: true,
},
];
// Mocking the response returned by fetch, used in InstructorTable fetchData
fetch.mockReset();
fetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValueOnce({
data: instructors_sample,
counts: {all: 2, active: 1, inactive: 1},
}),
});
render(<InstructorTable course_id={1} />);
await screen.findByText("reid");
});
it("each instructor is displayed as a row of the table", async () => {
instructors_sample.forEach(instructor => instructors_in_one_row(instructor));
});
});
describe("when no instructors are fetched", () => {
beforeAll(() => {
instructors_sample = [];
// Mocking the response returned by fetch, used in InstructorTable fetchData
fetch.mockReset();
fetch.mockResolvedValueOnce({
ok: true,
json: jest.fn().mockResolvedValueOnce({
data: instructors_sample,
counts: {all: 0, active: 0, inactive: 0},
}),
});
render(<InstructorTable course_id={1} />);
});
it("No rows found is shown", async () => {
await screen.findByText(I18n.t("instructors.empty_table"));
});
});
});