diff --git a/app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx b/app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx
index 39019fb13b..01c63e975c 100644
--- a/app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx
+++ b/app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx
@@ -1,4 +1,3 @@
-import * as React from "react";
import {render, screen, fireEvent, waitFor} from "@testing-library/react";
import CollectSubmissionsModal from "../Modals/collect_submissions_modal";
import Modal from "react-modal";
diff --git a/app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx b/app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx
index d7f1355b41..ce66eef1ad 100644
--- a/app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx
+++ b/app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx
@@ -1,7 +1,18 @@
-import * as React from "react";
-import {render, screen} from "@testing-library/react";
+import {render, screen, fireEvent} from "@testing-library/react";
import {ManualCollectionForm} from "../repo_browser";
+// workaround needed for using i18n in jest tests, see
+// https://github.com/fnando/i18n/issues/26#issuecomment-1235751777
+jest.mock("i18n-js", () => {
+ return jest.requireActual("i18n-js/dist/require/index");
+});
+
+jest.mock("@fortawesome/react-fontawesome", () => ({
+ FontAwesomeIcon: () => {
+ return null;
+ },
+}));
+
describe("RepoBrowser's ManualCollectionForm", () => {
let props, component;
@@ -15,7 +26,6 @@ describe("RepoBrowser's ManualCollectionForm", () => {
collected_revision_id: "test",
};
- // Set the app element for React Modal
component = render();
});
@@ -23,8 +33,8 @@ describe("RepoBrowser's ManualCollectionForm", () => {
const lblRecollectExistingSubmissions = screen.getByTestId("lbl_retain_existing_grading");
const chkRecollectExistingSubmissions = screen.getByTestId("chk_retain_existing_grading");
- expect(lblRecollectExistingSubmissions).toBeInTheDocument();
- expect(chkRecollectExistingSubmissions).toBeInTheDocument();
+ expect(lblRecollectExistingSubmissions).toBeVisible();
+ expect(chkRecollectExistingSubmissions).toBeVisible();
});
it("does not show the option to retain existing grading when there is a not collected revision present", () => {
@@ -34,7 +44,29 @@ describe("RepoBrowser's ManualCollectionForm", () => {
const lblRecollectExistingSubmissions = screen.queryByTestId("lbl_retain_existing_grading");
const chkRecollectExistingSubmissions = screen.queryByTestId("chk_retain_existing_grading");
- expect(lblRecollectExistingSubmissions).not.toBeInTheDocument();
- expect(chkRecollectExistingSubmissions).not.toBeInTheDocument();
+ 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.partial_overwrite_warning")
+ );
+ });
+
+ 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"));
});
});
diff --git a/app/assets/javascripts/Components/repo_browser.jsx b/app/assets/javascripts/Components/repo_browser.jsx
index a2659f2f86..244c236c95 100644
--- a/app/assets/javascripts/Components/repo_browser.jsx
+++ b/app/assets/javascripts/Components/repo_browser.jsx
@@ -157,7 +157,22 @@ class ManualCollectionForm extends React.Component {
-