Skip to content

Commit

Permalink
[Frontend] Data Entry Form Test (#22)
Browse files Browse the repository at this point in the history
* Resolving TODO 13325 - fix DE test

* remove console statement

Co-authored-by: Mahmoud <mahmoud@Mahmouds-MBP.cable.rcn.com>
  • Loading branch information
mxosman and Mahmoud authored Sep 20, 2022
1 parent bb46659 commit 8b929fa
Showing 1 changed file with 57 additions and 58 deletions.
115 changes: 57 additions & 58 deletions publisher/src/components/Reports/DataEntryForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
// along with this program. If not, see <https://www.gnu.org/licenses/>.
// =============================================================================

import { render, screen, waitFor } from "@testing-library/react";
import { fireEvent, render, screen, waitFor } from "@testing-library/react";
import { runInAction } from "mobx";
import React from "react";
import { MemoryRouter, Route, Routes } from "react-router-dom";
Expand Down Expand Up @@ -109,10 +109,10 @@ describe("test data entry form", () => {
display_name:
"Does this include programmatic or medical staff?",
reporting_note: null,
required: false,
required: true,
type: "MULTIPLE_CHOICE",
multiple_choice_options: ["YES", "NO"],
value: null,
value: "YES",
},
],
disaggregations: [
Expand Down Expand Up @@ -171,58 +171,57 @@ describe("test data entry form", () => {
});
});

// TODO(#13325) JSDOM does not recognize `.animate` as a function. Will need to refactor toast or this test.

// test("expect positive number value to not add field error (formErrors should be an empty object)", async () => {
// render(
// <StoreProvider>
// <MemoryRouter initialEntries={["/reports/0"]}>
// <Routes>
// <Route path="/reports/:id" element={<ReportDataEntry />} />
// </Routes>
// </MemoryRouter>
// </StoreProvider>
// );

// const labels = await screen.findAllByLabelText("Total Staff");
// fireEvent.change(labels[0], { target: { value: "100" } });
// expect(
// rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error
// ).toBeUndefined();
// });

// test("expect negative number value to add field error (formErrors should contain an error property for the field)", async () => {
// render(
// <StoreProvider>
// <MemoryRouter initialEntries={["/reports/0"]}>
// <Routes>
// <Route path="/reports/:id" element={<ReportDataEntry />} />
// </Routes>
// </MemoryRouter>
// </StoreProvider>
// );

// const labels = await screen.findAllByLabelText("Total Staff");
// fireEvent.change(labels[0], { target: { value: "-100" } });
// expect(rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error).toBe(
// "Please enter a valid number."
// );
// });

// test("expect empty value in required field to add field error (formErrors should contain an error property for the field)", async () => {
// render(
// <StoreProvider>
// <MemoryRouter initialEntries={["/reports/0"]}>
// <Routes>
// <Route path="/reports/:id" element={<ReportDataEntry />} />
// </Routes>
// </MemoryRouter>
// </StoreProvider>
// );

// const labels = await screen.findAllByLabelText("Total Staff");
// fireEvent.change(labels[0], { target: { value: "" } });
// expect(rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error).toBe(
// "This is a required field."
// );
// });
test("expect positive number value to not add field error (formErrors should be an empty object)", async () => {
render(
<StoreProvider>
<MemoryRouter initialEntries={["/reports/0"]}>
<Routes>
<Route path="/reports/:id" element={<ReportDataEntry />} />
</Routes>
</MemoryRouter>
</StoreProvider>
);

const labels = await screen.findAllByLabelText("Total Staff");
fireEvent.change(labels[0], { target: { value: "100" } });
expect(
rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error
).toBeUndefined();
});

test("expect negative number value to add field error (formErrors should contain an error property for the field)", async () => {
render(
<StoreProvider>
<MemoryRouter initialEntries={["/reports/0"]}>
<Routes>
<Route path="/reports/:id" element={<ReportDataEntry />} />
</Routes>
</MemoryRouter>
</StoreProvider>
);

const labels = await screen.findAllByLabelText("Total Staff");
fireEvent.change(labels[0], { target: { value: "-100" } });
expect(
rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error?.message
).toBe("Please enter a valid number.");
});

test("expect empty value in metric field to add field error when there is a value in other fields such as contexts", async () => {
render(
<StoreProvider>
<MemoryRouter initialEntries={["/reports/0"]}>
<Routes>
<Route path="/reports/:id" element={<ReportDataEntry />} />
</Routes>
</MemoryRouter>
</StoreProvider>
);

const labels = await screen.findAllByLabelText("Total Staff");
fireEvent.change(labels[0], { target: { value: "" } });

expect(
rootStore.formStore.metricsValues[0].PROSECUTION_STAFF.error?.message
).toBe("You are also required to enter a value for this field.");
});

0 comments on commit 8b929fa

Please sign in to comment.