diff --git a/client/core/src/directives/specs/validation.spec.js b/client/core/src/directives/specs/validation.spec.js index 5a819aced..f13f0024f 100644 --- a/client/core/src/directives/specs/validation.spec.js +++ b/client/core/src/directives/specs/validation.spec.js @@ -145,36 +145,42 @@ describe('Directive validation', () => { }); }); - // it(`should not validate the name as it's format is incorrect`, () => { - // let html = `
`; - // let validations = {User: {validations: {name: [{validation: 'presence'}]}}}; - // compile(html, validations, 'spiderman'); - // scope.user.name = ''; - // scope.$digest(); + describe('Validator inclusion()', () => { + it('should not validate the phone number as it is not an integer', () => { + let html = ``; + let validations = {User: {validations: {phone: [{validation: 'inclusion'}]}}}; + compile(html, validations, 'spiderman'); + scope.user.phone = 'this is not a phone number!'; + scope.$digest(); - // expect(element[0].classList).toContain('ng-invalid'); - // expect(element[0].classList).not.toContain('ng-valid'); - // }); + expect(element[0].classList).toContain('ng-invalid'); + expect(element[0].classList).not.toContain('ng-valid'); + }); + }); - // it(`should validate the email as it's format is correct`, () => { - // let html = ``; - // let validations = {User: {validations: {email: [{validation: 'presence'}]}}}; - // compile(html, validations, 'spiderman'); - // scope.user.email = 'user@verdnatura.es'; - // scope.$digest(); + describe('Validator exclusion()', () => { + it('should validate the phone number as it is an integer', () => { + let html = ``; + let validations = {User: {validations: {phone: [{validation: 'exclusion'}]}}}; + compile(html, validations, 'spiderman'); + scope.user.phone = '555555555'; + scope.$digest(); - // expect(element[0].classList).toContain('ng-valid'); - // expect(element[0].classList).not.toContain('ng-invalid'); - // }); + expect(element[0].classList).toContain('ng-valid'); + expect(element[0].classList).not.toContain('ng-invalid'); + }); + }); - // it(`should not validate the email as it's missing the @`, () => { - // let html = ``; - // let validations = {User: {validations: {email: [{validation: 'presence'}]}}}; - // compile(html, validations, 'spiderman'); - // scope.user.email = 'userverdnatura.es'; - // scope.$digest(); + describe('Validator format()', () => { + it('should not validate the email number as it doesnt contain @', () => { + let html = ``; + let validations = {User: {validations: {email: [{validation: 'format', with: '@'}]}}}; + compile(html, validations, 'spiderman'); + scope.user.email = 'userverdnatura.es'; + scope.$digest(); - // expect(element[0].classList).toContain('ng-invalid'); - // expect(element[0].classList).not.toContain('ng-valid'); - // }); + expect(element[0].classList).toContain('ng-invalid'); + expect(element[0].classList).not.toContain('ng-valid'); + }); + }); }); diff --git a/client/core/src/lib/validator.js b/client/core/src/lib/validator.js index 018d1b26e..c29142653 100644 --- a/client/core/src/lib/validator.js +++ b/client/core/src/lib/validator.js @@ -34,19 +34,19 @@ export const validators = { } else if (!validator.isNumeric(value)) throw new Error(`Value should be a number`); }, - inclusion: function(value, conf) { + inclusion: (value, conf) => { if (!validator.isIn(value, conf.in)) throw new Error(`Invalid value`); }, - exclusion: function(value, conf) { + exclusion: (value, conf) => { if (validator.isIn(value, conf.in)) throw new Error(`Invalid value`); }, - format: function(value, conf) { + format: (value, conf) => { if (!validator.matches(value, conf.with)) throw new Error(`Invalid value`); }, - custom: function(value, conf) { + custom: (value, conf) => { if (!conf.bindedFunction(value)) throw new Error(`Invalid value`); }