@@ -2830,50 +2830,31 @@ describe('input', function() {
2830
2830
var rangeTestEl = angular . element ( '<input type="range">' ) ;
2831
2831
var supportsRange = rangeTestEl [ 0 ] . type === 'range' ;
2832
2832
2833
- it ( 'should reset the model if view is invalid' , function ( ) {
2834
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age"/>' ) ;
2835
-
2836
- scope . $apply ( 'age = 100' ) ;
2837
- expect ( inputElm . val ( ) ) . toBe ( '100' ) ;
2838
-
2839
- try {
2840
- // to allow non-number values, we have to change type so that
2841
- // the browser which have number validation will not interfere with
2842
- // this test. IE8 won't allow it hence the catch.
2843
- inputElm [ 0 ] . setAttribute ( 'type' , 'text' ) ;
2844
- } catch ( e ) { }
2845
-
2846
- helper . changeInputValueTo ( '100X' ) ;
2847
- expect ( inputElm . val ( ) ) . toBe ( '100X' ) ;
2848
- expect ( scope . age ) . toBeUndefined ( ) ;
2849
- expect ( inputElm ) . toBeInvalid ( ) ;
2850
- } ) ;
2851
-
2833
+ if ( supportsRange ) {
2834
+ // This behavior only applies to browsers that implement the range input, which do not
2835
+ // allow to set a non-number value and will set the value of the input to 50 even when you
2836
+ // change it directly on the element.
2837
+ // Other browsers fall back to text inputs, where setting a model value of 50 does not make
2838
+ // sense if the input value is a string. These browser will mark the input as invalid instead.
2852
2839
2853
- it ( 'should render as 50 if null' , function ( ) {
2854
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2840
+ it ( 'should render as 50 if null' , function ( ) {
2841
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2855
2842
2856
- scope . $apply ( 'age = null' ) ;
2843
+ scope . $apply ( 'age = null' ) ;
2857
2844
2858
- expect ( inputElm . val ( ) ) . toEqual ( '50' ) ;
2859
- } ) ;
2845
+ expect ( inputElm . val ( ) ) . toEqual ( '50' ) ;
2846
+ } ) ;
2860
2847
2861
- it ( 'should set model to 50 when no value specified' , function ( ) {
2862
- var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2848
+ it ( 'should set model to 50 when no value specified' , function ( ) {
2849
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2863
2850
2864
- expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
2851
+ expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
2865
2852
2866
- scope . $apply ( 'age = null' ) ;
2853
+ scope . $apply ( 'age = null' ) ;
2867
2854
2868
- expect ( scope . age ) . toBe ( 50 ) ;
2869
- } ) ;
2855
+ expect ( scope . age ) . toBe ( 50 ) ;
2856
+ } ) ;
2870
2857
2871
- if ( supportsRange ) {
2872
- // This behavior only applies to browsers that implement the range input, which do not
2873
- // allow to set a non-number value and will set the value of the input to 50 even when you
2874
- // change it directly on the element.
2875
- // Other browsers fall back to text inputs, where setting a model value of 50 does not make
2876
- // sense if the input value is a string. These browser will mark the input as invalid instead.
2877
2858
it ( 'should parse non-number values to 50' , function ( ) {
2878
2859
var inputElm = helper . compileInput ( '<input type="range" ng-model="age" />' ) ;
2879
2860
@@ -2884,6 +2865,20 @@ describe('input', function() {
2884
2865
expect ( scope . age ) . toBe ( 50 ) ;
2885
2866
expect ( inputElm ) . toBeValid ( ) ;
2886
2867
} ) ;
2868
+
2869
+ } else {
2870
+
2871
+ it ( 'should reset the model if view is invalid' , function ( ) {
2872
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="age"/>' ) ;
2873
+
2874
+ scope . $apply ( 'age = 100' ) ;
2875
+ expect ( inputElm . val ( ) ) . toBe ( '100' ) ;
2876
+
2877
+ helper . changeInputValueTo ( '100X' ) ;
2878
+ expect ( inputElm . val ( ) ) . toBe ( '100X' ) ;
2879
+ expect ( scope . age ) . toBeUndefined ( ) ;
2880
+ expect ( inputElm ) . toBeInvalid ( ) ;
2881
+ } ) ;
2887
2882
}
2888
2883
2889
2884
it ( 'should only invalidate the model if suffering from bad input when the data is parsed' , function ( ) {
@@ -3183,14 +3178,34 @@ describe('input', function() {
3183
3178
} ) ;
3184
3179
3185
3180
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}}" />' ) ;
3190
3181
3191
- expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
3192
- expect ( scope . value ) . toBe ( 50 ) ;
3182
+ describe ( 'min and max' , function ( ) {
3183
+
3184
+ it ( 'should keep the initial default value when min and max are specified' , function ( ) {
3185
+ scope . max = 80 ;
3186
+ scope . min = 40 ;
3187
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3188
+
3189
+ expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
3190
+ expect ( scope . value ) . toBe ( 50 ) ;
3191
+ } ) ;
3192
+
3193
+
3194
+ it ( 'should set element and model value to min if max is less than min' , function ( ) {
3195
+ scope . min = 40 ;
3196
+ var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" max="{{max}}" min="{{min}}" />' ) ;
3197
+
3198
+ expect ( inputElm . val ( ) ) . toBe ( '50' ) ;
3199
+ expect ( scope . value ) . toBe ( 50 ) ;
3200
+
3201
+ scope . max = 20 ;
3202
+ scope . $digest ( ) ;
3203
+
3204
+ expect ( inputElm . val ( ) ) . toBe ( '40' ) ;
3205
+ expect ( scope . value ) . toBe ( 40 ) ;
3206
+ } ) ;
3193
3207
} ) ;
3208
+
3194
3209
}
3195
3210
3196
3211
} ) ;
0 commit comments