@@ -378,4 +378,80 @@ describe('tabs', function() {
378
378
expect ( contents ( ) . eq ( 2 ) ) . toHaveClass ( 'active' ) ;
379
379
} ) ) ;
380
380
} ) ;
381
+
382
+ describe ( 'disabled' , function ( ) {
383
+ beforeEach ( inject ( function ( $compile , $rootScope ) {
384
+ scope = $rootScope . $new ( ) ;
385
+
386
+ function makeTab ( disabled ) {
387
+ return {
388
+ active : false ,
389
+ select : jasmine . createSpy ( ) ,
390
+ disabled : disabled
391
+ } ;
392
+ }
393
+ scope . tabs = [
394
+ makeTab ( false ) , makeTab ( true ) , makeTab ( false ) , makeTab ( true )
395
+ ] ;
396
+ elm = $compile ( [
397
+ '<tabset>' ,
398
+ ' <tab ng-repeat="t in tabs" active="t.active" select="t.select()" disabled="t.disabled">' ,
399
+ ' <tab-heading><b>heading</b> {{index}}</tab-heading>' ,
400
+ ' content {{$index}}' ,
401
+ ' </tab>' ,
402
+ '</tabset>'
403
+ ] . join ( '\n' ) ) ( scope ) ;
404
+ scope . $apply ( ) ;
405
+ } ) ) ;
406
+
407
+ function titles ( ) {
408
+ return elm . find ( 'ul.nav-tabs li' ) ;
409
+ }
410
+ function contents ( ) {
411
+ return elm . find ( 'div.tab-content div.tab-pane' ) ;
412
+ }
413
+
414
+ function expectTabActive ( activeTab ) {
415
+ var _titles = titles ( ) ;
416
+ angular . forEach ( scope . tabs , function ( tab , i ) {
417
+ if ( activeTab === tab ) {
418
+ expect ( tab . active ) . toBe ( true ) ;
419
+ expect ( tab . select . callCount ) . toBe ( ( tab . disabled ) ? 0 : 1 ) ;
420
+ expect ( _titles . eq ( i ) ) . toHaveClass ( 'active' ) ;
421
+ expect ( contents ( ) . eq ( i ) . text ( ) . trim ( ) ) . toBe ( 'content ' + i ) ;
422
+ expect ( contents ( ) . eq ( i ) ) . toHaveClass ( 'active' ) ;
423
+ } else {
424
+ expect ( tab . active ) . toBe ( false ) ;
425
+ expect ( _titles . eq ( i ) ) . not . toHaveClass ( 'active' ) ;
426
+ }
427
+ } ) ;
428
+ }
429
+
430
+ it ( 'should not switch active when clicking on title' , function ( ) {
431
+ titles ( ) . eq ( 2 ) . find ( 'a' ) . click ( ) ;
432
+ expectTabActive ( scope . tabs [ 2 ] ) ;
433
+
434
+ titles ( ) . eq ( 3 ) . find ( 'a' ) . click ( ) ;
435
+ expectTabActive ( scope . tabs [ 2 ] ) ;
436
+ } ) ;
437
+
438
+ it ( 'should not switch active when setting active=true' , function ( ) {
439
+ scope . $apply ( 'tabs[2].active = true' ) ;
440
+ expectTabActive ( scope . tabs [ 2 ] ) ;
441
+
442
+ scope . $apply ( 'tabs[3].active = true' ) ;
443
+ expectTabActive ( scope . tabs [ 2 ] ) ;
444
+ } ) ;
445
+
446
+ it ( 'should toggle between states' , function ( ) {
447
+ expect ( titles ( ) . eq ( 3 ) ) . toHaveClass ( 'disabled' ) ;
448
+ scope . $apply ( 'tabs[3].disabled = false' ) ;
449
+ expect ( titles ( ) . eq ( 3 ) ) . not . toHaveClass ( 'disabled' ) ;
450
+
451
+ expect ( titles ( ) . eq ( 2 ) ) . not . toHaveClass ( 'disabled' ) ;
452
+ scope . $apply ( 'tabs[2].disabled = true' ) ;
453
+ expect ( titles ( ) . eq ( 2 ) ) . toHaveClass ( 'disabled' ) ;
454
+ } ) ;
455
+ } ) ;
456
+
381
457
} ) ;
0 commit comments