Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Frontend] Data Entry Form Test #22

Merged
merged 2 commits into from
Sep 20, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.");
});