Skip to content

Commit

Permalink
test: tests for modal behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
pbastia committed Jan 3, 2025
1 parent bf4f3c5 commit aae7ffd
Show file tree
Hide file tree
Showing 4 changed files with 109 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,10 @@ export default function OperationReview({
onConfirm={confirmReportTypeChange}
confirmText="Change report type"
>
Are you sure you want to change your report type? If you proceed, all of
the form data you have entered will be lost upon saving.
<p>
Are you sure you want to change your report type? If you proceed, all
of the form data you have entered will be lost upon saving.
</p>
</SimpleModal>
<MultiStepFormWithTaskList
initialStep={0}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ export const getOperationInformationTaskList: (
{
type: "Page",
title: "Review Operation information",
link: `/reporting/reports/${versionId}/review-operator-data`,
link: `/reports/${versionId}/review-operator-data`,
isActive: activeIndex === ActivePage.ReviewOperatorInfo,
},
{
type: "Page",
title: "Person responsible",
link: `/reporting/reports/${versionId}/person-responsible`,
link: `/reports/${versionId}/person-responsible`,
isActive: activeIndex === ActivePage.PersonResponsible,
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ describe("OperationReview Component", () => {
allRegulatedProducts={[{ id: 1, name: "Product 1" }]}
registrationPurpose="Test Purpose"
facilityReport={{
facility_id: 2344,
facility_id: "fake-guid",
operation_type: "Single Facility Operation",
}}
/>,
Expand Down Expand Up @@ -90,7 +90,7 @@ describe("OperationReview Component", () => {
allRegulatedProducts={[{ id: 1, name: "Product 1" }]}
registrationPurpose="Test Purpose"
facilityReport={{
facility_id: 2344,
facility_id: "fake-guid",
operation_type: "Single Facility Operation",
}}
/>,
Expand Down Expand Up @@ -134,7 +134,7 @@ describe("OperationReview Component", () => {
allRegulatedProducts={[{ id: 1, name: "Product 1" }]}
registrationPurpose="Test Purpose"
facilityReport={{
facility_id: 2344,
facility_id: "fake-guid",
operation_type: "Single Facility Operation",
}}
/>,
Expand All @@ -148,4 +148,103 @@ describe("OperationReview Component", () => {
).toBeInTheDocument();
});
});

it("shows modal when switching report type and switches report type when accepting", async () => {
render(
<OperationReview
formData={{
activities: [1],
regulated_products: [1],
operation_report_type: "Annual Report",
}}
version_id={1}
reportType={{ report_type: "Annual Report" }}
reportingYear={{
reporting_year: 2024,
report_due_date: "2024-12-31",
reporting_window_end: "2024-12-31",
}}
allActivities={[{ id: 1, name: "Activity 1" }]}
allRegulatedProducts={[{ id: 1, name: "Product 1" }]}
registrationPurpose="Test Purpose"
facilityReport={{
facility_id: "fake-guid",
operation_type: "Single Facility Operation",
}}
/>,
);

const reportTypeSelect = screen.getByLabelText(
/Select what type of report you are filling/i,
);

await waitFor(() => {
fireEvent.change(reportTypeSelect, {
target: { value: "Simple Report" },
});
});

expect(
screen.getByText(/Are you sure you want to change your report type/i),
).toBeVisible();
expect(screen.getByText(/Change Report Type/i)).toBeVisible();

await waitFor(() => {
fireEvent.click(
screen.getByRole("button", { name: "Change report type" }),
);
});

expect(
screen.queryByText(/Are you sure you want to change your report type/i),
).not.toBeVisible();
expect(screen.getByText(/Simple Report/i)).toBeVisible();
expect(screen.queryByText(/Annual Report/i)).not.toBeInTheDocument();
});

it("shows modal when switching report type and reverts report type when clicking cancel", async () => {
render(
<OperationReview
formData={{
activities: [1],
regulated_products: [1],
operation_report_type: "Annual Report",
}}
version_id={1}
reportType={{ report_type: "Annual Report" }}
reportingYear={{
reporting_year: 2024,
report_due_date: "2024-12-31",
reporting_window_end: "2024-12-31",
}}
allActivities={[{ id: 1, name: "Activity 1" }]}
allRegulatedProducts={[{ id: 1, name: "Product 1" }]}
registrationPurpose="Test Purpose"
facilityReport={{
facility_id: "fake-guid",
operation_type: "Single Facility Operation",
}}
/>,
);

const reportTypeSelect = screen.getByLabelText(
/Select what type of report you are filling/i,
);

await waitFor(() => {
fireEvent.change(reportTypeSelect, {
target: { value: "Simple Report" },
});
});

await waitFor(() => {
fireEvent.click(screen.getByRole("button", { name: "Cancel" }));
});

expect(
screen.queryByText(/Are you sure you want to change your report type/i),
).not.toBeVisible();
expect(screen.queryByText(/Simple Report/i)).not.toBeInTheDocument();
expect(screen.getByText(/Annual Report/i)).toBeVisible();
});
});
4 changes: 1 addition & 3 deletions bciers/libs/components/src/modal/SimpleModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ const SimpleModal: React.FC<Props> = ({
}) => {
return (
<Modal open={open} title={title}>
<DialogContentText>
<p>{children}</p>
</DialogContentText>
<DialogContentText>{children}</DialogContentText>
<DialogActions>
<Button variant="outlined" color="primary" onClick={onCancel}>
{cancelText}
Expand Down

0 comments on commit aae7ffd

Please sign in to comment.