@@ -2827,6 +2827,9 @@ describe('input', function() {
2827
2827
scope = $rootScope ;
2828
2828
} ) ;
2829
2829
2830
+ var rangeTestEl = angular . element ( '<input type="range">' ) ;
2831
+ var supportsRange = rangeTestEl [ 0 ] . type === 'range' ;
2832
+
2830
2833
it ( 'should reset the model if view is invalid' , function ( ) {
2831
2834
var inputElm = helper . compileInput ( '<input type="range" ng-model="age"/>' ) ;
2832
2835
@@ -2865,7 +2868,7 @@ describe('input', function() {
2865
2868
expect ( scope . age ) . toBe ( 50 ) ;
2866
2869
} ) ;
2867
2870
2868
- if ( msie !== 9 ) {
2871
+ if ( supportsRange ) {
2869
2872
// This behavior only applies to browsers that implement the range input, which do not
2870
2873
// allow to set a non-number value and will set the value of the input to 50 even when you
2871
2874
// change it directly on the element.
@@ -2920,7 +2923,7 @@ describe('input', function() {
2920
2923
2921
2924
describe ( 'min' , function ( ) {
2922
2925
2923
- if ( msie !== 9 ) {
2926
+ if ( supportsRange ) {
2924
2927
// Browsers that implement range will never allow you to set the value < min values
2925
2928
it ( 'should validate' , function ( ) {
2926
2929
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" />' ) ;
@@ -2935,49 +2938,55 @@ describe('input', function() {
2935
2938
expect ( scope . value ) . toBe ( 100 ) ;
2936
2939
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2937
2940
} ) ;
2938
- }
2939
2941
2940
- it ( 'should validate if "range" is not implemented' , function ( ) {
2941
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" />' ) ;
2942
-
2943
- // To test how browsers that don't implement range behave, we have to change the type, so
2944
- // that special layout and validation rules don't apply
2945
- inputElm [ 0 ] . setAttribute ( 'type' , 'text' ) ;
2942
+ it ( 'should adjust the element and model value when the min value changes on-the-fly' , function ( ) {
2943
+ scope . min = 10 ;
2944
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
2946
2945
2947
- helper . changeInputValueTo ( '5' ) ;
2948
- expect ( inputElm ) . toBeInvalid ( ) ;
2949
- expect ( scope . value ) . toBeUndefined ( ) ;
2950
- expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2946
+ helper . changeInputValueTo ( '15' ) ;
2947
+ expect ( inputElm ) . toBeValid ( ) ;
2951
2948
2952
- helper . changeInputValueTo ( '100' ) ;
2953
- expect ( inputElm ) . toBeValid ( ) ;
2954
- expect ( scope . value ) . toBe ( 100 ) ;
2955
- expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2956
- } ) ;
2949
+ scope . min = 20 ;
2950
+ scope . $digest ( ) ;
2951
+ expect ( inputElm ) . toBeValid ( ) ;
2952
+ expect ( scope . value ) . toBe ( 20 ) ;
2953
+ expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2957
2954
2958
- it ( 'should validate even if min value changes on-the-fly' , function ( ) {
2959
- scope . min = 10 ;
2960
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
2955
+ scope . min = null ;
2956
+ scope . $digest ( ) ;
2957
+ expect ( inputElm ) . toBeValid ( ) ;
2958
+ expect ( scope . value ) . toBe ( 20 ) ;
2959
+ expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2961
2960
2962
- helper . changeInputValueTo ( '15' ) ;
2963
- expect ( inputElm ) . toBeValid ( ) ;
2961
+ scope . min = '15' ;
2962
+ scope . $digest ( ) ;
2963
+ expect ( inputElm ) . toBeValid ( ) ;
2964
+ expect ( scope . value ) . toBe ( 20 ) ;
2965
+ expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2964
2966
2965
- scope . min = 20 ;
2966
- scope . $digest ( ) ;
2967
- expect ( inputElm ) . toBeInvalid ( ) ;
2967
+ scope . min = 'abc' ;
2968
+ scope . $digest ( ) ;
2969
+ expect ( inputElm ) . toBeValid ( ) ;
2970
+ expect ( scope . value ) . toBe ( 20 ) ;
2971
+ expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2972
+ } ) ;
2968
2973
2969
- scope . min = null ;
2970
- scope . $digest ( ) ;
2971
- expect ( inputElm ) . toBeValid ( ) ;
2974
+ } else {
2975
+ it ( 'should validate if "range" is not implemented' , function ( ) {
2976
+ // This will become type=text in browsers that don't support it
2977
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" />' ) ;
2972
2978
2973
- scope . min = '20' ;
2974
- scope . $digest ( ) ;
2975
- expect ( inputElm ) . toBeInvalid ( ) ;
2979
+ helper . changeInputValueTo ( '5' ) ;
2980
+ expect ( inputElm ) . toBeInvalid ( ) ;
2981
+ expect ( scope . value ) . toBeUndefined ( ) ;
2982
+ expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2976
2983
2977
- scope . min = 'abc' ;
2978
- scope . $digest ( ) ;
2979
- expect ( inputElm ) . toBeValid ( ) ;
2980
- } ) ;
2984
+ helper . changeInputValueTo ( '100' ) ;
2985
+ expect ( inputElm ) . toBeValid ( ) ;
2986
+ expect ( scope . value ) . toBe ( 100 ) ;
2987
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2988
+ } ) ;
2989
+ }
2981
2990
} ) ;
2982
2991
2983
2992
describe ( 'ngMin' , function ( ) {
@@ -3024,7 +3033,7 @@ describe('input', function() {
3024
3033
3025
3034
describe ( 'max' , function ( ) {
3026
3035
3027
- if ( msie !== 9 ) {
3036
+ if ( supportsRange ) {
3028
3037
// Browsers that implement range will never allow you to set the value > max value
3029
3038
it ( 'should validate' , function ( ) {
3030
3039
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
@@ -3048,49 +3057,87 @@ describe('input', function() {
3048
3057
expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
3049
3058
expect ( scope . value ) . toBe ( 10 ) ;
3050
3059
} ) ;
3051
- }
3052
3060
3053
- it ( 'should validate if "range" is not implemented' , function ( ) {
3054
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
3061
+ it ( 'should adjust the element and model value if the max value changes on-the-fly' , function ( ) {
3062
+ scope . max = 10 ;
3063
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3055
3064
3056
- // To test how browsers that don't implement range behave, we have to change the type, so
3057
- // that special layout and validation rules don't apply
3058
- inputElm [ 0 ] . setAttribute ( 'type' , 'text' ) ;
3065
+ helper . changeInputValueTo ( '5' ) ;
3066
+ expect ( inputElm ) . toBeValid ( ) ;
3059
3067
3060
- helper . changeInputValueTo ( '20' ) ;
3061
- expect ( inputElm ) . toBeInvalid ( ) ;
3062
- expect ( scope . value ) . toBeUndefined ( ) ;
3063
- expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
3068
+ scope . max = 0 ;
3069
+ scope . $digest ( ) ;
3070
+ expect ( inputElm ) . toBeValid ( ) ;
3071
+ expect ( scope . value ) . toBe ( 0 ) ;
3072
+ expect ( inputElm . val ( ) ) . toBe ( '0' ) ;
3064
3073
3065
- helper . changeInputValueTo ( '0' ) ;
3066
- expect ( inputElm ) . toBeValid ( ) ;
3067
- expect ( scope . value ) . toBe ( 0 ) ;
3068
- expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3069
- } ) ;
3074
+ scope . max = null ;
3075
+ scope . $digest ( ) ;
3076
+ expect ( inputElm ) . toBeValid ( ) ;
3077
+ expect ( scope . value ) . toBe ( 0 ) ;
3078
+ expect ( inputElm . val ( ) ) . toBe ( '0' ) ;
3070
3079
3071
- it ( 'should validate even if max value changes on-the-fly' , function ( ) {
3072
- scope . max = 10 ;
3073
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3080
+ scope . max = '4' ;
3081
+ scope . $digest ( ) ;
3082
+ expect ( inputElm ) . toBeValid ( ) ;
3083
+ expect ( scope . value ) . toBe ( 0 ) ;
3084
+ expect ( inputElm . val ( ) ) . toBe ( '0' ) ;
3074
3085
3075
- helper . changeInputValueTo ( '5' ) ;
3076
- expect ( inputElm ) . toBeValid ( ) ;
3086
+ scope . max = 'abc' ;
3087
+ scope . $digest ( ) ;
3088
+ expect ( inputElm ) . toBeValid ( ) ;
3089
+ expect ( scope . value ) . toBe ( 0 ) ;
3090
+ expect ( inputElm . val ( ) ) . toBe ( '0' ) ;
3091
+ } ) ;
3077
3092
3078
- scope . max = 0 ;
3079
- scope . $digest ( ) ;
3080
- expect ( inputElm ) . toBeInvalid ( ) ;
3093
+ } else {
3094
+ it ( 'should validate if "range" is not implemented' , function ( ) {
3095
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
3081
3096
3082
- scope . max = null ;
3083
- scope . $digest ( ) ;
3084
- expect ( inputElm ) . toBeValid ( ) ;
3097
+ helper . changeInputValueTo ( '20' ) ;
3098
+ expect ( inputElm ) . toBeInvalid ( ) ;
3099
+ expect ( scope . value ) . toBeUndefined ( ) ;
3100
+ expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
3085
3101
3086
- scope . max = '4' ;
3087
- scope . $digest ( ) ;
3088
- expect ( inputElm ) . toBeInvalid ( ) ;
3102
+ helper . changeInputValueTo ( '0' ) ;
3103
+ expect ( inputElm ) . toBeValid ( ) ;
3104
+ expect ( scope . value ) . toBe ( 0 ) ;
3105
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3106
+ } ) ;
3089
3107
3090
- scope . max = 'abc' ;
3091
- scope . $digest ( ) ;
3092
- expect ( inputElm ) . toBeValid ( ) ;
3093
- } ) ;
3108
+ it ( 'should validate even if the max value changes on-the-fly' , function ( ) {
3109
+ scope . max = 10 ;
3110
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3111
+
3112
+ helper . changeInputValueTo ( '5' ) ;
3113
+ expect ( inputElm ) . toBeValid ( ) ;
3114
+ expect ( scope . value ) . toBe ( 5 ) ;
3115
+
3116
+ scope . max = 0 ;
3117
+ scope . $digest ( ) ;
3118
+ expect ( inputElm ) . toBeInvalid ( ) ;
3119
+ expect ( scope . value ) . toBe ( 5 ) ;
3120
+ expect ( inputElm . val ( ) ) . toBe ( '5' ) ;
3121
+
3122
+ scope . max = null ;
3123
+ scope . $digest ( ) ;
3124
+ expect ( inputElm ) . toBeValid ( ) ;
3125
+ expect ( scope . value ) . toBe ( 5 ) ;
3126
+ expect ( inputElm . val ( ) ) . toBe ( '5' ) ;
3127
+
3128
+ scope . max = '4' ;
3129
+ scope . $digest ( ) ;
3130
+ expect ( inputElm ) . toBeInvalid ( ) ;
3131
+ expect ( scope . value ) . toBe ( 5 ) ;
3132
+ expect ( inputElm . val ( ) ) . toBe ( '5' ) ;
3133
+
3134
+ scope . max = 'abc' ;
3135
+ scope . $digest ( ) ;
3136
+ expect ( inputElm ) . toBeValid ( ) ;
3137
+ expect ( scope . value ) . toBe ( 5 ) ;
3138
+ expect ( inputElm . val ( ) ) . toBe ( '5' ) ;
3139
+ } ) ;
3140
+ }
3094
3141
} ) ;
3095
3142
3096
3143
describe ( 'ngMax' , function ( ) {
@@ -3132,16 +3179,19 @@ describe('input', function() {
3132
3179
scope . $digest ( ) ;
3133
3180
expect ( inputElm ) . toBeValid ( ) ;
3134
3181
} ) ;
3182
+
3135
3183
} ) ;
3136
3184
3137
- it ( 'should set the correct initial view and model when min and max are specified' , function ( ) {
3138
- scope . max = 80 ;
3139
- scope . min = 40 ;
3140
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3185
+ if ( supportsRange ) {
3186
+ it ( 'should keep the initial default value when min and max are specified' , function ( ) {
3187
+ scope . max = 80 ;
3188
+ scope . min = 40 ;
3189
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3141
3190
3142
- expect ( inputElm . val ( ) ) . toBe ( '60' ) ;
3143
- expect ( scope . value ) . toBe ( 60 ) ;
3144
- } ) ;
3191
+ expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
3192
+ expect ( scope . value ) . toBe ( 50 ) ;
3193
+ } ) ;
3194
+ }
3145
3195
3146
3196
} ) ;
3147
3197
0 commit comments