From 01e0d6377ea8abae522084e775ac8beec13c156b Mon Sep 17 00:00:00 2001
From: Pranav Rao <56097527+pranavrao145@users.noreply.github.com>
Date: Thu, 17 Oct 2024 23:26:40 -0400
Subject: [PATCH] test(retain-old-grading-data-option): further test coverage
---
.../collect_submissions_modal.test.jsx | 1 -
...po_browser_manual_collection_form.test.jsx | 46 +++++++++++--
.../javascripts/Components/repo_browser.jsx | 67 ++++++++++---------
spec/jobs/submissions_job_spec.rb | 50 ++++++++------
4 files changed, 104 insertions(+), 60 deletions(-)
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 {
-