@@ -2919,6 +2919,47 @@ describe('input', function() {
2919
2919
} ) ;
2920
2920
} ) ;
2921
2921
2922
+ describe ( 'ngMin' , function ( ) {
2923
+
2924
+ it ( 'should validate' , function ( ) {
2925
+ compileInput ( '<input type="number" ng-model="value" name="alias" ng-min="50" />' ) ;
2926
+
2927
+ changeInputValueTo ( '1' ) ;
2928
+ expect ( inputElm ) . toBeInvalid ( ) ;
2929
+ expect ( scope . value ) . toBeFalsy ( ) ;
2930
+ expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2931
+
2932
+ changeInputValueTo ( '100' ) ;
2933
+ expect ( inputElm ) . toBeValid ( ) ;
2934
+ expect ( scope . value ) . toBe ( 100 ) ;
2935
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2936
+ } ) ;
2937
+
2938
+ it ( 'should validate even if the ngMin value changes on-the-fly' , function ( ) {
2939
+ scope . min = 10 ;
2940
+ compileInput ( '<input type="number" ng-model="value" name="alias" ng-min="min" />' ) ;
2941
+
2942
+ changeInputValueTo ( '15' ) ;
2943
+ expect ( inputElm ) . toBeValid ( ) ;
2944
+
2945
+ scope . min = 20 ;
2946
+ scope . $digest ( ) ;
2947
+ expect ( inputElm ) . toBeInvalid ( ) ;
2948
+
2949
+ scope . min = null ;
2950
+ scope . $digest ( ) ;
2951
+ expect ( inputElm ) . toBeValid ( ) ;
2952
+
2953
+ scope . min = '20' ;
2954
+ scope . $digest ( ) ;
2955
+ expect ( inputElm ) . toBeInvalid ( ) ;
2956
+
2957
+ scope . min = 'abc' ;
2958
+ scope . $digest ( ) ;
2959
+ expect ( inputElm ) . toBeValid ( ) ;
2960
+ } ) ;
2961
+ } ) ;
2962
+
2922
2963
2923
2964
describe ( 'max' , function ( ) {
2924
2965
@@ -2961,6 +3002,47 @@ describe('input', function() {
2961
3002
} ) ;
2962
3003
} ) ;
2963
3004
3005
+ describe ( 'ngMax' , function ( ) {
3006
+
3007
+ it ( 'should validate' , function ( ) {
3008
+ compileInput ( '<input type="number" ng-model="value" name="alias" ng-max="5" />' ) ;
3009
+
3010
+ changeInputValueTo ( '20' ) ;
3011
+ expect ( inputElm ) . toBeInvalid ( ) ;
3012
+ expect ( scope . value ) . toBeUndefined ( ) ;
3013
+ expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
3014
+
3015
+ changeInputValueTo ( '0' ) ;
3016
+ expect ( inputElm ) . toBeValid ( ) ;
3017
+ expect ( scope . value ) . toBe ( 0 ) ;
3018
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3019
+ } ) ;
3020
+
3021
+ it ( 'should validate even if the ngMax value changes on-the-fly' , function ( ) {
3022
+ scope . max = 10 ;
3023
+ compileInput ( '<input type="number" ng-model="value" name="alias" ng-max="max" />' ) ;
3024
+
3025
+ changeInputValueTo ( '5' ) ;
3026
+ expect ( inputElm ) . toBeValid ( ) ;
3027
+
3028
+ scope . max = 0 ;
3029
+ scope . $digest ( ) ;
3030
+ expect ( inputElm ) . toBeInvalid ( ) ;
3031
+
3032
+ scope . max = null ;
3033
+ scope . $digest ( ) ;
3034
+ expect ( inputElm ) . toBeValid ( ) ;
3035
+
3036
+ scope . max = '4' ;
3037
+ scope . $digest ( ) ;
3038
+ expect ( inputElm ) . toBeInvalid ( ) ;
3039
+
3040
+ scope . max = 'abc' ;
3041
+ scope . $digest ( ) ;
3042
+ expect ( inputElm ) . toBeValid ( ) ;
3043
+ } ) ;
3044
+ } ) ;
3045
+
2964
3046
2965
3047
describe ( 'required' , function ( ) {
2966
3048
0 commit comments