Skip to content

Commit

Permalink
[MD] Validate length of title to be less or equal than 32 characters
Browse files Browse the repository at this point in the history
Signed-off-by: Zhongnan Su <szhongna@amazon.com>
  • Loading branch information
zhongnansu committed Apr 15, 2024
1 parent 476cffc commit 2868999
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ describe('DataSourceManagement: Form Validation', () => {
);
expect(result).toBe(false);
});
test('should fail validation when title is longer than 32 characters', () => {
form.title = 'test'.repeat(10);
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
expect(result).toBe(false);
});
test('should fail validation when endpoint is not valid', () => {
form.endpoint = mockDataSourceAttributesWithAuth.endpoint;
const result = performDataSourceFormValidation(form, [], '', authenticationMethodRegistry);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export const isTitleValid = (
error: '',
};
/* Title validation */
if (!title?.trim?.().length) {
if (!title.trim().length) {
isValid.valid = false;
} else if (
title.toLowerCase() !== existingTitle.toLowerCase() &&
Expand All @@ -62,6 +62,12 @@ export const isTitleValid = (
isValid.error = i18n.translate('dataSourcesManagement.validation.titleExists', {
defaultMessage: 'This title is already in use',
});
} else if (title.length > 32) {
/* title length validation */
isValid.valid = false;
isValid.error = i18n.translate('dataSourcesManagement.validation.titleLength', {
defaultMessage: 'Title must be less than 32 characters',
});
}
return isValid;
};
Expand Down

0 comments on commit 2868999

Please sign in to comment.