-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature: Add option to retain old grading data on recollection (#7256)
- Loading branch information
1 parent
77250af
commit ecd5b52
Showing
19 changed files
with
708 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
72 changes: 72 additions & 0 deletions
72
app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import {render, screen, fireEvent, waitFor} from "@testing-library/react"; | ||
import CollectSubmissionsModal from "../Modals/collect_submissions_modal"; | ||
import Modal from "react-modal"; | ||
|
||
describe("CollectSubmissionsModal", () => { | ||
let props; | ||
|
||
beforeEach(() => { | ||
props = { | ||
isOpen: true, | ||
isScannedExam: false, | ||
onRequestClose: jest.fn(), | ||
onSubmit: jest.fn(), | ||
}; | ||
|
||
// Set the app element for React Modal | ||
Modal.setAppElement("body"); | ||
render(<CollectSubmissionsModal {...props} />); | ||
}); | ||
|
||
it("should display the option to recollect old submissions unchecked by default", () => { | ||
const lblRecollectExistingSubmissions = screen.getByTestId( | ||
"lbl_recollect_existing_submissions" | ||
); | ||
const chkRecollectExistingSubmissions = screen.getByTestId( | ||
"chk_recollect_existing_submissions" | ||
); | ||
|
||
expect(lblRecollectExistingSubmissions).toBeInTheDocument(); | ||
expect(chkRecollectExistingSubmissions).toBeInTheDocument(); | ||
expect(chkRecollectExistingSubmissions.checked).toBe(false); | ||
}); | ||
|
||
describe("when the option to recollect checkbox is checked", () => { | ||
beforeEach(() => { | ||
fireEvent.click(screen.getByTestId("chk_recollect_existing_submissions")); | ||
}); | ||
|
||
it("should display the option to retain existing grading checked by default", () => { | ||
const lblRetainExistingGrading = screen.getByTestId("lbl_retain_existing_grading"); | ||
const chkRetainExistingGrading = screen.getByTestId("chk_retain_existing_grading"); | ||
|
||
expect(lblRetainExistingGrading).toBeInTheDocument(); | ||
expect(chkRetainExistingGrading).toBeInTheDocument(); | ||
expect(chkRetainExistingGrading.checked).toBe(true); | ||
}); | ||
|
||
it("should display a warning when the retain existing grading option is unchecked", () => { | ||
const chkRetainExistingGrading = screen.getByTestId("chk_retain_existing_grading"); | ||
|
||
fireEvent.click(chkRetainExistingGrading); | ||
|
||
const divGradingDataWillBeLost = screen.getByTestId("div_grading_data_will_be_lost"); | ||
const lblRetainExistingGrading = screen.queryByTestId("lbl_retain_existing_grading"); | ||
|
||
expect(chkRetainExistingGrading.checked).toBe(false); | ||
expect(divGradingDataWillBeLost).toBeInTheDocument(); | ||
expect(lblRetainExistingGrading).toBeInTheDocument(); | ||
}); | ||
|
||
it("should call onSubmit with the correct parameters when the form is submitted", async () => { | ||
const btnCollectSubmissions = screen.getByTestId("btn_collect_submissions"); | ||
|
||
fireEvent.click(btnCollectSubmissions); | ||
|
||
await waitFor(() => { | ||
expect(props.onSubmit).toHaveBeenCalledTimes(1); | ||
expect(props.onSubmit).toHaveBeenCalledWith(true, false, true, true); | ||
}); | ||
}); | ||
}); | ||
}); |
66 changes: 66 additions & 0 deletions
66
app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import {render, screen, fireEvent} from "@testing-library/react"; | ||
import {ManualCollectionForm} from "../repo_browser"; | ||
|
||
jest.mock("@fortawesome/react-fontawesome", () => ({ | ||
FontAwesomeIcon: () => { | ||
return null; | ||
}, | ||
})); | ||
|
||
describe("RepoBrowser's ManualCollectionForm", () => { | ||
let props, component; | ||
|
||
beforeEach(() => { | ||
props = { | ||
course_id: 1, | ||
assignment_id: 2, | ||
late_penalty: false, | ||
grouping_id: 1, | ||
revision_identifier: "test", | ||
collected_revision_id: "test", | ||
}; | ||
|
||
component = render(<ManualCollectionForm {...props} />); | ||
}); | ||
|
||
it("shows the option to retain existing grading when there is a collected revision present", () => { | ||
const lblRecollectExistingSubmissions = screen.getByTestId("lbl_retain_existing_grading"); | ||
const chkRecollectExistingSubmissions = screen.getByTestId("chk_retain_existing_grading"); | ||
|
||
expect(lblRecollectExistingSubmissions).toBeVisible(); | ||
expect(chkRecollectExistingSubmissions).toBeVisible(); | ||
}); | ||
|
||
it("does not show the option to retain existing grading when there is a not collected revision present", () => { | ||
props.collected_revision_id = ""; | ||
component.rerender(<ManualCollectionForm {...props} />); | ||
|
||
const lblRecollectExistingSubmissions = screen.queryByTestId("lbl_retain_existing_grading"); | ||
const chkRecollectExistingSubmissions = screen.queryByTestId("chk_retain_existing_grading"); | ||
|
||
expect(lblRecollectExistingSubmissions).not.toBeVisible(); | ||
expect(chkRecollectExistingSubmissions).not.toBeVisible(); | ||
}); | ||
|
||
it("should confirm with a full overwrite warning when retain existing grading option is checked", () => { | ||
const confirmSpy = jest.spyOn(window, "confirm").mockImplementation(() => false); | ||
const manualCollectionForm = component.getByTestId("form_manual_collection"); | ||
|
||
fireEvent.submit(manualCollectionForm); | ||
|
||
expect(confirmSpy).toHaveBeenCalledWith( | ||
I18n.t("submissions.collect.confirm_recollect_retain_data") | ||
); | ||
}); | ||
|
||
it("should confirm with a full overwrite warning when retain existing grading option is not checked", () => { | ||
const confirmSpy = jest.spyOn(window, "confirm").mockImplementation(() => false); | ||
const chkRecollectExistingSubmissions = screen.queryByTestId("chk_retain_existing_grading"); | ||
const manualCollectionForm = component.getByTestId("form_manual_collection"); | ||
|
||
fireEvent.click(chkRecollectExistingSubmissions); | ||
fireEvent.submit(manualCollectionForm); | ||
|
||
expect(confirmSpy).toHaveBeenCalledWith(I18n.t("submissions.collect.full_overwrite_warning")); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.