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

[FC-123783] User is not shown with the correct error message on exceeding the limit for internal name field #916

Merged
merged 7 commits into from
May 21, 2024
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 @@ -1053,7 +1053,15 @@ export class FieldEditor {

let strInternalName = '';
let boolInternalNameUpdated = false;
if ((!this.isInternalNameEdited && this.isNewField) || field.isNew) {
const objMaxLimitFieldInternalName = getMaxLimitProperty(
this.productName,
'maxInternalNameChars'
);
if (
((!this.isInternalNameEdited && this.isNewField) || field.isNew) &&
objMaxLimitFieldInternalName &&
strInputValue.length <= objMaxLimitFieldInternalName.count
) {
strInternalName = deriveInternalNameFromLabel(strInputValue);
boolInternalNameUpdated = true;
}
Expand Down Expand Up @@ -1088,8 +1096,7 @@ export class FieldEditor {
'maxInternalNameChars'
);
if (
!this.internalNameWarningMessage &&
this.internalNameWarningMessage !== '' &&
this.internalNameWarningMessage === '' &&
objMaxLimitFieldName &&
strInternalName.length >= objMaxLimitFieldName.count
) {
Expand All @@ -1099,6 +1106,8 @@ export class FieldEditor {
count: objMaxLimitFieldName.count,
}
);
} else {
this.internalNameWarningMessage = '';
}

if (!this.isInternalNameEdited || field.isNew) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
buildChoicesFromText,
getParentId,
getChildChoices,
getMaximumLimitsConfig,
} from './form-builder-utils';

describe('getFieldBasedOnLevel', () => {
Expand Down Expand Up @@ -586,3 +587,47 @@ describe('getChildChoices', () => {
});
});
});
describe('getMaximumLimitsConfig', () => {
it('returns maximum limits config for CUSTOM_OBJECTS', () => {
const formMapper = {
CUSTOM_OBJECTS: {
maximumLimits: {
DECIMAL: { count: 20, message: 'maximumLimits.fields' },
},
},
};
const result = getMaximumLimitsConfig();
expect(result.DECIMAL.count).toEqual(
formMapper.CUSTOM_OBJECTS.maximumLimits.DECIMAL.count
);
});

it('returns maximum limits config for Internal Name', () => {
const formMapper = {
CUSTOM_OBJECTS: {
maximumLimits: {
maxInternalNameChars: {
count: 50,
message: 'maximumLimits.maxCharsWarning',
},
},
},
};
const result = getMaximumLimitsConfig();
expect(result.maxInternalNameChars.count).toEqual(
formMapper.CUSTOM_OBJECTS.maximumLimits.maxInternalNameChars.count
);
});

it('returns null when productName is not found in formMapper', () => {
const formMapper = {
OTHER_PRODUCT: {
maximumLimits: {
DECIMAL: { count: 20, message: 'maximumLimits.fields' },
},
},
};
const result = getMaximumLimitsConfig('OTHER_PRODUCT');
expect(result).toBeNull();
});
});
Loading