Skip to content

Commit

Permalink
add validation test
Browse files Browse the repository at this point in the history
  • Loading branch information
lassopicasso committed Nov 1, 2024
1 parent e96aeee commit 15ac234
Showing 1 changed file with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand All @@ -60,7 +81,11 @@ const renderCreateNewSubformLayoutSet = (
queryClient.setQueryData([QueryKey.LayoutSets, org, app], layoutSetsMock);
return renderWithProviders(
<AppContext.Provider value={{ ...appContextMock }}>
<CreateNewSubformLayoutSet onSubformCreated={onSubformCreatedMock} {...componentProps} />
<CreateNewSubformLayoutSet
onSubformCreated={onSubformCreatedMock}
layoutSets={layoutSets}
{...componentProps}
/>
</AppContext.Provider>,
{ queryClient },
);
Expand Down

0 comments on commit 15ac234

Please sign in to comment.