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