@@ -2901,6 +2901,97 @@ describe('input', function() {
2901
2901
expect ( scope . form . alias . $error . required ) . toBeTruthy ( ) ;
2902
2902
} ) ;
2903
2903
} ) ;
2904
+
2905
+ describe ( 'minlength' , function ( ) {
2906
+
2907
+ it ( 'should invalidate values that are shorter than the given minlength' , function ( ) {
2908
+ compileInput ( '<input type="number" ng-model="value" ng-minlength="3" />' ) ;
2909
+
2910
+ changeInputValueTo ( '12' ) ;
2911
+ expect ( inputElm ) . toBeInvalid ( ) ;
2912
+
2913
+ changeInputValueTo ( '123' ) ;
2914
+ expect ( inputElm ) . toBeValid ( ) ;
2915
+ } ) ;
2916
+
2917
+ it ( 'should listen on ng-minlength when minlength is observed' , function ( ) {
2918
+ var value = 0 ;
2919
+ compileInput ( '<input type="number" ng-model="value" ng-minlength="min" attr-capture />' ) ;
2920
+ attrs . $observe ( 'minlength' , function ( v ) {
2921
+ value = int ( attrs . minlength ) ;
2922
+ } ) ;
2923
+
2924
+ scope . $apply ( function ( ) {
2925
+ scope . min = 5 ;
2926
+ } ) ;
2927
+
2928
+ expect ( value ) . toBe ( 5 ) ;
2929
+ } ) ;
2930
+
2931
+ it ( 'should observe the standard minlength attribute and register it as a validator on the model' , function ( ) {
2932
+ compileInput ( '<input type="number" name="input" ng-model="value" minlength="{{ min }}" />' ) ;
2933
+ scope . $apply ( function ( ) {
2934
+ scope . min = 10 ;
2935
+ } ) ;
2936
+
2937
+ changeInputValueTo ( '12345' ) ;
2938
+ expect ( inputElm ) . toBeInvalid ( ) ;
2939
+ expect ( scope . form . input . $error . minlength ) . toBe ( true ) ;
2940
+
2941
+ scope . $apply ( function ( ) {
2942
+ scope . min = 5 ;
2943
+ } ) ;
2944
+
2945
+ expect ( inputElm ) . toBeValid ( ) ;
2946
+ expect ( scope . form . input . $error . minlength ) . not . toBe ( true ) ;
2947
+ } ) ;
2948
+ } ) ;
2949
+
2950
+
2951
+ describe ( 'maxlength' , function ( ) {
2952
+
2953
+ it ( 'should invalidate values that are longer than the given maxlength' , function ( ) {
2954
+ compileInput ( '<input type="number" ng-model="value" ng-maxlength="5" />' ) ;
2955
+
2956
+ changeInputValueTo ( '12345678' ) ;
2957
+ expect ( inputElm ) . toBeInvalid ( ) ;
2958
+
2959
+ changeInputValueTo ( '123' ) ;
2960
+ expect ( inputElm ) . toBeValid ( ) ;
2961
+ } ) ;
2962
+
2963
+ it ( 'should listen on ng-maxlength when maxlength is observed' , function ( ) {
2964
+ var value = 0 ;
2965
+ compileInput ( '<input type="number" ng-model="value" ng-maxlength="max" attr-capture />' ) ;
2966
+ attrs . $observe ( 'maxlength' , function ( v ) {
2967
+ value = int ( attrs . maxlength ) ;
2968
+ } ) ;
2969
+
2970
+ scope . $apply ( function ( ) {
2971
+ scope . max = 10 ;
2972
+ } ) ;
2973
+
2974
+ expect ( value ) . toBe ( 10 ) ;
2975
+ } ) ;
2976
+
2977
+ it ( 'should observe the standard maxlength attribute and register it as a validator on the model' , function ( ) {
2978
+ compileInput ( '<input type="number" name="input" ng-model="value" maxlength="{{ max }}" />' ) ;
2979
+ scope . $apply ( function ( ) {
2980
+ scope . max = 1 ;
2981
+ } ) ;
2982
+
2983
+ changeInputValueTo ( '12345' ) ;
2984
+ expect ( inputElm ) . toBeInvalid ( ) ;
2985
+ expect ( scope . form . input . $error . maxlength ) . toBe ( true ) ;
2986
+
2987
+ scope . $apply ( function ( ) {
2988
+ scope . max = 6 ;
2989
+ } ) ;
2990
+
2991
+ expect ( inputElm ) . toBeValid ( ) ;
2992
+ expect ( scope . form . input . $error . maxlength ) . not . toBe ( true ) ;
2993
+ } ) ;
2994
+ } ) ;
2904
2995
} ) ;
2905
2996
2906
2997
describe ( 'email' , function ( ) {
0 commit comments