@@ -5,7 +5,7 @@ describe('mdSidenav', function() {
5
5
var el ;
6
6
inject ( function ( $compile , $rootScope ) {
7
7
var parent = angular . element ( '<div>' ) ;
8
- el = angular . element ( '<md-sidenav ' + ( attrs || '' ) + '>' ) ;
8
+ el = angular . element ( '<md-sidenav ' + ( attrs || '' ) + '>' ) ;
9
9
parent . append ( el ) ;
10
10
$compile ( parent ) ( $rootScope ) ;
11
11
$rootScope . $apply ( ) ;
@@ -79,7 +79,6 @@ describe('mdSidenav', function() {
79
79
expect ( backdrop . length ) . toBe ( 0 ) ;
80
80
} ) ) ;
81
81
82
-
83
82
it ( 'should focus sidenav on open' , inject ( function ( $rootScope , $material , $document ) {
84
83
jasmine . mockElementFocus ( this ) ;
85
84
var el = setup ( 'md-is-open="show"' ) ;
@@ -92,11 +91,11 @@ describe('mdSidenav', function() {
92
91
it ( 'should focus child with md-sidenav-focus' , inject ( function ( $rootScope , $material , $document , $compile ) {
93
92
jasmine . mockElementFocus ( this ) ;
94
93
var parent = angular . element ( '<div>' ) ;
95
- var markup = '<md-sidenav md-is-open="show">' +
96
- ' <md-input-container><label>Label</label>' +
97
- ' <input type="text" md-sidenav-focus>' +
98
- ' </md-input-container>' +
99
- '<md-sidenav>' ;
94
+ var markup = '<md-sidenav md-is-open="show">' +
95
+ ' <md-input-container><label>Label</label>' +
96
+ ' <input type="text" md-sidenav-focus>' +
97
+ ' </md-input-container>' +
98
+ '<md-sidenav>' ;
100
99
var sidenavEl = angular . element ( markup ) ;
101
100
parent . append ( sidenavEl ) ;
102
101
$compile ( parent ) ( $rootScope ) ;
@@ -110,11 +109,11 @@ describe('mdSidenav', function() {
110
109
it ( 'should focus child with md-autofocus' , inject ( function ( $rootScope , $material , $document , $compile ) {
111
110
jasmine . mockElementFocus ( this ) ;
112
111
var parent = angular . element ( '<div>' ) ;
113
- var markup = '<md-sidenav md-is-open="show">' +
114
- '<md-input-container><label>Label</label>' +
115
- '<input type="text" md-autofocus>' +
116
- '</md-input-container>' +
117
- '<md-sidenav>' ;
112
+ var markup = '<md-sidenav md-is-open="show">' +
113
+ '<md-input-container><label>Label</label>' +
114
+ '<input type="text" md-autofocus>' +
115
+ '</md-input-container>' +
116
+ '<md-sidenav>' ;
118
117
var sidenavEl = angular . element ( markup ) ;
119
118
parent . append ( sidenavEl ) ;
120
119
$compile ( parent ) ( $rootScope ) ;
@@ -125,16 +124,15 @@ describe('mdSidenav', function() {
125
124
expect ( $document . activeElement ) . toBe ( focusEl [ 0 ] ) ;
126
125
} ) ) ;
127
126
128
-
129
127
it ( 'should focus on last md-sidenav-focus element' , inject ( function ( $rootScope , $material , $document , $compile ) {
130
128
jasmine . mockElementFocus ( this ) ;
131
129
var parent = angular . element ( '<div>' ) ;
132
- var markup = '<md-sidenav md-is-open="show">' +
133
- '<md-button md-sidenav-focus>Button</md-button>' +
134
- '<md-input-container><label>Label</label>' +
135
- '<input type="text" md-sidenav-focus>' +
136
- '</md-input-container>' +
137
- '<md-sidenav>' ;
130
+ var markup = '<md-sidenav md-is-open="show">' +
131
+ '<md-button md-sidenav-focus>Button</md-button>' +
132
+ '<md-input-container><label>Label</label>' +
133
+ '<input type="text" md-sidenav-focus>' +
134
+ '</md-input-container>' +
135
+ '<md-sidenav>' ;
138
136
var sidenavEl = angular . element ( markup ) ;
139
137
parent . append ( sidenavEl ) ;
140
138
$compile ( parent ) ( $rootScope ) ;
@@ -208,22 +206,27 @@ describe('mdSidenav', function() {
208
206
$material . flushInterimElement ( ) ;
209
207
}
210
208
211
- beforeEach ( inject ( function ( _$material_ , _$rootScope_ , _$timeout_ ) {
212
- $material = _$material_ ;
213
- $rootScope = _$rootScope_ ;
214
- $timeout = _$timeout_ ;
209
+ beforeEach ( inject ( function ( _$material_ , _$rootScope_ , _$timeout_ ) {
210
+ $material = _$material_ ;
211
+ $rootScope = _$rootScope_ ;
212
+ $timeout = _$timeout_ ;
215
213
} ) ) ;
216
214
217
-
218
- it ( 'should open(), close(), and toggle() with promises' , function ( ) {
215
+ it ( 'should open(), close(), and toggle() with promises' , function ( ) {
219
216
var el = setup ( '' ) ;
220
217
var scope = el . isolateScope ( ) ;
221
218
var controller = el . controller ( 'mdSidenav' ) ;
222
219
223
220
var openDone = 0 , closeDone = 0 , toggleDone = 0 ;
224
- var onOpen = function ( ) { openDone ++ ; } ;
225
- var onClose = function ( ) { closeDone ++ ; } ;
226
- var onToggle = function ( ) { toggleDone ++ ; } ;
221
+ var onOpen = function ( ) {
222
+ openDone ++ ;
223
+ } ;
224
+ var onClose = function ( ) {
225
+ closeDone ++ ;
226
+ } ;
227
+ var onToggle = function ( ) {
228
+ toggleDone ++ ;
229
+ } ;
227
230
228
231
controller
229
232
. open ( )
@@ -253,14 +256,17 @@ describe('mdSidenav', function() {
253
256
expect ( scope . isOpen ) . toBe ( true ) ;
254
257
} ) ;
255
258
256
-
257
- it ( 'should open() to work multiple times before close()' , function ( ) {
259
+ it ( 'should open() to work multiple times before close()' , function ( ) {
258
260
var el = setup ( '' ) ;
259
261
var controller = el . controller ( 'mdSidenav' ) ;
260
262
261
263
var openDone = 0 , closeDone = 0 ;
262
- var onOpen = function ( ) { openDone ++ ; } ;
263
- var onClose = function ( ) { closeDone ++ ; } ;
264
+ var onOpen = function ( ) {
265
+ openDone ++ ;
266
+ } ;
267
+ var onClose = function ( ) {
268
+ closeDone ++ ;
269
+ } ;
264
270
265
271
controller
266
272
. open ( )
@@ -288,12 +294,10 @@ describe('mdSidenav', function() {
288
294
describe ( '$mdSidenav Service' , function ( ) {
289
295
var $rootScope , $timeout ;
290
296
291
-
292
- beforeEach ( inject ( function ( _$rootScope_ , _$timeout_ ) {
293
- $rootScope = _$rootScope_ ;
294
- $timeout = _$timeout_ ;
295
- } ) ) ;
296
-
297
+ beforeEach ( inject ( function ( _$rootScope_ , _$timeout_ ) {
298
+ $rootScope = _$rootScope_ ;
299
+ $timeout = _$timeout_ ;
300
+ } ) ) ;
297
301
298
302
it ( 'should grab instance' , inject ( function ( $mdSidenav ) {
299
303
var el = setup ( 'md-component-id="left"' ) ;
@@ -344,27 +348,85 @@ describe('mdSidenav', function() {
344
348
expect ( instance . isLockedOpen ( ) ) . toBe ( true ) ;
345
349
} ) ) ;
346
350
347
- it ( 'should find a deferred instantiation' , inject ( function ( $mdSidenav ) {
348
- var instance ;
351
+ } ) ;
352
+
353
+ it ( 'should find an instantiation using `$mdSidenav(id)`' , inject ( function ( $mdSidenav ) {
354
+ var el = setup ( 'md-component-id="left"' ) ;
355
+ $timeout . flush ( ) ;
349
356
350
- // Lookup deferred (not existing) instance
351
- $mdSidenav ( 'left' ) . then ( function ( inst ) { instance = inst ; } ) ;
352
- expect ( instance ) . toBeUndefined ( ) ;
357
+ // Lookup instance still available in the component registry
358
+ var instance = $mdSidenav ( 'left' ) ;
359
+ expect ( instance ) . toBeTruthy ( ) ;
360
+ } ) ) ;
353
361
354
- // Instantiate `left` sidenav component
355
- var el = setup ( 'md-component-id="left"' ) ;
362
+ it ( 'should find a deferred instantiation using `$mdSidenav(id, true)`' , inject ( function ( $mdSidenav ) {
363
+ var instance ;
356
364
357
- $timeout . flush ( ) ;
358
- expect ( instance ) . toBeTruthy ( ) ;
359
- expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
365
+ // Lookup deferred (not existing) instance
366
+ $mdSidenav ( 'left' , true ) . then ( function ( inst ) {
367
+ instance = inst ;
368
+ } ) ;
369
+ expect ( instance ) . toBeUndefined ( ) ;
360
370
361
- // Lookup instance still available in the component registry
362
- instance = undefined ;
363
- instance = $mdSidenav ( 'left' ) ;
371
+ // Instantiate `left` sidenav component
372
+ var el = setup ( 'md-component-id="left"' ) ;
373
+ $timeout . flush ( ) ;
364
374
365
- expect ( instance ) . toBeTruthy ( ) ;
375
+ expect ( instance ) . toBeDefined ( ) ;
376
+ expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
366
377
367
- } ) ) ;
368
- } ) ;
378
+ // Lookup instance still available in the component registry
379
+ instance = $mdSidenav ( 'left' , true ) ;
380
+ expect ( instance ) . toBeTruthy ( ) ;
381
+ } ) ) ;
382
+
383
+ it ( 'should find a deferred instantiation using `$mdSidenav().waitFor(id)` ' , inject ( function ( $mdSidenav ) {
384
+ var instance ;
385
+
386
+ // Lookup deferred (not existing) instance
387
+ $mdSidenav ( ) . waitFor ( 'left' ) . then ( function ( inst ) {
388
+ instance = inst ;
389
+ } ) ;
390
+ expect ( instance ) . toBeUndefined ( ) ;
391
+
392
+ // Instantiate `left` sidenav component
393
+ var el = setup ( 'md-component-id="left"' ) ;
394
+ $timeout . flush ( ) ;
395
+
396
+ expect ( instance ) . toBeDefined ( ) ;
397
+ expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
398
+
399
+ // Lookup instance still available in the component registry
400
+ instance = undefined ;
401
+ instance = $mdSidenav ( 'left' ) ;
402
+
403
+ expect ( instance ) . toBeTruthy ( ) ;
404
+ } ) ) ;
405
+
406
+ it ( 'should not find a lazy instantiation without waiting `$mdSidenav(id)`' , inject ( function ( $mdSidenav ) {
407
+ var instance = $mdSidenav ( 'left' ) ;
408
+ expect ( instance ) . toBeUndefined ( ) ;
409
+
410
+ // Instantiate `left` sidenav component
411
+ var el = setup ( 'md-component-id="left"' ) ;
412
+ $timeout . flush ( ) ;
413
+
414
+ instance = $mdSidenav ( 'left' ) ;
415
+ expect ( instance ) . toBeDefined ( ) ;
416
+ expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
417
+ } ) ) ;
418
+
419
+ it ( 'should not find a lazy instantiation without waiting `$mdSidenav().find(id)`' , inject ( function ( $mdSidenav ) {
420
+ var instance = $mdSidenav ( ) . find ( 'left' ) ;
421
+ expect ( instance ) . toBeUndefined ( ) ;
422
+
423
+ // Instantiate `left` sidenav component
424
+ var el = setup ( 'md-component-id="left"' ) ;
425
+ $timeout . flush ( ) ;
426
+
427
+ instance = $mdSidenav ( ) . find ( 'left' ) ;
428
+ expect ( instance ) . toBeDefined ( ) ;
429
+ expect ( instance . isOpen ( ) ) . toBeFalsy ( ) ;
430
+ } ) ) ;
369
431
370
432
} ) ;
0 commit comments