@@ -2877,7 +2877,7 @@ describe('input', function() {
2877
2877
expect ( inputElm . val ( ) ) . toEqual ( '50' ) ;
2878
2878
} ) ;
2879
2879
2880
- it ( 'should set model to 50 when no value specified' , function ( ) {
2880
+ it ( 'should set model to 50 when no value specified and default min/max ' , function ( ) {
2881
2881
var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2882
2882
2883
2883
expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
@@ -2887,7 +2887,7 @@ describe('input', function() {
2887
2887
expect ( scope . age ) . toBe ( 50 ) ;
2888
2888
} ) ;
2889
2889
2890
- it ( 'should parse non-number values to 50' , function ( ) {
2890
+ it ( 'should parse non-number values to 50 when default min/max ' , function ( ) {
2891
2891
var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2892
2892
2893
2893
scope . $apply ( 'age = 10' ) ;
@@ -2949,8 +2949,20 @@ describe('input', function() {
2949
2949
describe ( 'min' , function ( ) {
2950
2950
2951
2951
if ( supportsRange ) {
2952
+
2953
+ it ( 'should initialize correctly with non-default model and min value' , function ( ) {
2954
+ scope . value = - 3 ;
2955
+ scope . min = - 5 ;
2956
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
2957
+
2958
+ expect ( inputElm ) . toBeValid ( ) ;
2959
+ expect ( inputElm . val ( ) ) . toBe ( '-3' ) ;
2960
+ expect ( scope . value ) . toBe ( - 3 ) ;
2961
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2962
+ } ) ;
2963
+
2952
2964
// Browsers that implement range will never allow you to set the value < min values
2953
- it ( 'should validate ' , function ( ) {
2965
+ it ( 'should adjust invalid input values ' , function ( ) {
2954
2966
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" />' ) ;
2955
2967
2956
2968
helper . changeInputValueTo ( '5' ) ;
@@ -2964,6 +2976,22 @@ describe('input', function() {
2964
2976
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2965
2977
} ) ;
2966
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
+
2967
2995
it ( 'should adjust the element and model value when the min value changes on-the-fly' , function ( ) {
2968
2996
scope . min = 10 ;
2969
2997
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
@@ -2997,8 +3025,9 @@ describe('input', function() {
2997
3025
} ) ;
2998
3026
2999
3027
} else {
3028
+ // input[type=range] will become type=text in browsers that don't support it
3029
+
3000
3030
it ( 'should validate if "range" is not implemented' , function ( ) {
3001
- // This will become type=text in browsers that don't support it
3002
3031
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="10" />' ) ;
3003
3032
3004
3033
helper . changeInputValueTo ( '5' ) ;
@@ -3012,6 +3041,34 @@ describe('input', function() {
3012
3041
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
3013
3042
} ) ;
3014
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
+
3015
3072
it ( 'should validate even if the min value changes on-the-fly' , function ( ) {
3016
3073
scope . min = 10 ;
3017
3074
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" min="{{min}}" />' ) ;
@@ -3074,6 +3131,7 @@ describe('input', function() {
3074
3131
scope . min = 20 ;
3075
3132
scope . $digest ( ) ;
3076
3133
expect ( inputElm ) . toBeInvalid ( ) ;
3134
+ expect ( inputElm . val ( ) ) . toBe ( '15' ) ;
3077
3135
3078
3136
scope . min = null ;
3079
3137
scope . $digest ( ) ;
@@ -3094,6 +3152,17 @@ describe('input', function() {
3094
3152
3095
3153
if ( supportsRange ) {
3096
3154
// Browsers that implement range will never allow you to set the value > max value
3155
+ it ( 'should initialize correctly with non-default model and max value' , function ( ) {
3156
+ scope . value = 130 ;
3157
+ scope . max = 150 ;
3158
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3159
+
3160
+ expect ( inputElm ) . toBeValid ( ) ;
3161
+ expect ( inputElm . val ( ) ) . toBe ( '130' ) ;
3162
+ expect ( scope . value ) . toBe ( 130 ) ;
3163
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3164
+ } ) ;
3165
+
3097
3166
it ( 'should validate' , function ( ) {
3098
3167
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
3099
3168
@@ -3108,9 +3177,16 @@ describe('input', function() {
3108
3177
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3109
3178
} ) ;
3110
3179
3111
- it ( 'should set the model to the max val if it is more than the max val' , function ( ) {
3112
- scope . value = 90 ;
3113
- 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' ) ;
3114
3190
3115
3191
expect ( inputElm ) . toBeValid ( ) ;
3116
3192
expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
@@ -3164,6 +3240,34 @@ describe('input', function() {
3164
3240
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3165
3241
} ) ;
3166
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
+
3167
3271
it ( 'should validate even if the max value changes on-the-fly' , function ( ) {
3168
3272
scope . max = 10 ;
3169
3273
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
@@ -3245,22 +3349,21 @@ describe('input', function() {
3245
3349
3246
3350
describe ( 'min and max' , function ( ) {
3247
3351
3248
- it ( 'should keep the initial default value when min and max are specified' , function ( ) {
3352
+ it ( 'should set the correct initial value when min and max are specified' , function ( ) {
3249
3353
scope . max = 80 ;
3250
3354
scope . min = 40 ;
3251
3355
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3252
3356
3253
- expect ( inputElm . val ( ) ) . toBe ( '50 ' ) ;
3254
- expect ( scope . value ) . toBe ( 50 ) ;
3357
+ expect ( inputElm . val ( ) ) . toBe ( '60 ' ) ;
3358
+ expect ( scope . value ) . toBe ( 60 ) ;
3255
3359
} ) ;
3256
3360
3257
-
3258
3361
it ( 'should set element and model value to min if max is less than min' , function ( ) {
3259
3362
scope . min = 40 ;
3260
3363
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3261
3364
3262
- expect ( inputElm . val ( ) ) . toBe ( '50 ' ) ;
3263
- expect ( scope . value ) . toBe ( 50 ) ;
3365
+ expect ( inputElm . val ( ) ) . toBe ( '70 ' ) ;
3366
+ expect ( scope . value ) . toBe ( 70 ) ;
3264
3367
3265
3368
scope . max = 20 ;
3266
3369
scope . $digest ( ) ;
0 commit comments