3
3
/* globals generateInputCompilerHelper: false */
4
4
5
5
describe ( 'input' , function ( ) {
6
- var helper = { } , $compile , $rootScope , $browser , $sniffer , $timeout , $q ;
6
+ var helper = { } , $compile , $rootScope , $browser , $sniffer ;
7
7
8
8
// UA sniffing to exclude Edge from some date input tests
9
9
var isEdge = / \b E d g e \/ / . test ( window . navigator . userAgent ) ;
10
10
11
11
generateInputCompilerHelper ( helper ) ;
12
12
13
- beforeEach ( inject ( function ( _$compile_ , _$rootScope_ , _$browser_ , _$sniffer_ , _$timeout_ , _$q_ ) {
13
+ beforeEach ( inject ( function ( _$compile_ , _$rootScope_ , _$browser_ , _$sniffer_ ) {
14
14
$compile = _$compile_ ;
15
15
$rootScope = _$rootScope_ ;
16
16
$browser = _$browser_ ;
17
17
$sniffer = _$sniffer_ ;
18
- $timeout = _$timeout_ ;
19
- $q = _$q_ ;
20
18
} ) ) ;
21
19
22
20
@@ -1556,6 +1554,20 @@ describe('input', function() {
1556
1554
1557
1555
expect ( inputElm ) . toBeValid ( ) ;
1558
1556
} ) ;
1557
+
1558
+
1559
+ it ( 'should correctly handle 2-digit years' , function ( ) {
1560
+ helper . compileInput ( '<input type="datetime-local" ng-model="value" name="alias" />' ) ;
1561
+
1562
+ helper . changeInputValueTo ( '0001-01-01T12:34:00' ) ;
1563
+ expect ( $rootScope . value . getFullYear ( ) ) . toBe ( 1 ) ;
1564
+
1565
+ helper . changeInputValueTo ( '0099-01-01T12:34:00' ) ;
1566
+ expect ( $rootScope . value . getFullYear ( ) ) . toBe ( 99 ) ;
1567
+
1568
+ helper . changeInputValueTo ( '0100-01-01T12:34:00' ) ;
1569
+ expect ( $rootScope . value . getFullYear ( ) ) . toBe ( 100 ) ;
1570
+ } ) ;
1559
1571
} ) ;
1560
1572
1561
1573
@@ -2323,9 +2335,9 @@ describe('input', function() {
2323
2335
2324
2336
it ( 'should allow Date objects as valid ng-max values' , function ( ) {
2325
2337
$rootScope . max = new Date ( 2012 , 1 , 1 , 1 , 2 , 0 ) ;
2326
- var inputElm = helper . compileInput ( '<input type="datetime-local " ng-model="value" name="alias" ng-max="max" />' ) ;
2338
+ var inputElm = helper . compileInput ( '<input type="date " ng-model="value" name="alias" ng-max="max" />' ) ;
2327
2339
2328
- helper . changeInputValueTo ( '2014-01-01T12:34:00 ' ) ;
2340
+ helper . changeInputValueTo ( '2014-01-01 ' ) ;
2329
2341
expect ( inputElm ) . toBeInvalid ( ) ;
2330
2342
2331
2343
$rootScope . max = new Date ( 2013 , 1 , 1 , 1 , 2 , 0 ) ;
@@ -2342,9 +2354,9 @@ describe('input', function() {
2342
2354
2343
2355
it ( 'should allow Date objects as valid ng-min values' , function ( ) {
2344
2356
$rootScope . min = new Date ( 2013 , 1 , 1 , 1 , 2 , 0 ) ;
2345
- var inputElm = helper . compileInput ( '<input type="datetime-local " ng-model="value" name="alias" ng-min="min" />' ) ;
2357
+ var inputElm = helper . compileInput ( '<input type="date " ng-model="value" name="alias" ng-min="min" />' ) ;
2346
2358
2347
- helper . changeInputValueTo ( '2010-01-01T12:34:00 ' ) ;
2359
+ helper . changeInputValueTo ( '2010-01-01 ' ) ;
2348
2360
expect ( inputElm ) . toBeInvalid ( ) ;
2349
2361
2350
2362
$rootScope . min = new Date ( 2014 , 1 , 1 , 1 , 2 , 0 ) ;
@@ -2358,6 +2370,21 @@ describe('input', function() {
2358
2370
expect ( inputElm ) . toBeValid ( ) ;
2359
2371
} ) ;
2360
2372
2373
+
2374
+ it ( 'should correctly handle 2-digit years' , function ( ) {
2375
+ helper . compileInput ( '<input type="date" ng-model="value" name="alias" />' ) ;
2376
+
2377
+ helper . changeInputValueTo ( '0001-01-01' ) ;
2378
+ expect ( $rootScope . value . getFullYear ( ) ) . toBe ( 1 ) ;
2379
+
2380
+ helper . changeInputValueTo ( '0099-01-01' ) ;
2381
+ expect ( $rootScope . value . getFullYear ( ) ) . toBe ( 99 ) ;
2382
+
2383
+ helper . changeInputValueTo ( '0100-01-01' ) ;
2384
+ expect ( $rootScope . value . getFullYear ( ) ) . toBe ( 100 ) ;
2385
+ } ) ;
2386
+
2387
+
2361
2388
describe ( 'ISO_DATE_REGEXP' , function ( ) {
2362
2389
var dates = [
2363
2390
// Validate date
0 commit comments