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

added validation for CreateCustomReceiptForm and test. #13420

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
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,41 @@ describe('CreateCustomReceiptForm', () => {
expect(mockOnCloseForm).toHaveBeenCalledTimes(0);
});

it('Displays error when there is just one character present for layouSetId', async () => {
const user = userEvent.setup();
renderCreateCustomReceiptForm();

const layoutSetInput = screen.getByLabelText(
textMock('process_editor.configuration_panel_custom_receipt_textfield_label'),
);
await user.type(layoutSetInput, 'a');

const combobox = screen.getByRole('combobox', {
name: textMock('process_editor.configuration_panel_custom_receipt_select_data_model_label'),
});
await user.click(combobox);

const optionElement = screen.getByRole('option', { name: mockAllDataModelIds[0] });
await user.click(optionElement);
await user.keyboard('{Escape}');

const createButton = screen.getByRole('button', {
name: textMock('process_editor.configuration_panel_custom_receipt_create_button'),
});
await user.click(createButton);

const layoutIdError = screen.getByText(
textMock('process_editor.configuration_panel_custom_receipt_layout_set_name_validation'),
);
expect(layoutIdError).toBeInTheDocument();

const dataModelIdError = screen.queryByText(
textMock('process_editor.configuration_panel_custom_receipt_create_data_model_error'),
);
expect(dataModelIdError).not.toBeInTheDocument();
expect(mockOnCloseForm).toHaveBeenCalledTimes(0);
});

it('shows correct errormessage when layoutSetId is empty when typing in the textbox', async () => {
const user = userEvent.setup();
renderCreateCustomReceiptForm({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ export const CreateCustomReceiptForm = ({
const updateErrors = (customReceiptForm: CustomReceiptType) => {
const { layoutSetId, dataModelId } = customReceiptForm;
setLayoutSetError(!layoutSetId ? t('validation_errors.required') : null);
layoutSetId.length === 1 &&
setLayoutSetError(
t('process_editor.configuration_panel_custom_receipt_layout_set_name_validation'),
);

setDataModelError(
!dataModelId
Expand Down