Skip to content

Commit

Permalink
test(retain-old-grading-data-option): collect submissions modal jest
Browse files Browse the repository at this point in the history
  • Loading branch information
pranavrao145 committed Oct 16, 2024
1 parent 9cb0a2d commit 3728ee8
Showing 1 changed file with 76 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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";

describe("CollectSubmissionsModal", () => {
let props;
let component;

beforeEach(() => {
props = {
isOpen: true,
isScannedExam: false,
onRequestClose: jest.fn(),
onSubmit: jest.fn(),
};

// Set the app element for React Modal
Modal.setAppElement("body");
component = 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 lblRetainExistingGradingWarning = screen.getByTestId(
"lbl_retain_existing_grading_warning"
);
const lblRetainExistingGrading = screen.queryByTestId("lbl_retain_existing_grading");

expect(chkRetainExistingGrading.checked).toBe(false);
expect(lblRetainExistingGradingWarning).toBeInTheDocument();
expect(lblRetainExistingGrading).not.toBeInTheDocument();
});

it("should call onSubmit 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);
});
});
});
});

0 comments on commit 3728ee8

Please sign in to comment.