@@ -1337,23 +1337,107 @@ describe('datepicker directive', function () {
1337
1337
} ) ;
1338
1338
1339
1339
describe ( 'attribute `datepickerOptions`' , function ( ) {
1340
- var weekHeader , weekElement ;
1340
+
1341
+ describe ( 'show-weeks' , function ( ) {
1342
+ var weekHeader , weekElement ;
1343
+ beforeEach ( function ( ) {
1344
+ $rootScope . opts = {
1345
+ 'show-weeks' : false
1346
+ } ;
1347
+ var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup datepicker-options="opts" is-open="true"></div>' ) ( $rootScope ) ;
1348
+ $rootScope . $digest ( ) ;
1349
+ assignElements ( wrapElement ) ;
1350
+
1351
+ weekHeader = getLabelsRow ( ) . find ( 'th' ) . eq ( 0 ) ;
1352
+ weekElement = element . find ( 'tbody' ) . find ( 'tr' ) . eq ( 1 ) . find ( 'td' ) . eq ( 0 ) ;
1353
+ } ) ;
1354
+
1355
+ it ( 'hides week numbers based on variable' , function ( ) {
1356
+ expect ( weekHeader . text ( ) ) . toEqual ( '' ) ;
1357
+ expect ( weekHeader ) . toBeHidden ( ) ;
1358
+ expect ( weekElement ) . toBeHidden ( ) ;
1359
+ } ) ;
1360
+ } ) ;
1361
+
1362
+ describe ( 'init-date' , function ( ) {
1363
+ beforeEach ( function ( ) {
1364
+ $rootScope . date = null ;
1365
+ $rootScope . opts = {
1366
+ 'initDate' : new Date ( 'November 9, 1980' )
1367
+ } ;
1368
+ var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup datepicker-options="opts" is-open="true"></div>' ) ( $rootScope ) ;
1369
+ $rootScope . $digest ( ) ;
1370
+ assignElements ( wrapElement ) ;
1371
+ } ) ;
1372
+
1373
+ it ( 'does not alter the model' , function ( ) {
1374
+ expect ( $rootScope . date ) . toBe ( null ) ;
1375
+ } ) ;
1376
+
1377
+ it ( 'shows the correct title' , function ( ) {
1378
+ expect ( getTitle ( ) ) . toBe ( 'November 1980' ) ;
1379
+ } ) ;
1380
+ } ) ;
1381
+ } ) ;
1382
+
1383
+ describe ( 'attribute `init-date`' , function ( ) {
1341
1384
beforeEach ( function ( ) {
1342
- $rootScope . opts = {
1343
- 'show-weeks' : false
1344
- } ;
1345
- var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup datepicker-options="opts" is-open="true"></div>' ) ( $rootScope ) ;
1346
- $rootScope . $digest ( ) ;
1347
- assignElements ( wrapElement ) ;
1385
+ $rootScope . date = null ;
1386
+ $rootScope . initDate = new Date ( 'November 9, 1980' ) ;
1387
+ } ) ;
1388
+
1389
+ describe ( 'when initially set' , function ( ) {
1390
+ beforeEach ( function ( ) {
1391
+ var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup init-date="initDate" is-open="true"></div>' ) ( $rootScope ) ;
1392
+ $rootScope . $digest ( ) ;
1393
+ assignElements ( wrapElement ) ;
1394
+ } ) ;
1395
+
1396
+ it ( 'does not alter the model' , function ( ) {
1397
+ expect ( $rootScope . date ) . toBe ( null ) ;
1398
+ } ) ;
1399
+
1400
+ it ( 'shows the correct title' , function ( ) {
1401
+ expect ( getTitle ( ) ) . toBe ( 'November 1980' ) ;
1402
+ } ) ;
1403
+ } ) ;
1404
+
1405
+ describe ( 'when modified before date selected.' , function ( ) {
1406
+ beforeEach ( function ( ) {
1407
+ var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup init-date="initDate" is-open="true"></div>' ) ( $rootScope ) ;
1408
+ $rootScope . $digest ( ) ;
1409
+ assignElements ( wrapElement ) ;
1410
+
1411
+ $rootScope . initDate = new Date ( 'December 20, 1981' ) ;
1412
+ $rootScope . $digest ( ) ;
1413
+ } ) ;
1414
+
1415
+ it ( 'does not alter the model' , function ( ) {
1416
+ expect ( $rootScope . date ) . toBe ( null ) ;
1417
+ } ) ;
1348
1418
1349
- weekHeader = getLabelsRow ( ) . find ( 'th' ) . eq ( 0 ) ;
1350
- weekElement = element . find ( 'tbody' ) . find ( 'tr' ) . eq ( 1 ) . find ( 'td' ) . eq ( 0 ) ;
1419
+ it ( 'shows the correct title' , function ( ) {
1420
+ expect ( getTitle ( ) ) . toBe ( 'December 1981' ) ;
1421
+ } ) ;
1351
1422
} ) ;
1352
1423
1353
- it ( 'hides week numbers based on variable' , function ( ) {
1354
- expect ( weekHeader . text ( ) ) . toEqual ( '' ) ;
1355
- expect ( weekHeader ) . toBeHidden ( ) ;
1356
- expect ( weekElement ) . toBeHidden ( ) ;
1424
+ describe ( 'when modified after date selected.' , function ( ) {
1425
+ beforeEach ( function ( ) {
1426
+ var wrapElement = $compile ( '<div><input ng-model="date" datepicker-popup init-date="initDate" is-open="true"></div>' ) ( $rootScope ) ;
1427
+ $rootScope . $digest ( ) ;
1428
+ assignElements ( wrapElement ) ;
1429
+ $rootScope . date = new Date ( 'April 1, 1982' ) ;
1430
+ $rootScope . initDate = new Date ( 'December 20, 1981' ) ;
1431
+ $rootScope . $digest ( ) ;
1432
+ } ) ;
1433
+
1434
+ it ( 'does not alter the model' , function ( ) {
1435
+ expect ( $rootScope . date ) . toEqual ( new Date ( 'April 1, 1982' ) ) ;
1436
+ } ) ;
1437
+
1438
+ it ( 'shows the correct title' , function ( ) {
1439
+ expect ( getTitle ( ) ) . toBe ( 'April 1982' ) ;
1440
+ } ) ;
1357
1441
} ) ;
1358
1442
} ) ;
1359
1443
0 commit comments