|
5 | 5 | import {AssignmentSummaryTable} from "../assignment_summary_table"; |
6 | 6 | import {render, screen, fireEvent, waitFor, act} from "@testing-library/react"; |
7 | 7 | import {expect} from "@jest/globals"; |
| 8 | +import {defaultSearchPlaceholderText} from "../table/search_filter"; |
8 | 9 |
|
9 | 10 | describe("For the AssignmentSummaryTable's display of inactive groups", () => { |
10 | 11 | let groups_sample; |
@@ -173,6 +174,90 @@ describe("For the AssignmentSummaryTable's display of an assignment without auto |
173 | 174 | }); |
174 | 175 | }); |
175 | 176 |
|
| 177 | +describe("For the AssignmentSummaryTable's search filter", () => { |
| 178 | + beforeEach(async () => { |
| 179 | + fetch.mockReset(); |
| 180 | + fetch.mockResolvedValueOnce({ |
| 181 | + ok: true, |
| 182 | + json: jest.fn().mockResolvedValueOnce({ |
| 183 | + data: [ |
| 184 | + { |
| 185 | + group_name: "group_0001", |
| 186 | + section: null, |
| 187 | + members: [["c8debuss", "Debussy", "Claude", false]], |
| 188 | + tags: [], |
| 189 | + graders: [["c9varoqu", "Nelle", "Varoquaux"]], |
| 190 | + marking_state: "complete", |
| 191 | + final_grade: 9.0, |
| 192 | + criteria: {}, |
| 193 | + max_mark: "21.0", |
| 194 | + result_id: 1, |
| 195 | + submission_id: 1, |
| 196 | + total_extra_marks: null, |
| 197 | + }, |
| 198 | + { |
| 199 | + group_name: "group_0002", |
| 200 | + section: null, |
| 201 | + members: [["c8holstg", "Holst", "Gustav", false]], |
| 202 | + tags: [], |
| 203 | + graders: [["c9varoqu", "Nelle", "Varoquaux"]], |
| 204 | + marking_state: "complete", |
| 205 | + final_grade: 6.0, |
| 206 | + criteria: {}, |
| 207 | + max_mark: "21.0", |
| 208 | + result_id: 2, |
| 209 | + submission_id: 2, |
| 210 | + total_extra_marks: null, |
| 211 | + }, |
| 212 | + ], |
| 213 | + criteriaColumns: [], |
| 214 | + numAssigned: 2, |
| 215 | + numMarked: 2, |
| 216 | + ltiDeployments: [], |
| 217 | + }), |
| 218 | + }); |
| 219 | + |
| 220 | + await act(async () => { |
| 221 | + render( |
| 222 | + <AssignmentSummaryTable |
| 223 | + assignment_id={1} |
| 224 | + course_id={1} |
| 225 | + is_instructor={false} |
| 226 | + lti_deployments={[]} |
| 227 | + /> |
| 228 | + ); |
| 229 | + }); |
| 230 | + await screen.findByText("group_0001", {exact: false}); |
| 231 | + }); |
| 232 | + |
| 233 | + it("filters rows as the user types in the search box", () => { |
| 234 | + fireEvent.change(screen.getAllByPlaceholderText(defaultSearchPlaceholderText())[0], { |
| 235 | + target: {value: "0001"}, |
| 236 | + }); |
| 237 | + |
| 238 | + expect(screen.queryByText(/group_0001/)).toBeInTheDocument(); |
| 239 | + expect(screen.queryByText(/group_0002/)).not.toBeInTheDocument(); |
| 240 | + }); |
| 241 | + |
| 242 | + it("restores all rows when the search query is cleared", () => { |
| 243 | + const searchInput = screen.getAllByPlaceholderText(defaultSearchPlaceholderText())[0]; |
| 244 | + fireEvent.change(searchInput, {target: {value: "0001"}}); |
| 245 | + fireEvent.change(searchInput, {target: {value: ""}}); |
| 246 | + |
| 247 | + expect(screen.queryByText(/group_0001/)).toBeInTheDocument(); |
| 248 | + expect(screen.queryByText(/group_0002/)).toBeInTheDocument(); |
| 249 | + }); |
| 250 | + |
| 251 | + it("shows no rows when the search query matches nothing", () => { |
| 252 | + fireEvent.change(screen.getAllByPlaceholderText(defaultSearchPlaceholderText())[0], { |
| 253 | + target: {value: "zzznomatch"}, |
| 254 | + }); |
| 255 | + |
| 256 | + expect(screen.queryByText(/group_0001/)).not.toBeInTheDocument(); |
| 257 | + expect(screen.queryByText(/group_0002/)).not.toBeInTheDocument(); |
| 258 | + }); |
| 259 | +}); |
| 260 | + |
176 | 261 | describe("For the AssignmentSummaryTable's subcomponent behavior", () => { |
177 | 262 | let groups_sample; |
178 | 263 | beforeEach(async () => { |
|
0 commit comments