diff --git a/src/domain/johtoselvitys/Contacts.tsx b/src/domain/johtoselvitys/Contacts.tsx index 5d2e9f0c8..ee2ca0a27 100644 --- a/src/domain/johtoselvitys/Contacts.tsx +++ b/src/domain/johtoselvitys/Contacts.tsx @@ -209,10 +209,14 @@ const ContactFields: React.FC<{ function fillWithOrdererInformation() { if (ordererInformation !== undefined) { - setValue(`applicationData.${customerType}.contacts.${index}`, { - ...ordererInformation, - orderer: false, - }); + setValue( + `applicationData.${customerType}.contacts.${index}`, + { + ...ordererInformation, + orderer: false, + }, + { shouldValidate: true, shouldDirty: true }, + ); } } diff --git a/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx b/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx index 9ad8d259c..512dec66b 100644 --- a/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx +++ b/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx @@ -617,4 +617,22 @@ test('Form is saved when contacts are filled with orderer information', async () expect(screen.queryByText(/hakemus tallennettu/i)).toBeInTheDocument(); expect(saveApplication).toHaveBeenCalledTimes(1); + + saveApplication.mockRestore(); +}); + +test('Form is saved when sub contacts are filled with orderer information', async () => { + const saveApplication = jest.spyOn(applicationApi, 'saveApplication'); + const { user } = render(); + + await user.click(screen.getByRole('button', { name: /yhteystiedot/i })); + await user.click( + screen.getByTestId('applicationData.contractorWithContacts.contacts.0.fillOwnInfoButton'), + ); + await user.click(screen.getByRole('button', { name: /edellinen/i })); + + expect(screen.queryByText(/hakemus tallennettu/i)).toBeInTheDocument(); + expect(saveApplication).toHaveBeenCalledTimes(1); + + saveApplication.mockRestore(); });