[ACA-3742] Metadata - constraints validation (#5908)

* card min max value validator

* card match value validator

* card value length validator

* map validators to constraint type

* add minmax

* update exported validators

* register validators based on constraint type

* translate errors with parameters

* tests
This commit is contained in:
Cilibiu Bogdan
2020-07-24 18:58:07 +03:00
committed by GitHub
parent 154ca07aad
commit aa3d890342
15 changed files with 223 additions and 12 deletions

View File

@@ -56,4 +56,24 @@ describe('CardViewIntItemModel', () => {
expect(itemModel.isValid('42.3')).toBe(false, 'For "42.3" it should be false');
expect(itemModel.isValid('test')).toBe(false, 'For "test" it should be false');
});
it('should validate based on defined constraints', () => {
const constrainedProperties = {
label: 'Tribe',
value: '20',
key: 'tribe',
dataType: 'd:float',
constraints: [{
id: 'constraint-id',
type: 'MINMAX',
parameters: { minValue: 10, maxValue: 15 }
}]
};
const itemModel = new CardViewIntItemModel(constrainedProperties);
expect(itemModel.isValid(itemModel.value)).toBe(false, '20 is bigger than maximum allowed');
itemModel.value = '5';
expect(itemModel.isValid(itemModel.value)).toBe(false, '5 is less than minimum allowed');
});
});