From 622caa8a7a5dc65de6d1bdb8dd5199c1e2bda9e5 Mon Sep 17 00:00:00 2001 From: Marko Haarni Date: Tue, 19 Sep 2023 12:38:10 +0300 Subject: [PATCH] HAI-1917 Fix problem where form is not saved after filling contact information with user's own information Fixed a problem in cable report application form where the form would not be saved when user clicked the Fill with own information button in contacts page and changed form page after that. This was caused by not setting the form fields as dirty. --- src/domain/johtoselvitys/Contacts.tsx | 2 +- .../johtoselvitys/JohtoselvitysForm.test.tsx | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/domain/johtoselvitys/Contacts.tsx b/src/domain/johtoselvitys/Contacts.tsx index 735d1af59..5d2e9f0c8 100644 --- a/src/domain/johtoselvitys/Contacts.tsx +++ b/src/domain/johtoselvitys/Contacts.tsx @@ -124,7 +124,7 @@ const CustomerFields: React.FC<{ invoicingOperator: null, sapCustomerNumber: null, }, - { shouldValidate: true }, + { shouldValidate: true, shouldDirty: true }, ); } } diff --git a/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx b/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx index 8dc20c97a..9ad8d259c 100644 --- a/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx +++ b/src/domain/johtoselvitys/JohtoselvitysForm.test.tsx @@ -9,6 +9,7 @@ import { HankeData } from '../types/hanke'; import hankkeet from '../mocks/data/hankkeet-data'; import applications from '../mocks/data/hakemukset-data'; import { JohtoselvitysFormValues } from './types'; +import * as applicationApi from '../application/utils'; afterEach(cleanup); @@ -603,3 +604,17 @@ test('Validation error is shown if no work is about checkbox is selected', async ); expect(screen.queryByText('Kenttä on pakollinen')).toBeInTheDocument(); }); + +test('Form is saved when 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.customerWithContacts.customer.fillOwnInfoButton'), + ); + await user.click(screen.getByRole('button', { name: /edellinen/i })); + + expect(screen.queryByText(/hakemus tallennettu/i)).toBeInTheDocument(); + expect(saveApplication).toHaveBeenCalledTimes(1); +});