diff --git a/dist/amd/validation/validation-group.js b/dist/amd/validation/validation-group.js index b8871fc2..6101b341 100644 --- a/dist/amd/validation/validation-group.js +++ b/dist/amd/validation/validation-group.js @@ -111,7 +111,6 @@ define(['exports', '../validation/validation-group-builder', '../validation/vali var newPropResult = { latestValue: resultProp.latestValue }; - if (result === true || result === null || result === '') { if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { newPropResult.failingRule = null; @@ -120,14 +119,16 @@ define(['exports', '../validation/validation-group-builder', '../validation/vali resultProp.setValidity(newPropResult, true); } } else { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof result === 'string') { - newPropResult.message = result; - } else { - newPropResult.message = locale.translate(newPropResult.failingRule); + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof result === 'string') { + newPropResult.message = result; + } else { + newPropResult.message = locale.translate(newPropResult.failingRule); + } + resultProp.setValidity(newPropResult, true); } - resultProp.setValidity(newPropResult, true); } } _this3.result.checkValidity(); diff --git a/dist/amd/validation/validation-result.js b/dist/amd/validation/validation-result.js index 796e1b1a..59c07bf9 100644 --- a/dist/amd/validation/validation-result.js +++ b/dist/amd/validation/validation-result.js @@ -1,11 +1,11 @@ -define(["exports"], function (exports) { - "use strict"; +define(['exports'], function (exports) { + 'use strict'; - var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; + var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); - Object.defineProperty(exports, "__esModule", { + Object.defineProperty(exports, '__esModule', { value: true }); @@ -18,7 +18,7 @@ define(["exports"], function (exports) { } _createClass(ValidationResult, [{ - key: "addProperty", + key: 'addProperty', value: function addProperty(name) { if (!this.properties[name]) { this.properties[name] = new ValidationResultProperty(this); @@ -26,7 +26,7 @@ define(["exports"], function (exports) { return this.properties[name]; } }, { - key: "checkValidity", + key: 'checkValidity', value: function checkValidity() { for (var propertyName in this.properties) { if (!this.properties[propertyName].isValid) { @@ -36,6 +36,14 @@ define(["exports"], function (exports) { } this.isValid = true; } + }, { + key: 'clear', + value: function clear() { + for (var propertyName in this.properties) { + this.properties[propertyName].clear(); + } + this.isValid = true; + } }]); return ValidationResult; @@ -48,21 +56,35 @@ define(["exports"], function (exports) { _classCallCheck(this, ValidationResultProperty); this.group = group; - this.isValid = true; - this.isDirty = false; - this.message = null; - this.failingRule = null; this.onValidateCallbacks = []; - this.latestValue = null; + this.clear(); } _createClass(ValidationResultProperty, [{ - key: "onValidate", + key: 'clear', + value: function clear() { + this.isValid = true; + this.isDirty = false; + this.message = ''; + this.failingRule = null; + this.latestValue = null; + this.notifyObserversOfChange(); + } + }, { + key: 'onValidate', value: function onValidate(onValidateCallback) { this.onValidateCallbacks.push(onValidateCallback); } }, { - key: "setValidity", + key: 'notifyObserversOfChange', + value: function notifyObserversOfChange() { + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); + } + } + }, { + key: 'setValidity', value: function setValidity(validationResponse, shouldBeDirty) { var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; @@ -74,10 +96,7 @@ define(["exports"], function (exports) { if (this.isValid !== this.group.isValid) this.group.checkValidity(); if (notifyObservers) { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + this.notifyObserversOfChange(); } } }]); diff --git a/dist/commonjs/validation/validation-group.js b/dist/commonjs/validation/validation-group.js index 3cfce66e..3b44ad92 100644 --- a/dist/commonjs/validation/validation-group.js +++ b/dist/commonjs/validation/validation-group.js @@ -116,7 +116,6 @@ var ValidationGroup = (function () { var newPropResult = { latestValue: resultProp.latestValue }; - if (result === true || result === null || result === '') { if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { newPropResult.failingRule = null; @@ -125,14 +124,16 @@ var ValidationGroup = (function () { resultProp.setValidity(newPropResult, true); } } else { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof result === 'string') { - newPropResult.message = result; - } else { - newPropResult.message = locale.translate(newPropResult.failingRule); + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof result === 'string') { + newPropResult.message = result; + } else { + newPropResult.message = locale.translate(newPropResult.failingRule); + } + resultProp.setValidity(newPropResult, true); } - resultProp.setValidity(newPropResult, true); } } _this3.result.checkValidity(); diff --git a/dist/commonjs/validation/validation-result.js b/dist/commonjs/validation/validation-result.js index b743bbc5..3e8b24da 100644 --- a/dist/commonjs/validation/validation-result.js +++ b/dist/commonjs/validation/validation-result.js @@ -1,10 +1,10 @@ -"use strict"; +'use strict'; -var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; +var _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; -var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); +var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); -Object.defineProperty(exports, "__esModule", { +Object.defineProperty(exports, '__esModule', { value: true }); @@ -17,7 +17,7 @@ var ValidationResult = (function () { } _createClass(ValidationResult, [{ - key: "addProperty", + key: 'addProperty', value: function addProperty(name) { if (!this.properties[name]) { this.properties[name] = new ValidationResultProperty(this); @@ -25,7 +25,7 @@ var ValidationResult = (function () { return this.properties[name]; } }, { - key: "checkValidity", + key: 'checkValidity', value: function checkValidity() { for (var propertyName in this.properties) { if (!this.properties[propertyName].isValid) { @@ -35,6 +35,14 @@ var ValidationResult = (function () { } this.isValid = true; } + }, { + key: 'clear', + value: function clear() { + for (var propertyName in this.properties) { + this.properties[propertyName].clear(); + } + this.isValid = true; + } }]); return ValidationResult; @@ -47,21 +55,35 @@ var ValidationResultProperty = (function () { _classCallCheck(this, ValidationResultProperty); this.group = group; - this.isValid = true; - this.isDirty = false; - this.message = null; - this.failingRule = null; this.onValidateCallbacks = []; - this.latestValue = null; + this.clear(); } _createClass(ValidationResultProperty, [{ - key: "onValidate", + key: 'clear', + value: function clear() { + this.isValid = true; + this.isDirty = false; + this.message = ''; + this.failingRule = null; + this.latestValue = null; + this.notifyObserversOfChange(); + } + }, { + key: 'onValidate', value: function onValidate(onValidateCallback) { this.onValidateCallbacks.push(onValidateCallback); } }, { - key: "setValidity", + key: 'notifyObserversOfChange', + value: function notifyObserversOfChange() { + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); + } + } + }, { + key: 'setValidity', value: function setValidity(validationResponse, shouldBeDirty) { var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; @@ -73,10 +95,7 @@ var ValidationResultProperty = (function () { if (this.isValid !== this.group.isValid) this.group.checkValidity(); if (notifyObservers) { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + this.notifyObserversOfChange(); } } }]); diff --git a/dist/es6/validation/validation-group.js b/dist/es6/validation/validation-group.js index 638dab0f..3f1295b1 100644 --- a/dist/es6/validation/validation-group.js +++ b/dist/es6/validation/validation-group.js @@ -100,7 +100,6 @@ export class ValidationGroup { let newPropResult = { latestValue : resultProp.latestValue }; - if (result === true || result === null || result === '' ) { if(!resultProp.isValid && resultProp.failingRule === 'onValidateCallback' ) { newPropResult.failingRule = null; @@ -110,15 +109,17 @@ export class ValidationGroup { } } else { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof(result) === 'string') { - newPropResult.message = result; - } - else { - newPropResult.message = locale.translate(newPropResult.failingRule); + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof(result) === 'string') { + newPropResult.message = result; + } + else { + newPropResult.message = locale.translate(newPropResult.failingRule); + } + resultProp.setValidity(newPropResult, true); } - resultProp.setValidity(newPropResult, true); } } this.result.checkValidity(); diff --git a/dist/es6/validation/validation-result.js b/dist/es6/validation/validation-result.js index 9512217b..956aec5f 100644 --- a/dist/es6/validation/validation-result.js +++ b/dist/es6/validation/validation-result.js @@ -20,23 +20,41 @@ export class ValidationResult { } this.isValid = true; } + clear() { + for (let propertyName in this.properties) { + this.properties[propertyName].clear(); + } + this.isValid = true; + } } export class ValidationResultProperty { constructor(group) { this.group = group; + this.onValidateCallbacks = []; + this.clear(); + } + + clear(){ this.isValid = true; this.isDirty = false; - this.message = null; + this.message = ''; this.failingRule = null; - this.onValidateCallbacks = []; this.latestValue = null; + this.notifyObserversOfChange(); } onValidate(onValidateCallback) { this.onValidateCallbacks.push(onValidateCallback); } + notifyObserversOfChange(){ + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); + } + } + setValidity(validationResponse, shouldBeDirty) { var notifyObservers = (!this.isDirty && shouldBeDirty) || (this.isValid !== validationResponse.isValid) @@ -53,10 +71,7 @@ export class ValidationResultProperty { this.group.checkValidity(); if (notifyObservers) { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + this.notifyObserversOfChange(); } } } diff --git a/dist/system/validation/validation-group.js b/dist/system/validation/validation-group.js index 8204656a..ca5228bf 100644 --- a/dist/system/validation/validation-group.js +++ b/dist/system/validation/validation-group.js @@ -118,7 +118,6 @@ System.register(['../validation/validation-group-builder', '../validation/valida var newPropResult = { latestValue: resultProp.latestValue }; - if (result === true || result === null || result === '') { if (!resultProp.isValid && resultProp.failingRule === 'onValidateCallback') { newPropResult.failingRule = null; @@ -127,14 +126,16 @@ System.register(['../validation/validation-group-builder', '../validation/valida resultProp.setValidity(newPropResult, true); } } else { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof result === 'string') { - newPropResult.message = result; - } else { - newPropResult.message = locale.translate(newPropResult.failingRule); + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof result === 'string') { + newPropResult.message = result; + } else { + newPropResult.message = locale.translate(newPropResult.failingRule); + } + resultProp.setValidity(newPropResult, true); } - resultProp.setValidity(newPropResult, true); } } _this3.result.checkValidity(); diff --git a/dist/system/validation/validation-result.js b/dist/system/validation/validation-result.js index 48287c5d..cb244dcb 100644 --- a/dist/system/validation/validation-result.js +++ b/dist/system/validation/validation-result.js @@ -4,11 +4,11 @@ System.register([], function (_export) { return { setters: [], execute: function () { - "use strict"; + 'use strict'; - _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }; + _classCallCheck = function (instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } }; - _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); + _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ('value' in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })(); ValidationResult = (function () { function ValidationResult() { @@ -19,7 +19,7 @@ System.register([], function (_export) { } _createClass(ValidationResult, [{ - key: "addProperty", + key: 'addProperty', value: function addProperty(name) { if (!this.properties[name]) { this.properties[name] = new ValidationResultProperty(this); @@ -27,7 +27,7 @@ System.register([], function (_export) { return this.properties[name]; } }, { - key: "checkValidity", + key: 'checkValidity', value: function checkValidity() { for (var propertyName in this.properties) { if (!this.properties[propertyName].isValid) { @@ -37,33 +37,55 @@ System.register([], function (_export) { } this.isValid = true; } + }, { + key: 'clear', + value: function clear() { + for (var propertyName in this.properties) { + this.properties[propertyName].clear(); + } + this.isValid = true; + } }]); return ValidationResult; })(); - _export("ValidationResult", ValidationResult); + _export('ValidationResult', ValidationResult); ValidationResultProperty = (function () { function ValidationResultProperty(group) { _classCallCheck(this, ValidationResultProperty); this.group = group; - this.isValid = true; - this.isDirty = false; - this.message = null; - this.failingRule = null; this.onValidateCallbacks = []; - this.latestValue = null; + this.clear(); } _createClass(ValidationResultProperty, [{ - key: "onValidate", + key: 'clear', + value: function clear() { + this.isValid = true; + this.isDirty = false; + this.message = ''; + this.failingRule = null; + this.latestValue = null; + this.notifyObserversOfChange(); + } + }, { + key: 'onValidate', value: function onValidate(onValidateCallback) { this.onValidateCallbacks.push(onValidateCallback); } }, { - key: "setValidity", + key: 'notifyObserversOfChange', + value: function notifyObserversOfChange() { + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); + } + } + }, { + key: 'setValidity', value: function setValidity(validationResponse, shouldBeDirty) { var notifyObservers = !this.isDirty && shouldBeDirty || this.isValid !== validationResponse.isValid || this.message !== validationResponse.message; @@ -75,10 +97,7 @@ System.register([], function (_export) { if (this.isValid !== this.group.isValid) this.group.checkValidity(); if (notifyObservers) { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + this.notifyObserversOfChange(); } } }]); @@ -86,7 +105,7 @@ System.register([], function (_export) { return ValidationResultProperty; })(); - _export("ValidationResultProperty", ValidationResultProperty); + _export('ValidationResultProperty', ValidationResultProperty); } }; }); \ No newline at end of file diff --git a/src/validation/validation-group.js b/src/validation/validation-group.js index 638dab0f..3f1295b1 100644 --- a/src/validation/validation-group.js +++ b/src/validation/validation-group.js @@ -100,7 +100,6 @@ export class ValidationGroup { let newPropResult = { latestValue : resultProp.latestValue }; - if (result === true || result === null || result === '' ) { if(!resultProp.isValid && resultProp.failingRule === 'onValidateCallback' ) { newPropResult.failingRule = null; @@ -110,15 +109,17 @@ export class ValidationGroup { } } else { - newPropResult.failingRule = 'onValidateCallback'; - newPropResult.isValid = false; - if (typeof(result) === 'string') { - newPropResult.message = result; - } - else { - newPropResult.message = locale.translate(newPropResult.failingRule); + if (resultProp.isValid) { + newPropResult.failingRule = 'onValidateCallback'; + newPropResult.isValid = false; + if (typeof(result) === 'string') { + newPropResult.message = result; + } + else { + newPropResult.message = locale.translate(newPropResult.failingRule); + } + resultProp.setValidity(newPropResult, true); } - resultProp.setValidity(newPropResult, true); } } this.result.checkValidity(); diff --git a/src/validation/validation-result.js b/src/validation/validation-result.js index 9512217b..956aec5f 100644 --- a/src/validation/validation-result.js +++ b/src/validation/validation-result.js @@ -20,23 +20,41 @@ export class ValidationResult { } this.isValid = true; } + clear() { + for (let propertyName in this.properties) { + this.properties[propertyName].clear(); + } + this.isValid = true; + } } export class ValidationResultProperty { constructor(group) { this.group = group; + this.onValidateCallbacks = []; + this.clear(); + } + + clear(){ this.isValid = true; this.isDirty = false; - this.message = null; + this.message = ''; this.failingRule = null; - this.onValidateCallbacks = []; this.latestValue = null; + this.notifyObserversOfChange(); } onValidate(onValidateCallback) { this.onValidateCallbacks.push(onValidateCallback); } + notifyObserversOfChange(){ + for (var i = 0; i < this.onValidateCallbacks.length; i++) { + var callback = this.onValidateCallbacks[i]; + callback(this); + } + } + setValidity(validationResponse, shouldBeDirty) { var notifyObservers = (!this.isDirty && shouldBeDirty) || (this.isValid !== validationResponse.isValid) @@ -53,10 +71,7 @@ export class ValidationResultProperty { this.group.checkValidity(); if (notifyObservers) { - for (var i = 0; i < this.onValidateCallbacks.length; i++) { - var callback = this.onValidateCallbacks[i]; - callback(this); - } + this.notifyObserversOfChange(); } } } diff --git a/test/expectations.js b/test/expectations.js index b891c413..1b2bb0da 100644 --- a/test/expectations.js +++ b/test/expectations.js @@ -29,6 +29,8 @@ export class Expectations { } ) .then( (promiseResult) => { this.expect(promiseResult).toBe(shouldSucceed); + }, (failResult) => { + this.expect(failResult).toBe('assertion should not fail'); }); } }; diff --git a/test/on-validate.spec.js b/test/on-validate.spec.js index 004731ff..0613ca2d 100644 --- a/test/on-validate.spec.js +++ b/test/on-validate.spec.js @@ -28,6 +28,7 @@ describe('Tests on onValidate callbacks', () => { expectations.assert(subject.validation.validate(), false); expectations.expectAsync(() => { return wasCalled;}).toBe(true); + expectations.expectAsync(() => { return subject.validation.result.properties.firstName.failingRule;}).toBe('MinimumLengthValidationRule'); expectations.validate(); }); @@ -84,6 +85,16 @@ describe('Tests on onValidate callbacks', () => { expectations.validate(); }); + it('should not overwrite an already failing property', (done) => { + var expectations = new Expectations(expect, done); + var subject = TestSubject.createInstance('Bob'); + subject.validation.onValidate( () => { + return {firstName : false } + }); + expectations.assert(subject.validation.validate(), false); + expectations.expectAsync(() => { return subject.validation.result.properties.firstName.failingRule;}).toBe('MinimumLengthValidationRule'); + expectations.validate(); + }); it('should correctly handle the result of the callback if it returns a promise that returns false for a property', (done) => { diff --git a/test/validation-api.spec.js b/test/validation-api.spec.js index 6dd9b7fc..c46b63b2 100644 --- a/test/validation-api.spec.js +++ b/test/validation-api.spec.js @@ -247,6 +247,63 @@ describe('Some simple API tests', ()=>{ }); +describe('Some simple tests on .result', ()=>{ + it('on individual valid properties', (done) => { + var expectations = new Expectations(expect, done); + + let subject = { password : 'Abc*12345' }; + subject.validation = new Validation(new ObserverLocator(), new ValidationConfig()).on(subject) + .ensure('password').isNotEmpty().hasMinLength(8).isStrongPassword(); + + expectations.assert(subject.validation.validate(), true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isValid }).toBe(true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isDirty }).toBe(true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.message }).toBe(''); + expectations.expectAsync( () => { return subject.validation.result.properties.password.failingRule }).toBe(null); + expectations.validate(); + }); + it('on individual invalid properties', (done) => { + var expectations = new Expectations(expect, done); + + let subject = { password : 'abc' }; + subject.validation = new Validation(new ObserverLocator(), new ValidationConfig()).on(subject) + .ensure('password').isNotEmpty().hasMinLength(8).isStrongPassword(); + + expectations.assert(subject.validation.validate(), false); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isValid }).toBe(false); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isDirty }).toBe(true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.message }).toBe('needs to be at least 8 characters long'); + expectations.expectAsync( () => { return subject.validation.result.properties.password.failingRule }).toBe('MinimumLengthValidationRule'); + expectations.validate(); + }); + + it('on individual invalid properties after reset', (done) => { + var expectations = new Expectations(expect, done); + + let subject = { password : 'abc' }; + subject.validation = new Validation(new ObserverLocator(), new ValidationConfig()).on(subject) + .ensure('password').isNotEmpty().hasMinLength(8).isStrongPassword(); + + expectations.assert(subject.validation.validate(), false); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isValid }).toBe(false); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isDirty }).toBe(true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.message }).toBe('needs to be at least 8 characters long'); + expectations.expectAsync( () => { return subject.validation.result.properties.password.failingRule }).toBe('MinimumLengthValidationRule'); + + + expectations.expectAsync(() =>{ + subject.validation.result.clear(); + return true; + }).toBe(true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isValid }).toBe(true); + expectations.expectAsync( () => { return subject.validation.result.properties.password.isDirty }).toBe(false); + expectations.expectAsync( () => { return subject.validation.result.properties.password.message }).toBe(''); + expectations.expectAsync( () => { return subject.validation.result.properties.password.failingRule }).toBe(null); + expectations.validate(); + }); + +}); + describe('Some simple configuration API tests', ()=>{ it('on computedFrom with a single dependencies', (done) => { let subject = { password : 'Abc*12345', confirmPassword : 'Abc*12345' };