[MNT-24909] Check if property constraint is handled by validators available in ADF (#10696)

This commit is contained in:
MichalKinas 2025-03-05 11:48:08 +01:00 committed by GitHub
parent 97970735fe
commit f7e521607c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 1 deletions

View File

@ -185,5 +185,23 @@ describe('CardViewBaseItemModel', () => {
const itemModel = new CarViewCustomItemModel(constrainedProperties);
expect(itemModel.isValid(itemModel.value)).toBe(true);
});
it('should log warning when validator type is not supported by validatorsMap', () => {
spyOn(console, 'warn');
const constrainedProperties: CardViewItemProperties = {
...properties,
value: 'test.',
constraints: [
{
id: 'custom-constraint-id',
type: 'org.test.constraint'
}
]
};
const itemModel = new CarViewCustomItemModel(constrainedProperties);
expect(itemModel.isValid(itemModel.value)).toBe(true);
expect(console.warn).toHaveBeenCalledWith('Validator for type org.test.constraint is not supported');
});
});
});

View File

@ -50,7 +50,11 @@ export abstract class CardViewBaseItemModel<T = any> {
for (const constraint of props.constraints) {
if (constraint.type !== 'LIST') {
const validatorFactory = validatorsMap[constraint.type.toLowerCase()];
this.validators.push(validatorFactory(constraint.parameters));
if (validatorFactory !== undefined) {
this.validators.push(validatorFactory(constraint.parameters));
} else {
console.warn(`Validator for type ${constraint.type} is not supported`);
}
}
}
}