@@ -2063,9 +2063,12 @@ describe('input', function() {
2063
2063
} ) ;
2064
2064
2065
2065
describe ( 'min' , function ( ) {
2066
- beforeEach ( function ( ) {
2067
- compileInput ( '<input type="month" ng-model="value" name="alias" min="2013-01" />' ) ;
2068
- } ) ;
2066
+ var scope ;
2067
+ beforeEach ( inject ( function ( $rootScope ) {
2068
+ scope = $rootScope ;
2069
+ $rootScope . minVal = '2013-01' ;
2070
+ compileInput ( '<input type="month" ng-model="value" name="alias" min="{{ minVal }}" />' ) ;
2071
+ } ) ) ;
2069
2072
2070
2073
it ( 'should invalidate' , function ( ) {
2071
2074
changeInputValueTo ( '2012-12' ) ;
@@ -2080,12 +2083,27 @@ describe('input', function() {
2080
2083
expect ( + scope . value ) . toBe ( + new Date ( 2013 , 6 , 1 ) ) ;
2081
2084
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2082
2085
} ) ;
2086
+
2087
+ it ( 'should revalidate when the min value changes' , function ( ) {
2088
+ changeInputValueTo ( '2013-07' ) ;
2089
+ expect ( inputElm ) . toBeValid ( ) ;
2090
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2091
+
2092
+ scope . minVal = '2014-01' ;
2093
+ scope . $digest ( ) ;
2094
+
2095
+ expect ( inputElm ) . toBeInvalid ( ) ;
2096
+ expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2097
+ } ) ;
2083
2098
} ) ;
2084
2099
2085
2100
describe ( 'max' , function ( ) {
2086
- beforeEach ( function ( ) {
2087
- compileInput ( '<input type="month" ng-model="value" name="alias" max="2013-01" />' ) ;
2088
- } ) ;
2101
+ var scope ;
2102
+ beforeEach ( inject ( function ( $rootScope ) {
2103
+ scope = $rootScope ;
2104
+ $rootScope . maxVal = '2013-01' ;
2105
+ compileInput ( '<input type="month" ng-model="value" name="alias" max="{{ maxVal }}" />' ) ;
2106
+ } ) ) ;
2089
2107
2090
2108
it ( 'should validate' , function ( ) {
2091
2109
changeInputValueTo ( '2012-03' ) ;
@@ -2100,6 +2118,18 @@ describe('input', function() {
2100
2118
expect ( scope . value ) . toBeUndefined ( ) ;
2101
2119
expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
2102
2120
} ) ;
2121
+
2122
+ it ( 'should revalidate when the max value changes' , function ( ) {
2123
+ changeInputValueTo ( '2012-07' ) ;
2124
+ expect ( inputElm ) . toBeValid ( ) ;
2125
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
2126
+
2127
+ scope . maxVal = '2012-01' ;
2128
+ scope . $digest ( ) ;
2129
+
2130
+ expect ( inputElm ) . toBeInvalid ( ) ;
2131
+ expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
2132
+ } ) ;
2103
2133
} ) ;
2104
2134
} ) ;
2105
2135
@@ -2204,9 +2234,12 @@ describe('input', function() {
2204
2234
} ) ;
2205
2235
2206
2236
describe ( 'min' , function ( ) {
2207
- beforeEach ( function ( ) {
2208
- compileInput ( '<input type="week" ng-model="value" name="alias" min="2013-W01" />' ) ;
2209
- } ) ;
2237
+ var scope ;
2238
+ beforeEach ( inject ( function ( $rootScope ) {
2239
+ scope = $rootScope ;
2240
+ $rootScope . minVal = '2013-W01' ;
2241
+ compileInput ( '<input type="week" ng-model="value" name="alias" min="{{ minVal }}" />' ) ;
2242
+ } ) ) ;
2210
2243
2211
2244
it ( 'should invalidate' , function ( ) {
2212
2245
changeInputValueTo ( '2012-W12' ) ;
@@ -2221,12 +2254,26 @@ describe('input', function() {
2221
2254
expect ( + scope . value ) . toBe ( + new Date ( 2013 , 0 , 17 ) ) ;
2222
2255
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2223
2256
} ) ;
2257
+
2258
+ it ( 'should revalidate when the min value changes' , function ( ) {
2259
+ changeInputValueTo ( '2013-W03' ) ;
2260
+ expect ( inputElm ) . toBeValid ( ) ;
2261
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2262
+
2263
+ scope . minVal = '2014-W01' ;
2264
+ scope . $digest ( ) ;
2265
+
2266
+ expect ( inputElm ) . toBeInvalid ( ) ;
2267
+ expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2268
+ } ) ;
2224
2269
} ) ;
2225
2270
2226
2271
describe ( 'max' , function ( ) {
2227
- beforeEach ( function ( ) {
2228
- compileInput ( '<input type="week" ng-model="value" name="alias" max="2013-W01" />' ) ;
2229
- } ) ;
2272
+ beforeEach ( inject ( function ( $rootScope ) {
2273
+ $rootScope . maxVal = '2013-W01' ;
2274
+ scope = $rootScope ;
2275
+ compileInput ( '<input type="week" ng-model="value" name="alias" max="{{ maxVal }}" />' ) ;
2276
+ } ) ) ;
2230
2277
2231
2278
it ( 'should validate' , function ( ) {
2232
2279
changeInputValueTo ( '2012-W01' ) ;
@@ -2241,6 +2288,18 @@ describe('input', function() {
2241
2288
expect ( scope . value ) . toBeUndefined ( ) ;
2242
2289
expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
2243
2290
} ) ;
2291
+
2292
+ it ( 'should revalidate when the max value changes' , function ( ) {
2293
+ changeInputValueTo ( '2012-W03' ) ;
2294
+ expect ( inputElm ) . toBeValid ( ) ;
2295
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
2296
+
2297
+ scope . maxVal = '2012-W01' ;
2298
+ scope . $digest ( ) ;
2299
+
2300
+ expect ( inputElm ) . toBeInvalid ( ) ;
2301
+ expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
2302
+ } ) ;
2244
2303
} ) ;
2245
2304
} ) ;
2246
2305
@@ -2363,9 +2422,12 @@ describe('input', function() {
2363
2422
} ) ;
2364
2423
2365
2424
describe ( 'min' , function ( ) {
2366
- beforeEach ( function ( ) {
2367
- compileInput ( '<input type="datetime-local" ng-model="value" name="alias" min="2000-01-01T12:30:00" />' ) ;
2368
- } ) ;
2425
+ var scope ;
2426
+ beforeEach ( inject ( function ( $rootScope ) {
2427
+ $rootScope . minVal = '2000-01-01T12:30:00' ;
2428
+ scope = $rootScope ;
2429
+ compileInput ( '<input type="datetime-local" ng-model="value" name="alias" min="{{ minVal }}" />' ) ;
2430
+ } ) ) ;
2369
2431
2370
2432
it ( 'should invalidate' , function ( ) {
2371
2433
changeInputValueTo ( '1999-12-31T01:02:00' ) ;
@@ -2380,12 +2442,27 @@ describe('input', function() {
2380
2442
expect ( + scope . value ) . toBe ( + new Date ( 2000 , 0 , 1 , 23 , 2 , 0 ) ) ;
2381
2443
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2382
2444
} ) ;
2445
+
2446
+ it ( 'should revalidate when the min value changes' , function ( ) {
2447
+ changeInputValueTo ( '2000-02-01T01:02:00' ) ;
2448
+ expect ( inputElm ) . toBeValid ( ) ;
2449
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2450
+
2451
+ scope . minVal = '2010-01-01T01:02:00' ;
2452
+ scope . $digest ( ) ;
2453
+
2454
+ expect ( inputElm ) . toBeInvalid ( ) ;
2455
+ expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2456
+ } ) ;
2383
2457
} ) ;
2384
2458
2385
2459
describe ( 'max' , function ( ) {
2386
- beforeEach ( function ( ) {
2387
- compileInput ( '<input type="datetime-local" ng-model="value" name="alias" max="2019-01-01T01:02:00" />' ) ;
2388
- } ) ;
2460
+ var scope ;
2461
+ beforeEach ( inject ( function ( $rootScope ) {
2462
+ $rootScope . maxVal = '2019-01-01T01:02:00' ;
2463
+ scope = $rootScope ;
2464
+ compileInput ( '<input type="datetime-local" ng-model="value" name="alias" max="{{ maxVal }}" />' ) ;
2465
+ } ) ) ;
2389
2466
2390
2467
it ( 'should invalidate' , function ( ) {
2391
2468
changeInputValueTo ( '2019-12-31T01:02:00' ) ;
@@ -2400,6 +2477,18 @@ describe('input', function() {
2400
2477
expect ( + scope . value ) . toBe ( + new Date ( 2000 , 0 , 1 , 1 , 2 , 0 ) ) ;
2401
2478
expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
2402
2479
} ) ;
2480
+
2481
+ it ( 'should revalidate when the max value changes' , function ( ) {
2482
+ changeInputValueTo ( '2000-02-01T01:02:00' ) ;
2483
+ expect ( inputElm ) . toBeValid ( ) ;
2484
+ expect ( scope . form . alias . $error . max ) . toBeFalsy ( ) ;
2485
+
2486
+ scope . maxVal = '2000-01-01T01:02:00' ;
2487
+ scope . $digest ( ) ;
2488
+
2489
+ expect ( inputElm ) . toBeInvalid ( ) ;
2490
+ expect ( scope . form . alias . $error . max ) . toBeTruthy ( ) ;
2491
+ } ) ;
2403
2492
} ) ;
2404
2493
2405
2494
it ( 'should validate even if max value changes on-the-fly' , function ( done ) {
@@ -2550,9 +2639,12 @@ describe('input', function() {
2550
2639
} ) ;
2551
2640
2552
2641
describe ( 'min' , function ( ) {
2553
- beforeEach ( function ( ) {
2554
- compileInput ( '<input type="time" ng-model="value" name="alias" min="09:30:00" />' ) ;
2555
- } ) ;
2642
+ var scope ;
2643
+ beforeEach ( inject ( function ( $rootScope ) {
2644
+ $rootScope . minVal = '09:30:00' ;
2645
+ scope = $rootScope ;
2646
+ compileInput ( '<input type="time" ng-model="value" name="alias" min="{{ minVal }}" />' ) ;
2647
+ } ) ) ;
2556
2648
2557
2649
it ( 'should invalidate' , function ( ) {
2558
2650
changeInputValueTo ( '01:02:00' ) ;
@@ -2567,6 +2659,18 @@ describe('input', function() {
2567
2659
expect ( + scope . value ) . toBe ( + new Date ( 1970 , 0 , 1 , 23 , 2 , 0 ) ) ;
2568
2660
expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2569
2661
} ) ;
2662
+
2663
+ it ( 'should revalidate when the min value changes' , function ( ) {
2664
+ changeInputValueTo ( '23:02:00' ) ;
2665
+ expect ( inputElm ) . toBeValid ( ) ;
2666
+ expect ( scope . form . alias . $error . min ) . toBeFalsy ( ) ;
2667
+
2668
+ scope . minVal = '23:55:00' ;
2669
+ scope . $digest ( ) ;
2670
+
2671
+ expect ( inputElm ) . toBeInvalid ( ) ;
2672
+ expect ( scope . form . alias . $error . min ) . toBeTruthy ( ) ;
2673
+ } ) ;
2570
2674
} ) ;
2571
2675
2572
2676
describe ( 'max' , function ( ) {
@@ -2589,32 +2693,30 @@ describe('input', function() {
2589
2693
} ) ;
2590
2694
} ) ;
2591
2695
2592
- it ( 'should validate even if max value changes on-the-fly' , function ( done ) {
2593
- scope . max = '21 :02:00' ;
2696
+ it ( 'should validate even if max value changes on-the-fly' , function ( ) {
2697
+ scope . max = '4 :02:00' ;
2594
2698
compileInput ( '<input type="time" ng-model="value" name="alias" max="{{max}}" />' ) ;
2595
2699
2596
- changeInputValueTo ( '22 :34:00' ) ;
2700
+ changeInputValueTo ( '05 :34:00' ) ;
2597
2701
expect ( inputElm ) . toBeInvalid ( ) ;
2598
2702
2599
- scope . max = '12:34:00' ;
2600
- scope . $digest ( function ( ) {
2601
- expect ( inputElm ) . toBeValid ( ) ;
2602
- done ( ) ;
2603
- } ) ;
2703
+ scope . max = '06:34:00' ;
2704
+ scope . $digest ( ) ;
2705
+
2706
+ expect ( inputElm ) . toBeValid ( ) ;
2604
2707
} ) ;
2605
2708
2606
- it ( 'should validate even if min value changes on-the-fly' , function ( done ) {
2709
+ it ( 'should validate even if min value changes on-the-fly' , function ( ) {
2607
2710
scope . min = '08:45:00' ;
2608
2711
compileInput ( '<input type="time" ng-model="value" name="alias" min="{{min}}" />' ) ;
2609
2712
2610
2713
changeInputValueTo ( '06:15:00' ) ;
2611
2714
expect ( inputElm ) . toBeInvalid ( ) ;
2612
2715
2613
- scope . min = '13:50:00' ;
2614
- scope . $digest ( function ( ) {
2615
- expect ( inputElm ) . toBeValid ( ) ;
2616
- done ( ) ;
2617
- } ) ;
2716
+ scope . min = '05:50:00' ;
2717
+ scope . $digest ( ) ;
2718
+
2719
+ expect ( inputElm ) . toBeValid ( ) ;
2618
2720
} ) ;
2619
2721
} ) ;
2620
2722
0 commit comments