@@ -278,58 +278,127 @@ describe('uiSrefActive', function() {
278
278
url : '/:id' ,
279
279
} ) . state ( 'contacts.item.detail' , {
280
280
url : '/detail/:foo'
281
+ } ) . state ( 'contacts.item.edit' , {
282
+ url : '/edit'
281
283
} ) ;
282
284
} ) ) ;
283
285
284
286
beforeEach ( inject ( function ( $document ) {
285
287
document = $document [ 0 ] ;
286
288
} ) ) ;
287
289
288
- it ( 'should update class for sibling uiSref' , inject ( function ( $rootScope , $q , $compile , $state ) {
290
+ it ( 'should update class for sibling uiSref' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
289
291
el = angular . element ( '<div><a ui-sref="contacts" ui-sref-active="active">Contacts</a></div>' ) ;
290
292
template = $compile ( el ) ( $rootScope ) ;
291
293
$rootScope . $digest ( ) ;
294
+ $timeout . flush ( ) ; // emitEvent timeout hacks
292
295
293
- expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
296
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
297
+ $state . transitionTo ( 'contacts' ) ;
298
+ $timeout . flush ( ) ; // emitEvent timeout hacks
299
+ $q . flush ( ) ;
300
+
301
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
302
+
303
+ $state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
304
+ $timeout . flush ( ) ; // emitEvent timeout hacks
305
+ $q . flush ( ) ;
306
+
307
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active-nested' ) ;
308
+ } ) ) ;
309
+
310
+ it ( 'should update class for decendant uiSrefs' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
311
+ el = angular . element ( '<section><div ui-sref-active="active"><p ng-init="newScope=1"><a ui-sref="contacts">Contacts</a></p></div></section>' ) ;
312
+ template = $compile ( el ) ( $rootScope ) ;
313
+ $rootScope . $digest ( ) ;
314
+ $timeout . flush ( ) ; // emitEvent timeout hacks
315
+
316
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'div' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
294
317
$state . transitionTo ( 'contacts' ) ;
318
+ $timeout . flush ( ) ; // emitEvent timeout hacks
295
319
$q . flush ( ) ;
296
320
297
- expect ( angular . element ( template [ 0 ] . querySelector ( 'a ' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
321
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'div ' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
298
322
299
323
$state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
324
+ $timeout . flush ( ) ; // emitEvent timeout hacks
300
325
$q . flush ( ) ;
301
- expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
326
+
327
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'div' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active-nested' ) ;
302
328
} ) ) ;
303
329
304
- it ( 'should match state\'s parameters' , inject ( function ( $rootScope , $q , $compile , $state ) {
330
+ it ( 'should not update class for sibling elements with uiSrefs' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
331
+ el = angular . element ( '<section><div ui-sref-active="active"></div><a ui-sref="contacts">Contacts</a></section>' ) ;
332
+ template = $compile ( el ) ( $rootScope ) ;
333
+ $rootScope . $digest ( ) ;
334
+ $timeout . flush ( ) ; // emitEvent timeout hacks
335
+
336
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'div' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
337
+ $state . transitionTo ( 'contacts' ) ;
338
+ $timeout . flush ( ) ; // emitEvent timeout hacks
339
+ $q . flush ( ) ;
340
+
341
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'div' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
342
+
343
+ $state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
344
+ $timeout . flush ( ) ; // emitEvent timeout hacks
345
+ $q . flush ( ) ;
346
+
347
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'div' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
348
+ } ) ) ;
349
+
350
+ it ( 'should match state\'s parameters' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
305
351
el = angular . element ( '<div><a ui-sref="contacts.item.detail({ foo: \'bar\' })" ui-sref-active="active">Contacts</a></div>' ) ;
306
352
template = $compile ( el ) ( $rootScope ) ;
307
353
$rootScope . $digest ( ) ;
354
+ $timeout . flush ( ) ; // emitEvent timeout hacks
308
355
309
- expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
356
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope ' ) ;
310
357
$state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'bar' } ) ;
311
358
$q . flush ( ) ;
312
- expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'active' ) ;
359
+ $timeout . flush ( ) ; // emitEvent timeout hacks
360
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
313
361
314
362
$state . transitionTo ( 'contacts.item.detail' , { id : 5 , foo : 'baz' } ) ;
315
363
$q . flush ( ) ;
316
- expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( '' ) ;
364
+ $timeout . flush ( ) ; // emitEvent timeout hacks
365
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
366
+ } ) ) ;
367
+
368
+ it ( 'should match child states' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
369
+ el = angular . element ( '<div><a ui-sref="contacts.item({ id: 1 })" ui-sref-active="active">Contacts</a></div>' ) ;
370
+ template = $compile ( el ) ( $rootScope ) ;
371
+ $rootScope . $digest ( ) ;
372
+ $timeout . flush ( ) ; // emitEvent timeout hacks
373
+
374
+ $state . transitionTo ( 'contacts.item.edit' , { id : 1 } ) ;
375
+ $q . flush ( ) ;
376
+ $timeout . flush ( ) ; // emitEvent timeout hacks
377
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active-nested' ) ;
378
+
379
+ $state . transitionTo ( 'contacts.item.edit' , { id : 4 } ) ;
380
+ $q . flush ( ) ;
381
+ $timeout . flush ( ) ; // emitEvent timeout hacks
382
+ expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
317
383
} ) ) ;
318
384
319
- it ( 'should resolve relative state refs' , inject ( function ( $rootScope , $q , $compile , $state ) {
385
+ it ( 'should resolve relative state refs' , inject ( function ( $rootScope , $q , $compile , $state , $timeout ) {
320
386
el = angular . element ( '<section><div ui-view></div></section>' ) ;
321
387
template = $compile ( el ) ( $rootScope ) ;
322
388
$rootScope . $digest ( ) ;
323
389
324
390
$state . transitionTo ( 'contacts' ) ;
391
+ $timeout . flush ( ) ; // emitEvent timeout hacks
325
392
$q . flush ( ) ;
326
393
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
327
394
328
395
$state . transitionTo ( 'contacts.item' , { id : 6 } ) ;
396
+ $timeout . flush ( ) ; // emitEvent timeout hacks
329
397
$q . flush ( ) ;
330
398
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope active' ) ;
331
399
332
400
$state . transitionTo ( 'contacts.item' , { id : 5 } ) ;
401
+ $timeout . flush ( ) ; // emitEvent timeout hacks
333
402
$q . flush ( ) ;
334
403
expect ( angular . element ( template [ 0 ] . querySelector ( 'a' ) ) . attr ( 'class' ) ) . toBe ( 'ng-scope' ) ;
335
404
} ) ) ;
0 commit comments