Skip to content

Commit

Permalink
fix: prevent uncaught exception when submitting empty overview form
Browse files Browse the repository at this point in the history
  • Loading branch information
matthieu-foucault committed Jul 7, 2022
1 parent 6b98c27 commit 36305b9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/components/Form/ProjectForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const ProjectForm: React.FC<Props> = (props) => {
changeStatus: "pending" | "staged"
) => {
// don't trigger a change if the form data is an empty object
if (Object.keys(changeData).length === 0) return;
if (changeData && Object.keys(changeData).length === 0) return;
const updatedFormData = {
...revision.projectFormChange.newFormData,
...changeData,
Expand Down
29 changes: 29 additions & 0 deletions app/tests/unit/components/Form/ProjectForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,35 @@ describe("The Project Form", () => {
formChangePatch: { changeStatus: "staged" },
});
});

it("stages a formChange with null newFormData", () => {
const mockResolver = {
...mockQueryPayload,
ProjectRevision() {
return {
id: "Test Project Revision ID",
projectFormChange: {
id: "Test Project Form Change ID",
isUniqueValue: true,
changeStatus: "pending",
newFormData: null,
},
};
},
};

componentTestingHelper.loadQuery(mockResolver);
componentTestingHelper.renderComponent();

screen.getByText(/submit/i).click();
expect(
componentTestingHelper.environment.mock.getMostRecentOperation().request
.variables.input
).toMatchObject({
formChangePatch: { changeStatus: "staged" },
});
});

it("reverts the form_change status to 'pending' when editing", () => {
const mockResolver = {
...mockQueryPayload,
Expand Down

0 comments on commit 36305b9

Please sign in to comment.