-
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.
test(retain-old-grading-data-option): collect submissions modal jest
- Loading branch information
1 parent
9cb0a2d
commit 3728ee8
Showing
1 changed file
with
76 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
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,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); | ||
}); | ||
}); | ||
}); | ||
}); |