@@ -2976,6 +2976,22 @@ describe('input', function() {
2976
2976
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2977
2977
} ) ;
2978
2978
2979
+ it ( 'should set the model to the min val if it is less than the min val' , function ( ) {
2980
+ scope . value = - 10 ;
2981
+ // Default min is 0
2982
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
2983
+
2984
+ expect ( inputElm ) . toBeValid ( ) ;
2985
+ expect ( inputElm . val ( ) ) . toBe ( '0' ) ;
2986
+ expect ( scope . value ) . toBe ( 0 ) ;
2987
+
2988
+ scope . $apply ( 'value = 5; min = 10' ) ;
2989
+
2990
+ expect ( inputElm ) . toBeValid ( ) ;
2991
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2992
+ expect ( scope . value ) . toBe ( 10 ) ;
2993
+ } ) ;
2994
+
2979
2995
it ( 'should adjust the element and model value when the min value changes on-the-fly' , function ( ) {
2980
2996
scope . min = 10 ;
2981
2997
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
@@ -3009,8 +3025,9 @@ describe('input', function() {
3009
3025
} ) ;
3010
3026
3011
3027
} else {
3028
+ // input[type=range] will become type=text in browsers that don't support it
3029
+
3012
3030
it ( 'should validate if "range" is not implemented' , function ( ) {
3013
- // This will become type=text in browsers that don't support it
3014
3031
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" />' ) ;
3015
3032
3016
3033
helper . changeInputValueTo ( '5' ) ;
@@ -3024,6 +3041,34 @@ describe('input', function() {
3024
3041
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
3025
3042
} ) ;
3026
3043
3044
+ it ( 'should not assume a min val of 0 if the min interpolates to a non-number' , function ( ) {
3045
+ scope . value = - 10 ;
3046
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
3047
+
3048
+ expect ( inputElm ) . toBeValid ( ) ;
3049
+ expect ( inputElm . val ( ) ) . toBe ( '-10' ) ;
3050
+ expect ( scope . value ) . toBe ( - 10 ) ;
3051
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
3052
+
3053
+ helper . changeInputValueTo ( '-5' ) ;
3054
+ expect ( inputElm ) . toBeValid ( ) ;
3055
+ expect ( inputElm . val ( ) ) . toBe ( '-5' ) ;
3056
+ expect ( scope . value ) . toBe ( - 5 ) ;
3057
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
3058
+
3059
+ scope . $apply ( 'max = "null"' ) ;
3060
+ expect ( inputElm ) . toBeValid ( ) ;
3061
+ expect ( inputElm . val ( ) ) . toBe ( '-5' ) ;
3062
+ expect ( scope . value ) . toBe ( - 5 ) ;
3063
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3064
+
3065
+ scope . $apply ( 'max = "asdf"' ) ;
3066
+ expect ( inputElm ) . toBeValid ( ) ;
3067
+ expect ( inputElm . val ( ) ) . toBe ( '-5' ) ;
3068
+ expect ( scope . value ) . toBe ( - 5 ) ;
3069
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3070
+ } ) ;
3071
+
3027
3072
it ( 'should validate even if the min value changes on-the-fly' , function ( ) {
3028
3073
scope . min = 10 ;
3029
3074
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
@@ -3118,7 +3163,6 @@ describe('input', function() {
3118
3163
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3119
3164
} ) ;
3120
3165
3121
- // Browsers that implement range will never allow you to set the value > max value
3122
3166
it ( 'should validate' , function ( ) {
3123
3167
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
3124
3168
@@ -3133,9 +3177,16 @@ describe('input', function() {
3133
3177
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3134
3178
} ) ;
3135
3179
3136
- it ( 'should set the model to the max val if it is more than the max val' , function ( ) {
3137
- scope . value = 90 ;
3138
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
3180
+ it ( 'should set the model to the max val if it is greater than the max val' , function ( ) {
3181
+ scope . value = 110 ;
3182
+ // Default max is 100
3183
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3184
+
3185
+ expect ( inputElm ) . toBeValid ( ) ;
3186
+ expect ( inputElm . val ( ) ) . toBe ( '100' ) ;
3187
+ expect ( scope . value ) . toBe ( 100 ) ;
3188
+
3189
+ scope . $apply ( 'value = 90; max = 10' ) ;
3139
3190
3140
3191
expect ( inputElm ) . toBeValid ( ) ;
3141
3192
expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
@@ -3189,6 +3240,34 @@ describe('input', function() {
3189
3240
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3190
3241
} ) ;
3191
3242
3243
+ it ( 'should not assume a max val of 100 if the max attribute interpolates to a non-number' , function ( ) {
3244
+ scope . value = 120 ;
3245
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3246
+
3247
+ expect ( inputElm ) . toBeValid ( ) ;
3248
+ expect ( inputElm . val ( ) ) . toBe ( '120' ) ;
3249
+ expect ( scope . value ) . toBe ( 120 ) ;
3250
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3251
+
3252
+ helper . changeInputValueTo ( '140' ) ;
3253
+ expect ( inputElm ) . toBeValid ( ) ;
3254
+ expect ( inputElm . val ( ) ) . toBe ( '140' ) ;
3255
+ expect ( scope . value ) . toBe ( 140 ) ;
3256
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3257
+
3258
+ scope . $apply ( 'max = null' ) ;
3259
+ expect ( inputElm ) . toBeValid ( ) ;
3260
+ expect ( inputElm . val ( ) ) . toBe ( '140' ) ;
3261
+ expect ( scope . value ) . toBe ( 140 ) ;
3262
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3263
+
3264
+ scope . $apply ( 'max = "asdf"' ) ;
3265
+ expect ( inputElm ) . toBeValid ( ) ;
3266
+ expect ( inputElm . val ( ) ) . toBe ( '140' ) ;
3267
+ expect ( scope . value ) . toBe ( 140 ) ;
3268
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3269
+ } ) ;
3270
+
3192
3271
it ( 'should validate even if the max value changes on-the-fly' , function ( ) {
3193
3272
scope . max = 10 ;
3194
3273
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
0 commit comments