Skip to content

Commit

Permalink
HAI-1917 Fix problem where form is not saved after filling contact in…
Browse files Browse the repository at this point in the history
…formation 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.
  • Loading branch information
markohaarni committed Sep 19, 2023
1 parent 0793950 commit 622caa8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/domain/johtoselvitys/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ const CustomerFields: React.FC<{
invoicingOperator: null,
sapCustomerNumber: null,
},
{ shouldValidate: true },
{ shouldValidate: true, shouldDirty: true },
);
}
}
Expand Down
15 changes: 15 additions & 0 deletions src/domain/johtoselvitys/JohtoselvitysForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(<JohtoselvitysContainer application={applications[0]} />);

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);
});

0 comments on commit 622caa8

Please sign in to comment.