-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
278 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
63 changes: 63 additions & 0 deletions
63
services/ui-src/src/components/modals/AddEditReportModal.test.tsx
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,63 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { AddEditReportModal } from "components"; | ||
import { | ||
mockStateUserStore, | ||
RouterWrappedComponent, | ||
} from "utils/testing/setupJest"; | ||
import { useStore } from "utils"; | ||
import userEvent from "@testing-library/user-event"; | ||
|
||
const mockCloseHandler = jest.fn(); | ||
const mockReportHandler = jest.fn(); | ||
|
||
jest.mock("utils/state/useStore"); | ||
const mockedUseStore = useStore as jest.MockedFunction<typeof useStore>; | ||
|
||
const modalComponent = ( | ||
<RouterWrappedComponent> | ||
<AddEditReportModal | ||
activeState="AB" | ||
reportType={"QM"} | ||
modalDisclosure={{ | ||
isOpen: true, | ||
onClose: mockCloseHandler, | ||
}} | ||
reportHandler={mockReportHandler} | ||
/> | ||
</RouterWrappedComponent> | ||
); | ||
|
||
describe("Test AddEditProgramModal", () => { | ||
beforeEach(() => { | ||
mockedUseStore.mockReturnValue(mockStateUserStore); | ||
render(modalComponent); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.clearAllMocks(); | ||
}); | ||
|
||
test("AddEditReportModal shows the contents", () => { | ||
expect(screen.getByText("QMS report name")).toBeInTheDocument(); | ||
expect(screen.getByText("Start new")).toBeInTheDocument(); | ||
}); | ||
|
||
test("AddEditReportModal top close button can be clicked", async () => { | ||
await userEvent.click(screen.getByText("Close")); | ||
expect(mockCloseHandler).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
test("AddEditReportModal bottom cancel button can be clicked", async () => { | ||
await userEvent.click(screen.getByText("Cancel")); | ||
expect(mockCloseHandler).toHaveBeenCalledTimes(1); | ||
}); | ||
}); | ||
|
||
describe("Test AddEditReportModal accessibility", () => { | ||
it("Should not have basic accessibility issues", async () => { | ||
const { container } = render(modalComponent); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
}); |
78 changes: 78 additions & 0 deletions
78
services/ui-src/src/components/modals/AddEditReportModal.tsx
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,78 @@ | ||
import { useState } from "react"; | ||
import { Modal, TextField } from "components"; | ||
import { Spinner, Flex } from "@chakra-ui/react"; | ||
import { AnyObject, ElementType } from "types"; | ||
import { createReport } from "utils/api/requestMethods/report"; | ||
import { FormProvider, useForm } from "react-hook-form"; | ||
import { ReportOptions } from "types/report"; | ||
|
||
export const AddEditReportModal = ({ | ||
activeState, | ||
reportType, | ||
modalDisclosure, | ||
reportHandler, | ||
}: Props) => { | ||
const [submitting, setSubmitting] = useState<boolean>(false); | ||
|
||
// add validation to formJson | ||
const form = useForm(); | ||
|
||
const onSubmit = async (formData: any) => { | ||
setSubmitting(true); | ||
|
||
const reportOptions: ReportOptions = { | ||
name: "", | ||
}; | ||
|
||
if (formData.reportTitle) { | ||
reportOptions.name = formData.reportTitle.answer; | ||
} | ||
|
||
await createReport(reportType, activeState, reportOptions); | ||
|
||
await reportHandler(reportType, activeState); | ||
setSubmitting(false); | ||
modalDisclosure.onClose(); | ||
}; | ||
|
||
return ( | ||
<Modal | ||
data-testid="add-edit-report-modal" | ||
formId="addEditReportModal" | ||
modalDisclosure={modalDisclosure} | ||
content={{ | ||
heading: "Add new Quality Measure Set Report", | ||
subheading: "", | ||
actionButtonText: submitting ? <Spinner size="md" /> : "Start new", | ||
closeButtonText: "Cancel", | ||
}} | ||
> | ||
<FormProvider {...form}> | ||
<form id="addEditReportModal" onSubmit={form.handleSubmit(onSubmit)}> | ||
<Flex> | ||
<TextField | ||
element={{ | ||
type: ElementType.Textbox, | ||
label: "QMS report name", | ||
helperText: | ||
"Name this QMS report so you can easily refer to it. Consider using timeframe(s).", | ||
}} | ||
formkey={"reportTitle"} | ||
></TextField> | ||
</Flex> | ||
</form> | ||
</FormProvider> | ||
</Modal> | ||
); | ||
}; | ||
|
||
interface Props { | ||
activeState: string; | ||
reportType: string; | ||
selectedReport?: AnyObject; | ||
modalDisclosure: { | ||
isOpen: boolean; | ||
onClose: any; | ||
}; | ||
reportHandler: (reportType: string, activeState: string) => void; | ||
} |
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
Oops, something went wrong.