@@ -2491,32 +2491,40 @@ describe('input', function() {
2491
2491
} ) ;
2492
2492
} ) ;
2493
2493
2494
- it ( 'should validate even if max value changes on-the-fly' , function ( done ) {
2494
+ it ( 'should validate even if max value changes on-the-fly' , function ( ) {
2495
2495
scope . max = '2013-01-01T01:02:00' ;
2496
2496
compileInput ( '<input type="datetime-local" ng-model="value" name="alias" max="{{max}}" />' ) ;
2497
2497
2498
2498
changeInputValueTo ( '2014-01-01T12:34:00' ) ;
2499
2499
expect ( inputElm ) . toBeInvalid ( ) ;
2500
2500
2501
2501
scope . max = '2001-01-01T01:02:00' ;
2502
- scope . $digest ( function ( ) {
2503
- expect ( inputElm ) . toBeValid ( ) ;
2504
- done ( ) ;
2505
- } ) ;
2502
+ scope . $digest ( ) ;
2503
+
2504
+ expect ( inputElm ) . toBeInvalid ( ) ;
2505
+
2506
+ scope . max = '2024-01-01T01:02:00' ;
2507
+ scope . $digest ( ) ;
2508
+
2509
+ expect ( inputElm ) . toBeValid ( ) ;
2506
2510
} ) ;
2507
2511
2508
- it ( 'should validate even if min value changes on-the-fly' , function ( done ) {
2512
+ it ( 'should validate even if min value changes on-the-fly' , function ( ) {
2509
2513
scope . min = '2013-01-01T01:02:00' ;
2510
2514
compileInput ( '<input type="datetime-local" ng-model="value" name="alias" min="{{min}}" />' ) ;
2511
2515
2512
2516
changeInputValueTo ( '2010-01-01T12:34:00' ) ;
2513
2517
expect ( inputElm ) . toBeInvalid ( ) ;
2514
2518
2515
2519
scope . min = '2014-01-01T01:02:00' ;
2516
- scope . $digest ( function ( ) {
2517
- expect ( inputElm ) . toBeValid ( ) ;
2518
- done ( ) ;
2519
- } ) ;
2520
+ scope . $digest ( ) ;
2521
+
2522
+ expect ( inputElm ) . toBeInvalid ( ) ;
2523
+
2524
+ scope . min = '2009-01-01T01:02:00' ;
2525
+ scope . $digest ( ) ;
2526
+
2527
+ expect ( inputElm ) . toBeValid ( ) ;
2520
2528
} ) ;
2521
2529
} ) ;
2522
2530
@@ -2837,6 +2845,23 @@ describe('input', function() {
2837
2845
expect ( + scope . value ) . toBe ( + new Date ( 2000 , 0 , 1 ) ) ;
2838
2846
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2839
2847
} ) ;
2848
+
2849
+ it ( 'should parse ISO-based date strings as a valid min date value' , inject ( function ( $rootScope ) {
2850
+ var scope = $rootScope . $new ( ) ;
2851
+ var element = $compile ( '<form name="myForm">' +
2852
+ '<input name="myControl" type="date" min="{{ min }}" ng-model="value">' +
2853
+ '</form>' ) ( scope ) ;
2854
+
2855
+ var inputElm = element . find ( 'input' ) ;
2856
+
2857
+ scope . value = new Date ( 2010 , 1 , 1 , 0 , 0 , 0 ) ;
2858
+ scope . min = new Date ( 2014 , 10 , 10 , 0 , 0 , 0 ) ;
2859
+ scope . $digest ( ) ;
2860
+
2861
+ expect ( scope . myForm . myControl . $error . min ) . toBeTruthy ( ) ;
2862
+
2863
+ dealoc ( element ) ;
2864
+ } ) ) ;
2840
2865
} ) ;
2841
2866
2842
2867
describe ( 'max' , function ( ) {
@@ -2857,34 +2882,59 @@ describe('input', function() {
2857
2882
expect ( + scope . value ) . toBe ( + new Date ( 2000 , 0 , 1 ) ) ;
2858
2883
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
2859
2884
} ) ;
2885
+
2886
+ it ( 'should parse ISO-based date strings as a valid max date value' , inject ( function ( $rootScope ) {
2887
+ var scope = $rootScope . $new ( ) ;
2888
+ var element = $compile ( '<form name="myForm">' +
2889
+ '<input name="myControl" type="date" max="{{ max }}" ng-model="value">' +
2890
+ '</form>' ) ( scope ) ;
2891
+
2892
+ var inputElm = element . find ( 'input' ) ;
2893
+
2894
+ scope . value = new Date ( 2020 , 1 , 1 , 0 , 0 , 0 ) ;
2895
+ scope . max = new Date ( 2014 , 10 , 10 , 0 , 0 , 0 ) ;
2896
+ scope . $digest ( ) ;
2897
+
2898
+ expect ( scope . myForm . myControl . $error . max ) . toBeTruthy ( ) ;
2899
+
2900
+ dealoc ( element ) ;
2901
+ } ) ) ;
2860
2902
} ) ;
2861
2903
2862
- it ( 'should validate even if max value changes on-the-fly' , function ( done ) {
2904
+ it ( 'should validate even if max value changes on-the-fly' , function ( ) {
2863
2905
scope . max = '2013-01-01' ;
2864
2906
compileInput ( '<input type="date" ng-model="value" name="alias" max="{{max}}" />' ) ;
2865
2907
2866
2908
changeInputValueTo ( '2014-01-01' ) ;
2867
2909
expect ( inputElm ) . toBeInvalid ( ) ;
2868
2910
2869
2911
scope . max = '2001-01-01' ;
2870
- scope . $digest ( function ( ) {
2871
- expect ( inputElm ) . toBeValid ( ) ;
2872
- done ( ) ;
2873
- } ) ;
2912
+ scope . $digest ( ) ;
2913
+
2914
+ expect ( inputElm ) . toBeInvalid ( ) ;
2915
+
2916
+ scope . max = '2021-01-01' ;
2917
+ scope . $digest ( ) ;
2918
+
2919
+ expect ( inputElm ) . toBeValid ( ) ;
2874
2920
} ) ;
2875
2921
2876
- it ( 'should validate even if min value changes on-the-fly' , function ( done ) {
2922
+ it ( 'should validate even if min value changes on-the-fly' , function ( ) {
2877
2923
scope . min = '2013-01-01' ;
2878
2924
compileInput ( '<input type="date" ng-model="value" name="alias" min="{{min}}" />' ) ;
2879
2925
2880
2926
changeInputValueTo ( '2010-01-01' ) ;
2881
2927
expect ( inputElm ) . toBeInvalid ( ) ;
2882
2928
2883
2929
scope . min = '2014-01-01' ;
2884
- scope . $digest ( function ( ) {
2885
- expect ( inputElm ) . toBeValid ( ) ;
2886
- done ( ) ;
2887
- } ) ;
2930
+ scope . $digest ( ) ;
2931
+
2932
+ expect ( inputElm ) . toBeInvalid ( ) ;
2933
+
2934
+ scope . min = '2009-01-01' ;
2935
+ scope . $digest ( ) ;
2936
+
2937
+ expect ( inputElm ) . toBeValid ( ) ;
2888
2938
} ) ;
2889
2939
} ) ;
2890
2940
0 commit comments