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
}
@@ -168,13 +168,13 @@ describe('mdSidenav', function() {
168
168
169
169
describe ( 'controller' , function ( ) {
170
170
it ( 'should create controller' , function ( ) {
171
- var el = setup ( '' ) ;
171
+ var el = setup ( ) ;
172
172
var controller = el . controller ( 'mdSidenav' ) ;
173
173
expect ( controller ) . not . toBe ( undefined ) ;
174
174
} ) ;
175
175
176
176
it ( 'should open and close and toggle' , inject ( function ( $timeout ) {
177
- var el = setup ( '' ) ;
177
+ var el = setup ( ) ;
178
178
var scope = el . isolateScope ( ) ;
179
179
var controller = el . controller ( 'mdSidenav' ) ;
180
180
@@ -213,7 +213,7 @@ describe('mdSidenav', function() {
213
213
} ) ) ;
214
214
215
215
it ( 'should open(), close(), and toggle() with promises' , function ( ) {
216
- var el = setup ( '' ) ;
216
+ var el = setup ( ) ;
217
217
var scope = el . isolateScope ( ) ;
218
218
var controller = el . controller ( 'mdSidenav' ) ;
219
219
@@ -257,7 +257,7 @@ describe('mdSidenav', function() {
257
257
} ) ;
258
258
259
259
it ( 'should open() to work multiple times before close()' , function ( ) {
260
- var el = setup ( '' ) ;
260
+ var el = setup ( ) ;
261
261
var controller = el . controller ( 'mdSidenav' ) ;
262
262
263
263
var openDone = 0 , closeDone = 0 ;
@@ -351,23 +351,35 @@ describe('mdSidenav', function() {
351
351
} ) ;
352
352
353
353
describe ( '$mdSidenav lookups' , function ( ) {
354
- var $rootScope , $timeout ;
354
+ var $rootScope , $timeout , $mdSidenav ;
355
355
356
- beforeEach ( inject ( function ( _$rootScope_ , _$timeout_ ) {
356
+ beforeEach ( inject ( function ( _$rootScope_ , _$timeout_ , _$mdSidenav_ ) {
357
357
$rootScope = _$rootScope_ ;
358
358
$timeout = _$timeout_ ;
359
+ $mdSidenav = _$mdSidenav_ ;
359
360
} ) ) ;
360
361
361
- it ( 'should find an instantiation using `$mdSidenav(id)`' , inject ( function ( $mdSidenav ) {
362
+ it ( 'should find an instantiation using `$mdSidenav(id)`' , function ( ) {
362
363
var el = setup ( 'md-component-id="left"' ) ;
363
364
$timeout . flush ( ) ;
364
365
365
366
// Lookup instance still available in the component registry
366
367
var instance = $mdSidenav ( 'left' ) ;
367
368
expect ( instance ) . toBeTruthy ( ) ;
368
- } ) ) ;
369
+ } ) ;
369
370
370
- it ( 'should find a deferred instantiation using `$mdSidenav(id, true)`' , inject ( function ( $mdSidenav ) {
371
+ it ( 'should support data bindings' , function ( ) {
372
+ // It should work on init.
373
+ $rootScope . leftComponentId = 'left' ;
374
+ setup ( 'md-component-id="{{ leftComponentId }}"' , true ) ;
375
+ expect ( $mdSidenav ( $rootScope . leftComponentId , false ) ) . toBeTruthy ( ) ;
376
+
377
+ // It should also work if the data binding has changed.
378
+ $rootScope . $apply ( 'leftComponentId = "otherLeft"' ) ;
379
+ expect ( $mdSidenav ( $rootScope . leftComponentId , false ) ) . toBeTruthy ( ) ;
380
+ } ) ;
381
+
382
+ it ( 'should find a deferred instantiation using `$mdSidenav(id, true)`' , function ( ) {
371
383
var instance ;
372
384
373
385
// Lookup deferred (not existing) instance
@@ -386,9 +398,9 @@ describe('mdSidenav', function() {
386
398
// Lookup instance still available in the component registry
387
399
instance = $mdSidenav ( 'left' , true ) ;
388
400
expect ( instance ) . toBeTruthy ( ) ;
389
- } ) ) ;
401
+ } ) ;
390
402
391
- it ( 'should find a deferred instantiation using `$mdSidenav().waitFor(id)` ' , inject ( function ( $mdSidenav ) {
403
+ it ( 'should find a deferred instantiation using `$mdSidenav().waitFor(id)` ' , function ( ) {
392
404
var instance ;
393
405
394
406
// Lookup deferred (not existing) instance
@@ -409,9 +421,9 @@ describe('mdSidenav', function() {
409
421
instance = $mdSidenav ( 'left' ) ;
410
422
411
423
expect ( instance ) . toBeTruthy ( ) ;
412
- } ) ) ;
424
+ } ) ;
413
425
414
- it ( 'should not find a lazy instantiation without waiting `$mdSidenav(id)`' , inject ( function ( $mdSidenav ) {
426
+ it ( 'should not find a lazy instantiation without waiting `$mdSidenav(id)`' , function ( ) {
415
427
var instance = $mdSidenav ( 'left' ) ;
416
428
expect ( instance . isOpen ) . toBeDefined ( ) ; // returns legacy API with noops
417
429
@@ -425,9 +437,9 @@ describe('mdSidenav', function() {
425
437
instance = $mdSidenav ( 'left' ) ; // returns instance
426
438
expect ( instance ) . toBeDefined ( ) ;
427
439
expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
428
- } ) ) ;
440
+ } ) ;
429
441
430
- it ( 'should not find a lazy instantiation without waiting `$mdSidenav().find(id)`' , inject ( function ( $mdSidenav ) {
442
+ it ( 'should not find a lazy instantiation without waiting `$mdSidenav().find(id)`' , function ( ) {
431
443
var instance = $mdSidenav ( ) . find ( 'left' ) ;
432
444
expect ( instance ) . toBeUndefined ( ) ;
433
445
@@ -438,7 +450,7 @@ describe('mdSidenav', function() {
438
450
instance = $mdSidenav ( ) . find ( 'left' ) ;
439
451
expect ( instance ) . toBeDefined ( ) ;
440
452
expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
441
- } ) ) ;
453
+ } ) ;
442
454
443
455
describe ( 'onClose' , function ( ) {
444
456
it ( 'should call callback on escape' , inject ( function ( $mdSidenav , $rootScope , $material , $mdConstant , $timeout ) {
0 commit comments