@@ -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' ) ;
@@ -3051,7 +3063,7 @@ describe('input', function() {
3051
3063
describe ( 'ngMin' , function ( ) {
3052
3064
3053
3065
it ( 'should validate' , function ( ) {
3054
- var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" ng-min="50 " />' ) ;
3066
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" ng-min="20 " />' ) ;
3055
3067
3056
3068
helper . changeInputValueTo ( '1' ) ;
3057
3069
expect ( inputElm ) . toBeInvalid ( ) ;
@@ -3074,6 +3086,7 @@ describe('input', function() {
3074
3086
scope . min = 20 ;
3075
3087
scope . $digest ( ) ;
3076
3088
expect ( inputElm ) . toBeInvalid ( ) ;
3089
+ expect ( inputElm . val ( ) ) . toBe ( '15' ) ;
3077
3090
3078
3091
scope . min = null ;
3079
3092
scope . $digest ( ) ;
@@ -3093,6 +3106,18 @@ describe('input', function() {
3093
3106
describe ( 'max' , function ( ) {
3094
3107
3095
3108
if ( supportsRange ) {
3109
+ // Browsers that implement range will never allow you to set the value > max value
3110
+ it ( 'should initialize correctly with non-default model and max value' , function ( ) {
3111
+ scope . value = 130 ;
3112
+ scope . max = 150 ;
3113
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" />' ) ;
3114
+
3115
+ expect ( inputElm ) . toBeValid ( ) ;
3116
+ expect ( inputElm . val ( ) ) . toBe ( '130' ) ;
3117
+ expect ( scope . value ) . toBe ( 130 ) ;
3118
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3119
+ } ) ;
3120
+
3096
3121
// Browsers that implement range will never allow you to set the value > max value
3097
3122
it ( 'should validate' , function ( ) {
3098
3123
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="10" />' ) ;
@@ -3204,15 +3229,15 @@ describe('input', function() {
3204
3229
it ( 'should validate' , function ( ) {
3205
3230
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" ng-max="5" />' ) ;
3206
3231
3207
- helper . changeInputValueTo ( '20' ) ;
3208
- expect ( inputElm ) . toBeInvalid ( ) ;
3209
- expect ( scope . value ) . toBeUndefined ( ) ;
3210
- expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
3211
-
3212
3232
helper . changeInputValueTo ( '0' ) ;
3213
3233
expect ( inputElm ) . toBeValid ( ) ;
3214
3234
expect ( scope . value ) . toBe ( 0 ) ;
3215
3235
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
3236
+
3237
+ helper . changeInputValueTo ( '20' ) ;
3238
+ expect ( inputElm ) . toBeInvalid ( ) ;
3239
+ expect ( scope . value ) . toBeUndefined ( ) ;
3240
+ expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
3216
3241
} ) ;
3217
3242
3218
3243
it ( 'should validate even if the ngMax value changes on-the-fly' , function ( ) {
@@ -3245,22 +3270,21 @@ describe('input', function() {
3245
3270
3246
3271
describe ( 'min and max' , function ( ) {
3247
3272
3248
- it ( 'should keep the initial default value when min and max are specified' , function ( ) {
3273
+ it ( 'should set the correct initial value when min and max are specified' , function ( ) {
3249
3274
scope . max = 80 ;
3250
3275
scope . min = 40 ;
3251
3276
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3252
3277
3253
- expect ( inputElm . val ( ) ) . toBe ( '50 ' ) ;
3254
- expect ( scope . value ) . toBe ( 50 ) ;
3278
+ expect ( inputElm . val ( ) ) . toBe ( '60 ' ) ;
3279
+ expect ( scope . value ) . toBe ( 60 ) ;
3255
3280
} ) ;
3256
3281
3257
-
3258
3282
it ( 'should set element and model value to min if max is less than min' , function ( ) {
3259
3283
scope . min = 40 ;
3260
3284
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3261
3285
3262
- expect ( inputElm . val ( ) ) . toBe ( '50 ' ) ;
3263
- expect ( scope . value ) . toBe ( 50 ) ;
3286
+ expect ( inputElm . val ( ) ) . toBe ( '70 ' ) ;
3287
+ expect ( scope . value ) . toBe ( 70 ) ;
3264
3288
3265
3289
scope . max = 20 ;
3266
3290
scope . $digest ( ) ;
0 commit comments