From 70a407b9aae9dcc9304458344e99fdae5af84bcb Mon Sep 17 00:00:00 2001
From: Pranav Rao <56097527+pranavrao145@users.noreply.github.com>
Date: Wed, 16 Oct 2024 18:13:48 -0400
Subject: [PATCH] test(retain-old-grading-data-option):
repo_browser_manual_collection_form
---
.../collect_submissions_modal.test.jsx | 3 +-
...po_browser_manual_collection_form.test.jsx | 40 +++++++++++++++++++
.../javascripts/Components/repo_browser.jsx | 7 +++-
jest.config.js | 4 +-
4 files changed, 50 insertions(+), 4 deletions(-)
create mode 100644 app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx
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 985df4bb4e..39019fb13b 100644
--- a/app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx
+++ b/app/assets/javascripts/Components/__tests__/collect_submissions_modal.test.jsx
@@ -5,7 +5,6 @@ import Modal from "react-modal";
describe("CollectSubmissionsModal", () => {
let props;
- let component;
beforeEach(() => {
props = {
@@ -17,7 +16,7 @@ describe("CollectSubmissionsModal", () => {
// Set the app element for React Modal
Modal.setAppElement("body");
- component = render();
+ render();
});
it("should display the option to recollect old submissions unchecked by default", () => {
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
new file mode 100644
index 0000000000..d7f1355b41
--- /dev/null
+++ b/app/assets/javascripts/Components/__tests__/repo_browser_manual_collection_form.test.jsx
@@ -0,0 +1,40 @@
+import * as React from "react";
+import {render, screen} from "@testing-library/react";
+import {ManualCollectionForm} from "../repo_browser";
+
+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",
+ };
+
+ // Set the app element for React Modal
+ component = render();
+ });
+
+ 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).toBeInTheDocument();
+ expect(chkRecollectExistingSubmissions).toBeInTheDocument();
+ });
+
+ it("does not show the option to retain existing grading when there is a not collected revision present", () => {
+ props.collected_revision_id = "";
+ component.rerender();
+
+ const lblRecollectExistingSubmissions = screen.queryByTestId("lbl_retain_existing_grading");
+ const chkRecollectExistingSubmissions = screen.queryByTestId("chk_retain_existing_grading");
+
+ expect(lblRecollectExistingSubmissions).not.toBeInTheDocument();
+ expect(chkRecollectExistingSubmissions).not.toBeInTheDocument();
+ });
+});
diff --git a/app/assets/javascripts/Components/repo_browser.jsx b/app/assets/javascripts/Components/repo_browser.jsx
index 151ac71a84..a2659f2f86 100644
--- a/app/assets/javascripts/Components/repo_browser.jsx
+++ b/app/assets/javascripts/Components/repo_browser.jsx
@@ -181,12 +181,15 @@ class ManualCollectionForm extends React.Component {
{
this.setState({retainExistingGrading: e.target.checked});
}}
/>
-
+
)}
, elem);
}
+
+export {ManualCollectionForm};
diff --git a/jest.config.js b/jest.config.js
index 4a1e8c8408..2bb33fc826 100644
--- a/jest.config.js
+++ b/jest.config.js
@@ -60,7 +60,9 @@ module.exports = {
// globalTeardown: undefined,
// A set of global variables that need to be available in all test environments
- // globals: {},
+ globals: {
+ AUTH_TOKEN: "test_auth_token",
+ },
// The maximum amount of workers used to run your tests. Can be specified as % or a number. E.g. maxWorkers: 10% will use 10% of your CPU amount + 1 as the maximum worker number. maxWorkers: 2 will use a maximum of 2 workers.
// maxWorkers: "50%",