mirror of
https://github.com/Alfresco/alfresco-ng2-components.git
synced 2025-07-24 17:32:15 +00:00
[ACS-6586] "Folder" property complains about letters provided into "Name" input field (#9365)
This commit is contained in:
@@ -119,5 +119,63 @@ describe('CardViewBaseItemModel', () => {
|
|||||||
expect(isValid).toBe(false);
|
expect(isValid).toBe(false);
|
||||||
expect(itemModel.getValidationErrors('test-against-this')).toEqual([validator1, validator3 ]);
|
expect(itemModel.getValidationErrors('test-against-this')).toEqual([validator1, validator3 ]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should validate field with special character and return false when there is REGEX constraint and requiresMatch is false', () => {
|
||||||
|
const constrainedProperties: CardViewItemProperties = {
|
||||||
|
...properties,
|
||||||
|
value: 'test.',
|
||||||
|
constraints: [{
|
||||||
|
id: 'constraint-id',
|
||||||
|
type: 'REGEX',
|
||||||
|
parameters: { expression: '(.*[\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)', requiresMatch: false }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemModel = new CarViewCustomItemModel(constrainedProperties);
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate field without special character and return true when there is REGEX constraint and requiresMatch is false', () => {
|
||||||
|
const constrainedProperties: CardViewItemProperties = {
|
||||||
|
...properties,
|
||||||
|
constraints: [{
|
||||||
|
id: 'constraint-id',
|
||||||
|
type: 'REGEX',
|
||||||
|
parameters: { expression: '(.*[\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)', requiresMatch: false }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemModel = new CarViewCustomItemModel(constrainedProperties);
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(true);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate field without special character and return false when there is REGEX constraint and requiresMatch is true', () => {
|
||||||
|
const constrainedProperties: CardViewItemProperties = {
|
||||||
|
...properties,
|
||||||
|
constraints: [{
|
||||||
|
id: 'constraint-id',
|
||||||
|
type: 'REGEX',
|
||||||
|
parameters: { expression: '(.*[\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)', requiresMatch: true }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemModel = new CarViewCustomItemModel(constrainedProperties);
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should validate field without special character and return true when there is REGEX constraint and requiresMatch is true', () => {
|
||||||
|
const constrainedProperties: CardViewItemProperties = {
|
||||||
|
...properties,
|
||||||
|
value: 'test.',
|
||||||
|
constraints: [{
|
||||||
|
id: 'constraint-id',
|
||||||
|
type: 'REGEX',
|
||||||
|
parameters: { expression: '(.*[\\"\\*\\\\\\>\\<\\?\\/\\:\\|]+.*)|(.*[\\.]?.*[\\.]+$)|(.*[ ]+$)', requiresMatch: true }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemModel = new CarViewCustomItemModel(constrainedProperties);
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@@ -86,16 +86,15 @@ describe('CardViewTextItemModel', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should validate based on defined constraints', () => {
|
it('should validate based on defined constraints and require a match to be valid', () => {
|
||||||
const constrainedProperties = {
|
const constrainedProperties: CardViewTextItemProperties = {
|
||||||
label: 'Tribe',
|
label: 'Tribe',
|
||||||
value: 'test',
|
value: 'test',
|
||||||
key: 'tribe',
|
key: 'tribe',
|
||||||
dataType: 'd:text',
|
|
||||||
constraints: [{
|
constraints: [{
|
||||||
id: 'constraint-id',
|
id: 'constraint-id',
|
||||||
type: 'REGEX',
|
type: 'REGEX',
|
||||||
parameters: { expression: '^(?=.*test).*' }
|
parameters: { expression: '^(?=.*test).*', requiresMatch: true }
|
||||||
}]
|
}]
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -105,4 +104,23 @@ describe('CardViewTextItemModel', () => {
|
|||||||
itemModel.value = 'dummy';
|
itemModel.value = 'dummy';
|
||||||
expect(itemModel.isValid(itemModel.value)).toBe(false, '`dummy` is not a constraint expression pattern');
|
expect(itemModel.isValid(itemModel.value)).toBe(false, '`dummy` is not a constraint expression pattern');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should validate based on defined constraints and not require a match to be valid', () => {
|
||||||
|
const constrainedProperties: CardViewTextItemProperties = {
|
||||||
|
label: 'Tribe',
|
||||||
|
value: 'test',
|
||||||
|
key: 'tribe',
|
||||||
|
constraints: [{
|
||||||
|
id: 'constraint-id',
|
||||||
|
type: 'REGEX',
|
||||||
|
parameters: { expression: '^(?=.*test).*', requiresMatch: false }
|
||||||
|
}]
|
||||||
|
};
|
||||||
|
|
||||||
|
const itemModel = new CardViewTextItemModel(constrainedProperties);
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(false);
|
||||||
|
|
||||||
|
itemModel.value = 'dummy';
|
||||||
|
expect(itemModel.isValid(itemModel.value)).toBe(true);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@@ -20,15 +20,17 @@ import { CardViewItemValidator } from '../interfaces/card-view.interfaces';
|
|||||||
export interface MatchValidatorParams {
|
export interface MatchValidatorParams {
|
||||||
expression: string;
|
expression: string;
|
||||||
flags?: string;
|
flags?: string;
|
||||||
|
requiresMatch?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
export class CardViewItemMatchValidator implements CardViewItemValidator {
|
export class CardViewItemMatchValidator implements CardViewItemValidator {
|
||||||
message = 'CORE.CARDVIEW.VALIDATORS.MATCH_VALIDATION_ERROR';
|
message = 'CORE.CARDVIEW.VALIDATORS.MATCH_VALIDATION_ERROR';
|
||||||
|
|
||||||
constructor(private expression: string, private flags?: string) {}
|
constructor(private expression: string, private flags?: string, private requiresMatch?: boolean) {
|
||||||
|
}
|
||||||
|
|
||||||
isValid(value: string): boolean {
|
isValid(value: string): boolean {
|
||||||
const regex = new RegExp(this.expression, this.flags);
|
const regex = new RegExp(this.expression, this.flags);
|
||||||
return value === '' || regex.test(value);
|
return value === '' || this.requiresMatch ? regex.test(value) : !regex.test(value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -21,7 +21,7 @@ import { CardViewItemLengthValidator, LengthValidatorParams } from './card-view-
|
|||||||
|
|
||||||
const validators = {
|
const validators = {
|
||||||
minmax: (parameters: MinMaxValidatorParams) => new CardViewItemMinMaxValidator(parameters.minValue, parameters.maxValue),
|
minmax: (parameters: MinMaxValidatorParams) => new CardViewItemMinMaxValidator(parameters.minValue, parameters.maxValue),
|
||||||
regex: (parameters: MatchValidatorParams) => new CardViewItemMatchValidator(parameters.expression),
|
regex: (parameters: MatchValidatorParams) => new CardViewItemMatchValidator(parameters.expression, parameters.flags, parameters.requiresMatch),
|
||||||
length: (parameters: LengthValidatorParams) => new CardViewItemLengthValidator(parameters.minLength, parameters.maxLength)
|
length: (parameters: LengthValidatorParams) => new CardViewItemLengthValidator(parameters.minLength, parameters.maxLength)
|
||||||
};
|
};
|
||||||
export default validators;
|
export default validators;
|
||||||
|
Reference in New Issue
Block a user