From 62c05d1807323ab733192ea7f05972df3ff91ca5 Mon Sep 17 00:00:00 2001 From: HowardRichards Date: Fri, 22 Nov 2013 09:38:52 +0000 Subject: [PATCH] Fixed failing code, reran tests - now passing. --- valerie/valerie-tests.ts | 20 +++++++++++--------- valerie/valerie.d.ts | 37 +++++++++++++++++++++++++++++-------- 2 files changed, 40 insertions(+), 17 deletions(-) diff --git a/valerie/valerie-tests.ts b/valerie/valerie-tests.ts index e826b24c93..bf9ce78806 100644 --- a/valerie/valerie-tests.ts +++ b/valerie/valerie-tests.ts @@ -51,7 +51,7 @@ function ObservableValidationTypes() { .end(); //array - var t6 = ko.observableArray([]) + var t6 = ko.observableArray([]) .validate() .end(); } @@ -67,23 +67,25 @@ function RuleTests() { // various values used in rule tests var dummyRule: Valerie.IRule = { test: null, defaultOptions: null }; + // valerie supports both value and function arguments in many cases + var stringValue = ""; - var stringFN = function () { return ""; } + var stringFN = function () { return stringValue; } var numberValue = 1; - var numberFN = function () { return 2 } + var numberFN = function () { return numberValue; } var booleanValue = false; - var booleanFN = ko.observable(true); + var booleanFN = function () { return booleanValue; } var dateValue = new Date(); - var dateFN = function () { return new Date(); } + var dateFN = function () { return dateValue; } - var anyValue = {}; - var anyFN = function () { return {}; } + var anyValue = {}; + var anyFN = function () { return anyValue; } - var arrayValue = []; - var arrayFN = function () { return []; } + var arrayValue = []; + var arrayFN = function () { return arrayValue; } var regexpValue = /\d+/; diff --git a/valerie/valerie.d.ts b/valerie/valerie.d.ts index 75afeaa115..847e0a7a0f 100644 --- a/valerie/valerie.d.ts +++ b/valerie/valerie.d.ts @@ -3,6 +3,8 @@ // Definitions by: Howard Richards // Definitions: https://github.com/borisyankov/DefinitelyTyped +/// + /** * * Extensions to KO functions to provide validation @@ -19,7 +21,20 @@ interface KnockoutComputed { interface KnockoutObservableArray { validate(validationOptions?: Valerie.ValidationOptions): Valerie.PropertyValidationState>; - // starts model validation for array +} + + +interface KnockoutObservableArrayFunctions { + /** + * Creates and sets a model validation state on a Knockout observable array.
+ * [fluent] + * @name ko.observableArray#validateAsModel + * @method + * @fluent + * @param {valerie.ModelValidationState.options} [validationOptions] the options to use when creating the + * validation state + * @return {valerie.ModelValidationState} the validation state belonging to the observable array + */ validateAsModel(): Valerie.ValidatableModel>; } @@ -248,8 +263,7 @@ declare module Valerie { // ctor new: (model: any, options?: ModelValidationStateOptions) => ModelValidationState; - addValidationStates(any): void; - + addValidationStates(validationStateOrStates: any): void; model: any; options?: ModelValidationStateOptions @@ -278,7 +292,14 @@ declare module Valerie { // fluent methods (can be chanined): - addRule(IRule): PropertyValidationState; + /** + * Adds a rule to the chain of rules used to validate the property's value.
+ * [fluent] + * @fluent + * @param {valerie.IRule} rule the rule to add + * @return {valerie.PropertyValidationState} + */ + addRule(rule: IRule): PropertyValidationState; applicable(value: boolean): PropertyValidationState; applicable(fn: () => boolean): PropertyValidationState; currencyMajor(options?: ValidationOptions): PropertyValidationState; @@ -365,7 +386,7 @@ declare module Valerie { passed: boolean; //true if the activity passed validation pending: boolean; //true if the activity hasn't yet completed message: string; //a message from the activity - new (state: any, message?: string); + new: (state: any, message?: string) => ValidationResult; //TODO: not added static members/methods createFailedResult(message: string): ValidationResult; @@ -390,7 +411,7 @@ declare module Valerie { } interface ValidatableModel { - name: (string) => PropertyValidationState; + name: (value:string) => PropertyValidationState; // return original observableArray end: () => T; @@ -431,10 +452,10 @@ declare module Valerie { currencyMinorUnitPlaces: number): NumericHelper; // Informs whether the given numeric string represents a currency value with major units only. - isCurrencyMajor(numericString): boolean; + isCurrencyMajor(numericString: string): boolean; // Informs whether the given numeric string represents a currency value with major units and optionally minor units. - isCurrencyMajorMinor(numericString): boolean; + isCurrencyMajorMinor(numericString: string): boolean; // Informs whether the given numeric string represents a non-integer numeric value. isFloat(numericString: string): boolean;