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

HAI-1939 Fix problem where validation errors would remain when filling sub-contacts in cable report application #382

Merged
merged 1 commit into from
Oct 9, 2023
Merged
Show file tree
Hide file tree
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
12 changes: 8 additions & 4 deletions src/domain/johtoselvitys/Contacts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
);
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/domain/johtoselvitys/JohtoselvitysForm.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(<JohtoselvitysContainer application={applications[0]} />);

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