From 15ac234cdd006c36a508e18bb38fd45b8fd5de9c Mon Sep 17 00:00:00 2001 From: lassopicasso Date: Fri, 1 Nov 2024 14:32:12 +0100 Subject: [PATCH] add validation test --- .../CreateNewSubformLayoutSet.test.tsx | 27 ++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/EditLayoutSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.test.tsx b/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/EditLayoutSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.test.tsx index 8a918996a9a..47bcb935ae0 100644 --- a/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/EditLayoutSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.test.tsx +++ b/frontend/packages/ux-editor/src/components/Properties/PropertiesHeader/EditLayoutSetForSubform/EditLayoutSet/CreateNewSubformLayoutSet/CreateNewSubformLayoutSet.test.tsx @@ -50,6 +50,27 @@ describe('CreateNewSubformLayoutSet ', () => { await waitFor(() => expect(onSubformCreatedMock).toHaveBeenCalledTimes(1)); expect(onSubformCreatedMock).toHaveBeenCalledWith('NewSubform'); }); + + it('disables the save button when input is invalid', async () => { + const user = userEvent.setup(); + renderCreateNewSubformLayoutSet(); + + const saveButton = screen.getByRole('button', { name: textMock('general.close') }); + expect(saveButton).toBeDisabled(); + + const input = screen.getByRole('textbox'); + + await user.type(input, 'æøå'); + expect(saveButton).toBeDisabled(); + + await user.clear(input); + await user.type(input, 'e re a'); + expect(saveButton).toBeDisabled(); + + await user.clear(input); + await user.type(input, 'NewSubform'); + expect(saveButton).not.toBeDisabled(); + }); }); const renderCreateNewSubformLayoutSet = ( @@ -60,7 +81,11 @@ const renderCreateNewSubformLayoutSet = ( queryClient.setQueryData([QueryKey.LayoutSets, org, app], layoutSetsMock); return renderWithProviders( - + , { queryClient }, );