@@ -2621,154 +2621,88 @@ describe('input', function() {
2621
2621
} ) ;
2622
2622
} ) ;
2623
2623
2624
- describe ( 'step' , function ( ) {
2625
- it ( 'should validate' , function ( ) {
2626
- $rootScope . step = 10 ;
2627
- $rootScope . value = 20 ;
2628
- var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" step="{{step}}" />' ) ;
2629
-
2630
- expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2631
- expect ( inputElm ) . toBeValid ( ) ;
2632
- expect ( $rootScope . value ) . toBe ( 20 ) ;
2633
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2634
-
2635
- helper . changeInputValueTo ( '18' ) ;
2636
- expect ( inputElm ) . toBeInvalid ( ) ;
2637
- expect ( inputElm . val ( ) ) . toBe ( '18' ) ;
2638
- expect ( $rootScope . value ) . toBeUndefined ( ) ;
2639
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2640
-
2641
- helper . changeInputValueTo ( '10' ) ;
2642
- expect ( inputElm ) . toBeValid ( ) ;
2643
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2644
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2645
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2646
-
2647
- $rootScope . $apply ( 'value = 12' ) ;
2648
- expect ( inputElm ) . toBeInvalid ( ) ;
2649
- expect ( inputElm . val ( ) ) . toBe ( '12' ) ;
2650
- expect ( $rootScope . value ) . toBe ( 12 ) ;
2651
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2652
- } ) ;
2653
-
2654
- it ( 'should validate even if the step value changes on-the-fly' , function ( ) {
2655
- $rootScope . step = 10 ;
2656
- var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" step="{{step}}" />' ) ;
2657
-
2658
- helper . changeInputValueTo ( '10' ) ;
2659
- expect ( inputElm ) . toBeValid ( ) ;
2660
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2661
-
2662
- // Step changes, but value matches
2663
- $rootScope . $apply ( 'step = 5' ) ;
2664
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2665
- expect ( inputElm ) . toBeValid ( ) ;
2666
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2667
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2668
-
2669
- // Step changes, value does not match
2670
- $rootScope . $apply ( 'step = 6' ) ;
2671
- expect ( inputElm ) . toBeInvalid ( ) ;
2672
- expect ( $rootScope . value ) . toBeUndefined ( ) ;
2673
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2674
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2675
-
2676
- // null = valid
2677
- $rootScope . $apply ( 'step = null' ) ;
2678
- expect ( inputElm ) . toBeValid ( ) ;
2679
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2680
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2681
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2682
-
2683
- // Step val as string
2684
- $rootScope . $apply ( 'step = "7"' ) ;
2685
- expect ( inputElm ) . toBeInvalid ( ) ;
2686
- expect ( $rootScope . value ) . toBeUndefined ( ) ;
2687
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2688
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2689
2624
2690
- // unparsable string is ignored
2691
- $rootScope . $apply ( 'step = "abc"' ) ;
2692
- expect ( inputElm ) . toBeValid ( ) ;
2693
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2694
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2695
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2696
- } ) ;
2697
- } ) ;
2625
+ forEach ( {
2626
+ step : 'step="{{step}}"' ,
2627
+ ngStep : 'ng-step="step"'
2628
+ } , function ( attrHtml , attrName ) {
2698
2629
2630
+ describe ( attrName , function ( ) {
2699
2631
2700
- describe ( 'ngStep ', function ( ) {
2701
- it ( 'should validate' , function ( ) {
2702
- $rootScope . step = 10 ;
2703
- $rootScope . value = 20 ;
2704
- var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" ng-step="step" />' ) ;
2632
+ it ( 'should validate ', function ( ) {
2633
+ $rootScope . step = 10 ;
2634
+ $rootScope . value = 20 ;
2635
+ var inputElm = helper . compileInput (
2636
+ '<input type="number" ng-model="value" name="alias" ' + attrHtml + ' />') ;
2705
2637
2706
- expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2707
- expect ( inputElm ) . toBeValid ( ) ;
2708
- expect ( $rootScope . value ) . toBe ( 20 ) ;
2709
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2638
+ expect ( inputElm . val ( ) ) . toBe ( '20' ) ;
2639
+ expect ( inputElm ) . toBeValid ( ) ;
2640
+ expect ( $rootScope . value ) . toBe ( 20 ) ;
2641
+ expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2710
2642
2711
- helper . changeInputValueTo ( '18' ) ;
2712
- expect ( inputElm ) . toBeInvalid ( ) ;
2713
- expect ( inputElm . val ( ) ) . toBe ( '18' ) ;
2714
- expect ( $rootScope . value ) . toBeUndefined ( ) ;
2715
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2643
+ helper . changeInputValueTo ( '18' ) ;
2644
+ expect ( inputElm ) . toBeInvalid ( ) ;
2645
+ expect ( inputElm . val ( ) ) . toBe ( '18' ) ;
2646
+ expect ( $rootScope . value ) . toBeUndefined ( ) ;
2647
+ expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2716
2648
2717
- helper . changeInputValueTo ( '10' ) ;
2718
- expect ( inputElm ) . toBeValid ( ) ;
2719
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2720
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2721
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2649
+ helper . changeInputValueTo ( '10' ) ;
2650
+ expect ( inputElm ) . toBeValid ( ) ;
2651
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2652
+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2653
+ expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2722
2654
2723
- $rootScope . $apply ( 'value = 12' ) ;
2724
- expect ( inputElm ) . toBeInvalid ( ) ;
2725
- expect ( inputElm . val ( ) ) . toBe ( '12' ) ;
2726
- expect ( $rootScope . value ) . toBe ( 12 ) ;
2727
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2728
- } ) ;
2655
+ $rootScope . $apply ( 'value = 12' ) ;
2656
+ expect ( inputElm ) . toBeInvalid ( ) ;
2657
+ expect ( inputElm . val ( ) ) . toBe ( '12' ) ;
2658
+ expect ( $rootScope . value ) . toBe ( 12 ) ;
2659
+ expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2660
+ } ) ;
2729
2661
2730
- it ( 'should validate even if the step value changes on-the-fly' , function ( ) {
2731
- $rootScope . step = 10 ;
2732
- var inputElm = helper . compileInput ( '<input type="number" ng-model="value" name="alias" ng-step="step" />' ) ;
2662
+ it ( 'should validate even if the step value changes on-the-fly' , function ( ) {
2663
+ $rootScope . step = 10 ;
2664
+ var inputElm = helper . compileInput (
2665
+ '<input type="number" ng-model="value" name="alias" ' + attrHtml + ' />' ) ;
2733
2666
2734
- helper . changeInputValueTo ( '10' ) ;
2735
- expect ( inputElm ) . toBeValid ( ) ;
2736
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2667
+ helper . changeInputValueTo ( '10' ) ;
2668
+ expect ( inputElm ) . toBeValid ( ) ;
2669
+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2737
2670
2738
- // Step changes, but value matches
2739
- $rootScope . $apply ( 'step = 5' ) ;
2740
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2741
- expect ( inputElm ) . toBeValid ( ) ;
2742
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2743
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2671
+ // Step changes, but value matches
2672
+ $rootScope . $apply ( 'step = 5' ) ;
2673
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2674
+ expect ( inputElm ) . toBeValid ( ) ;
2675
+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2676
+ expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2744
2677
2745
- // Step changes, value does not match
2746
- $rootScope . $apply ( 'step = 6' ) ;
2747
- expect ( inputElm ) . toBeInvalid ( ) ;
2748
- expect ( $rootScope . value ) . toBeUndefined ( ) ;
2749
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2750
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2678
+ // Step changes, value does not match
2679
+ $rootScope . $apply ( 'step = 6' ) ;
2680
+ expect ( inputElm ) . toBeInvalid ( ) ;
2681
+ expect ( $rootScope . value ) . toBeUndefined ( ) ;
2682
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2683
+ expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2751
2684
2752
- // null = valid
2753
- $rootScope . $apply ( 'step = null' ) ;
2754
- expect ( inputElm ) . toBeValid ( ) ;
2755
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2756
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2757
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2685
+ // null = valid
2686
+ $rootScope . $apply ( 'step = null' ) ;
2687
+ expect ( inputElm ) . toBeValid ( ) ;
2688
+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2689
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2690
+ expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2758
2691
2759
- // Step val as string
2760
- $rootScope . $apply ( 'step = "7"' ) ;
2761
- expect ( inputElm ) . toBeInvalid ( ) ;
2762
- expect ( $rootScope . value ) . toBeUndefined ( ) ;
2763
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2764
- expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2692
+ // Step val as string
2693
+ $rootScope . $apply ( 'step = "7"' ) ;
2694
+ expect ( inputElm ) . toBeInvalid ( ) ;
2695
+ expect ( $rootScope . value ) . toBeUndefined ( ) ;
2696
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2697
+ expect ( $rootScope . form . alias . $error . step ) . toBeTruthy ( ) ;
2765
2698
2766
- // unparsable string is ignored
2767
- $rootScope . $apply ( 'step = "abc"' ) ;
2768
- expect ( inputElm ) . toBeValid ( ) ;
2769
- expect ( $rootScope . value ) . toBe ( 10 ) ;
2770
- expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2771
- expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2699
+ // unparsable string is ignored
2700
+ $rootScope . $apply ( 'step = "abc"' ) ;
2701
+ expect ( inputElm ) . toBeValid ( ) ;
2702
+ expect ( $rootScope . value ) . toBe ( 10 ) ;
2703
+ expect ( inputElm . val ( ) ) . toBe ( '10' ) ;
2704
+ expect ( $rootScope . form . alias . $error . step ) . toBeFalsy ( ) ;
2705
+ } ) ;
2772
2706
} ) ;
2773
2707
} ) ;
2774
2708
@@ -3001,7 +2935,6 @@ describe('input', function() {
3001
2935
} ) ;
3002
2936
3003
2937
describe ( 'range' , function ( ) {
3004
-
3005
2938
var scope ;
3006
2939
3007
2940
var rangeTestEl = angular . element ( '<input type="range">' ) ;
@@ -3048,7 +2981,6 @@ describe('input', function() {
3048
2981
expect ( scope . age ) . toBe ( 50 ) ;
3049
2982
expect ( inputElm ) . toBeValid ( ) ;
3050
2983
} ) ;
3051
-
3052
2984
} else {
3053
2985
3054
2986
it ( 'should reset the model if view is invalid' , function ( ) {
@@ -3438,7 +3370,6 @@ describe('input', function() {
3438
3370
expect ( scope . value ) . toBe ( 40 ) ;
3439
3371
} ) ;
3440
3372
} ) ;
3441
-
3442
3373
}
3443
3374
3444
3375
@@ -3448,6 +3379,7 @@ describe('input', function() {
3448
3379
// Browsers that implement range will never allow you to set a value that doesn't match the step value
3449
3380
// However, currently only Firefox fully implements the spec when setting the value after the step value changes.
3450
3381
// Other browsers fail in various edge cases, which is why they are not tested here.
3382
+
3451
3383
it ( 'should round the input value to the nearest step on user input' , function ( ) {
3452
3384
var inputElm = helper . compileInput ( '<input type="range" ng-model="value" name="alias" step="5" />' ) ;
3453
3385
@@ -3510,8 +3442,8 @@ describe('input', function() {
3510
3442
expect ( scope . value ) . toBe ( 10 ) ;
3511
3443
expect ( scope . form . alias . $error . step ) . toBeFalsy ( ) ;
3512
3444
} ) ;
3513
-
3514
3445
} else {
3446
+
3515
3447
it ( 'should validate if "range" is not implemented' , function ( ) {
3516
3448
scope . step = 10 ;
3517
3449
scope . value = 20 ;
0 commit comments