|
| 1 | +import {render, screen} from "@testing-library/react"; |
| 2 | +import {GroupsManager} from "../groups_manager"; |
| 3 | +import {beforeEach, describe, expect, it} from "@jest/globals"; |
| 4 | +import {getTimeExtension} from "../Helpers/table_helpers"; |
| 5 | + |
| 6 | +jest.mock("@fortawesome/react-fontawesome", () => ({ |
| 7 | + FontAwesomeIcon: () => { |
| 8 | + return null; |
| 9 | + }, |
| 10 | +})); |
| 11 | + |
| 12 | +const groupMock = [ |
| 13 | + { |
| 14 | + group_name: "c6scriab", |
| 15 | + inactive: false, |
| 16 | + instructor_approved: true, |
| 17 | + members: [ |
| 18 | + { |
| 19 | + 0: "c6scriab", |
| 20 | + 1: "inviter", |
| 21 | + 2: false, |
| 22 | + display_label: "(inviter)", |
| 23 | + }, |
| 24 | + ], |
| 25 | + extension: { |
| 26 | + apply_penalty: false, |
| 27 | + grouping_id: 22, |
| 28 | + id: null, |
| 29 | + note: "", |
| 30 | + }, |
| 31 | + section: "", |
| 32 | + }, |
| 33 | + { |
| 34 | + group_name: "group2", |
| 35 | + inactive: false, |
| 36 | + instructor_approved: true, |
| 37 | + members: [ |
| 38 | + { |
| 39 | + 0: "student1", |
| 40 | + 1: "inviter", |
| 41 | + 2: false, |
| 42 | + display_label: "(inviter)", |
| 43 | + }, |
| 44 | + ], |
| 45 | + section: "", |
| 46 | + extension: { |
| 47 | + apply_penalty: true, |
| 48 | + days: 2, |
| 49 | + grouping_id: 16, |
| 50 | + hours: 0, |
| 51 | + id: 51, |
| 52 | + minutes: 0, |
| 53 | + note: "", |
| 54 | + weeks: 0, |
| 55 | + }, |
| 56 | + }, |
| 57 | +]; |
| 58 | +const studentMock = [ |
| 59 | + { |
| 60 | + assigned: true, |
| 61 | + first_name: "coolStudent", |
| 62 | + hidden: false, |
| 63 | + id: 8, |
| 64 | + last_name: "Alberic", |
| 65 | + user_name: "student1", |
| 66 | + }, |
| 67 | +]; |
| 68 | + |
| 69 | +describe("GroupsManager", () => { |
| 70 | + let filter_method = null; |
| 71 | + let wrapper = React.createRef(); |
| 72 | + |
| 73 | + beforeEach(async () => { |
| 74 | + fetch.mockReset(); |
| 75 | + fetch.mockResolvedValueOnce({ |
| 76 | + ok: true, |
| 77 | + json: jest.fn().mockResolvedValueOnce({ |
| 78 | + templates: [], |
| 79 | + groups: groupMock, |
| 80 | + exam_templates: [], |
| 81 | + students: studentMock, |
| 82 | + clone_assignments: [], |
| 83 | + }), |
| 84 | + }); |
| 85 | + const props = { |
| 86 | + course_id: 1, |
| 87 | + timed: false, |
| 88 | + assignment_id: 2, |
| 89 | + scanned_exam: false, |
| 90 | + examTemplates: [], |
| 91 | + times: ["weeks", "days", "hours", "minutes"], |
| 92 | + }; |
| 93 | + render(<GroupsManager {...props} ref={wrapper} />); |
| 94 | + // wait for page to load and render content |
| 95 | + await screen.findByText("abcd").catch(err => err); |
| 96 | + // to view screen render: screen.debug(undefined, 300000) |
| 97 | + }); |
| 98 | + |
| 99 | + describe("DueDateExtensions", () => { |
| 100 | + beforeEach(() => { |
| 101 | + filter_method = |
| 102 | + wrapper.current.groupsTable.wrapped.checkboxTable.props.columns[5].filterMethod; |
| 103 | + }); |
| 104 | + |
| 105 | + it("append (late submissions accepted) to assignments with extensions", async () => { |
| 106 | + const groupWithExtension = groupMock[1]; |
| 107 | + const timePeriods = ["weeks", "days", "hours", "minutes"]; |
| 108 | + const timeExtension = getTimeExtension(groupWithExtension.extension, timePeriods); |
| 109 | + const searchTerm = `${timeExtension} (${I18n.t("groups.late_submissions_accepted")})`; |
| 110 | + expect(await screen.getByRole("link", {name: searchTerm})).toBeInTheDocument(); |
| 111 | + }); |
| 112 | + |
| 113 | + it("returns true when the selected value is all", () => { |
| 114 | + expect(filter_method({value: "all"})).toEqual(true); |
| 115 | + }); |
| 116 | + |
| 117 | + describe("withExtension: false", () => { |
| 118 | + it("returns true when assignments without an extension are present", () => { |
| 119 | + const rowMock = {_original: {extension: {}}}; |
| 120 | + const filterOptionsMock = JSON.stringify({withExtension: false}); |
| 121 | + expect(filter_method({value: filterOptionsMock}, rowMock)).toEqual(true); |
| 122 | + }); |
| 123 | + it("returns false when assignments with an extension are present", () => { |
| 124 | + const rowMock = {_original: {extension: {hours: 1}}}; |
| 125 | + const filterOptionsMock = JSON.stringify({withExtension: false}); |
| 126 | + expect(filter_method({value: filterOptionsMock}, rowMock)).toEqual(false); |
| 127 | + }); |
| 128 | + }); |
| 129 | + |
| 130 | + describe("withExtension: true", () => { |
| 131 | + describe("withLateSubmission: true", () => { |
| 132 | + it("returns true when assignments have a late submission rule applied", () => { |
| 133 | + const rowMock = {_original: {extension: {hours: 1, apply_penalty: true}}}; |
| 134 | + const filterOptionsMock = JSON.stringify({withExtension: true, withLateSubmission: true}); |
| 135 | + expect(filter_method({value: filterOptionsMock}, rowMock)).toEqual(true); |
| 136 | + }); |
| 137 | + it("returns false when assignments are missing an extension", () => { |
| 138 | + const rowMock = {_original: {extension: {apply_penalty: true}}}; |
| 139 | + const filterOptionsMock = JSON.stringify({withExtension: true, withLateSubmission: true}); |
| 140 | + expect(filter_method({value: filterOptionsMock}, rowMock)).toEqual(false); |
| 141 | + }); |
| 142 | + }); |
| 143 | + describe("withLateSubmission: false", () => { |
| 144 | + it("returns true when assignments are missing an extension", () => { |
| 145 | + const rowMock = {_original: {extension: {hours: 1, apply_penalty: true}}}; |
| 146 | + const filterOptionsMock = JSON.stringify({ |
| 147 | + withExtension: true, |
| 148 | + withLateSubmission: false, |
| 149 | + }); |
| 150 | + expect(filter_method({value: filterOptionsMock}, rowMock)).toEqual(false); |
| 151 | + }); |
| 152 | + |
| 153 | + it("returns false when assignments have a late submission rule applied", () => { |
| 154 | + const rowMock = {_original: {extension: {hours: 1, apply_penalty: true}}}; |
| 155 | + const filterOptionsMock = JSON.stringify({ |
| 156 | + withExtension: true, |
| 157 | + withLateSubmission: false, |
| 158 | + }); |
| 159 | + expect(filter_method({value: filterOptionsMock}, rowMock)).toEqual(false); |
| 160 | + }); |
| 161 | + }); |
| 162 | + }); |
| 163 | + }); |
| 164 | +}); |
0 commit comments