1
1
describe ( 'mdSidenav' , function ( ) {
2
2
beforeEach ( module ( 'material.components.sidenav' ) ) ;
3
3
4
- function setup ( attrs ) {
4
+ function setup ( attrs , skipInitialDigest ) {
5
5
var el ;
6
6
inject ( function ( $compile , $rootScope ) {
7
7
var parent = angular . element ( '<div>' ) ;
8
8
el = angular . element ( '<md-sidenav ' + ( attrs || '' ) + '>' ) ;
9
9
parent . append ( el ) ;
10
10
$compile ( parent ) ( $rootScope ) ;
11
- $rootScope . $apply ( ) ;
11
+ ! skipInitialDigest && $rootScope . $apply ( ) ;
12
12
} ) ;
13
13
return el ;
14
14
}
@@ -225,13 +225,13 @@ describe('mdSidenav', function() {
225
225
226
226
describe ( 'controller' , function ( ) {
227
227
it ( 'should create controller' , function ( ) {
228
- var el = setup ( '' ) ;
228
+ var el = setup ( ) ;
229
229
var controller = el . controller ( 'mdSidenav' ) ;
230
230
expect ( controller ) . not . toBe ( undefined ) ;
231
231
} ) ;
232
232
233
233
it ( 'should open and close and toggle' , inject ( function ( $timeout ) {
234
- var el = setup ( '' ) ;
234
+ var el = setup ( ) ;
235
235
var scope = el . isolateScope ( ) ;
236
236
var controller = el . controller ( 'mdSidenav' ) ;
237
237
@@ -270,7 +270,7 @@ describe('mdSidenav', function() {
270
270
} ) ) ;
271
271
272
272
it ( 'should open(), close(), and toggle() with promises' , function ( ) {
273
- var el = setup ( '' ) ;
273
+ var el = setup ( ) ;
274
274
var scope = el . isolateScope ( ) ;
275
275
var controller = el . controller ( 'mdSidenav' ) ;
276
276
@@ -314,7 +314,7 @@ describe('mdSidenav', function() {
314
314
} ) ;
315
315
316
316
it ( 'should open() to work multiple times before close()' , function ( ) {
317
- var el = setup ( '' ) ;
317
+ var el = setup ( ) ;
318
318
var controller = el . controller ( 'mdSidenav' ) ;
319
319
320
320
var openDone = 0 , closeDone = 0 ;
@@ -408,23 +408,35 @@ describe('mdSidenav', function() {
408
408
} ) ;
409
409
410
410
describe ( '$mdSidenav lookups' , function ( ) {
411
- var $rootScope , $timeout ;
411
+ var $rootScope , $timeout , $mdSidenav ;
412
412
413
- beforeEach ( inject ( function ( _$rootScope_ , _$timeout_ ) {
413
+ beforeEach ( inject ( function ( _$rootScope_ , _$timeout_ , _$mdSidenav_ ) {
414
414
$rootScope = _$rootScope_ ;
415
415
$timeout = _$timeout_ ;
416
+ $mdSidenav = _$mdSidenav_ ;
416
417
} ) ) ;
417
418
418
- it ( 'should find an instantiation using `$mdSidenav(id)`' , inject ( function ( $mdSidenav ) {
419
+ it ( 'should find an instantiation using `$mdSidenav(id)`' , function ( ) {
419
420
var el = setup ( 'md-component-id="left"' ) ;
420
421
$timeout . flush ( ) ;
421
422
422
423
// Lookup instance still available in the component registry
423
424
var instance = $mdSidenav ( 'left' ) ;
424
425
expect ( instance ) . toBeTruthy ( ) ;
425
- } ) ) ;
426
+ } ) ;
426
427
427
- it ( 'should find a deferred instantiation using `$mdSidenav(id, true)`' , inject ( function ( $mdSidenav ) {
428
+ it ( 'should support data bindings' , function ( ) {
429
+ // It should work on init.
430
+ $rootScope . leftComponentId = 'left' ;
431
+ setup ( 'md-component-id="{{ leftComponentId }}"' , true ) ;
432
+ expect ( $mdSidenav ( $rootScope . leftComponentId , false ) ) . toBeTruthy ( ) ;
433
+
434
+ // It should also work if the data binding has changed.
435
+ $rootScope . $apply ( 'leftComponentId = "otherLeft"' ) ;
436
+ expect ( $mdSidenav ( $rootScope . leftComponentId , false ) ) . toBeTruthy ( ) ;
437
+ } ) ;
438
+
439
+ it ( 'should find a deferred instantiation using `$mdSidenav(id, true)`' , function ( ) {
428
440
var instance ;
429
441
430
442
// Lookup deferred (not existing) instance
@@ -443,9 +455,9 @@ describe('mdSidenav', function() {
443
455
// Lookup instance still available in the component registry
444
456
instance = $mdSidenav ( 'left' , true ) ;
445
457
expect ( instance ) . toBeTruthy ( ) ;
446
- } ) ) ;
458
+ } ) ;
447
459
448
- it ( 'should find a deferred instantiation using `$mdSidenav().waitFor(id)` ' , inject ( function ( $mdSidenav ) {
460
+ it ( 'should find a deferred instantiation using `$mdSidenav().waitFor(id)` ' , function ( ) {
449
461
var instance ;
450
462
451
463
// Lookup deferred (not existing) instance
@@ -466,9 +478,9 @@ describe('mdSidenav', function() {
466
478
instance = $mdSidenav ( 'left' ) ;
467
479
468
480
expect ( instance ) . toBeTruthy ( ) ;
469
- } ) ) ;
481
+ } ) ;
470
482
471
- it ( 'should not find a lazy instantiation without waiting `$mdSidenav(id)`' , inject ( function ( $mdSidenav ) {
483
+ it ( 'should not find a lazy instantiation without waiting `$mdSidenav(id)`' , function ( ) {
472
484
var instance = $mdSidenav ( 'left' ) ;
473
485
expect ( instance . isOpen ) . toBeDefined ( ) ; // returns legacy API with noops
474
486
@@ -482,9 +494,9 @@ describe('mdSidenav', function() {
482
494
instance = $mdSidenav ( 'left' ) ; // returns instance
483
495
expect ( instance ) . toBeDefined ( ) ;
484
496
expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
485
- } ) ) ;
497
+ } ) ;
486
498
487
- it ( 'should not find a lazy instantiation without waiting `$mdSidenav().find(id)`' , inject ( function ( $mdSidenav ) {
499
+ it ( 'should not find a lazy instantiation without waiting `$mdSidenav().find(id)`' , function ( ) {
488
500
var instance = $mdSidenav ( ) . find ( 'left' ) ;
489
501
expect ( instance ) . toBeUndefined ( ) ;
490
502
@@ -495,7 +507,7 @@ describe('mdSidenav', function() {
495
507
instance = $mdSidenav ( ) . find ( 'left' ) ;
496
508
expect ( instance ) . toBeDefined ( ) ;
497
509
expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
498
- } ) ) ;
510
+ } ) ;
499
511
500
512
describe ( 'onClose' , function ( ) {
501
513
it ( 'should call callback on escape' , inject ( function ( $mdSidenav , $rootScope , $material , $mdConstant , $timeout ) {
0 commit comments