@@ -664,4 +664,113 @@ describe('tabs', function() {
664
664
expect ( contents . eq ( 2 ) . text ( ) . trim ( ) ) . toEqual ( '3,4,5,' ) ;
665
665
} ) ) ;
666
666
} ) ;
667
+
668
+ //https://github.com/angular-ui/bootstrap/issues/783
669
+ describe ( 'nested tabs' , function ( ) {
670
+ var elm ;
671
+ it ( 'should render without errors' , inject ( function ( $compile , $rootScope ) {
672
+ var scope = $rootScope . $new ( ) ;
673
+ elm = $compile ( [
674
+ '<div>' ,
675
+ ' <tabset>' ,
676
+ ' <tab heading="Tab 1">' ,
677
+ ' <tabset>' ,
678
+ ' <tab heading="Tab 1A">' ,
679
+ ' </tab>' ,
680
+ ' </tabset>' ,
681
+ ' </tab>' ,
682
+ ' <tab heading="Tab 2">' ,
683
+ ' <tabset>' ,
684
+ ' <tab heading="Tab 2A">' ,
685
+ ' </tab>' ,
686
+ ' </tabset>' ,
687
+ ' </tab>' ,
688
+ ' </tabset>' ,
689
+ '</div>'
690
+ ] . join ( '\n' ) ) ( scope ) ;
691
+ scope . $apply ( ) ;
692
+
693
+ // 1 outside tabset, 2 nested tabsets
694
+ expect ( elm . find ( '.tabbable' ) . length ) . toEqual ( 3 ) ;
695
+ } ) ) ;
696
+
697
+ it ( 'should render with the correct scopes' , inject ( function ( $compile , $rootScope ) {
698
+ var scope = $rootScope . $new ( ) ;
699
+ scope . tab1Text = 'abc' ;
700
+ scope . tab1aText = '123' ;
701
+ scope . tab1aHead = '123' ;
702
+ scope . tab2aaText = '456' ;
703
+ elm = $compile ( [
704
+ '<div>' ,
705
+ ' <tabset>' ,
706
+ ' <tab heading="Tab 1">' ,
707
+ ' <tabset>' ,
708
+ ' <tab heading="{{ tab1aHead }}">' ,
709
+ ' {{ tab1aText }}' ,
710
+ ' </tab>' ,
711
+ ' </tabset>' ,
712
+ ' <span class="tab-1">{{ tab1Text }}</span>' ,
713
+ ' </tab>' ,
714
+ ' <tab heading="Tab 2">' ,
715
+ ' <tabset>' ,
716
+ ' <tab heading="Tab 2A">' ,
717
+ ' <tabset>' ,
718
+ ' <tab heading="Tab 2AA">' ,
719
+ ' <span class="tab-2aa">{{ tab2aaText }}</span>' ,
720
+ ' </tab>' ,
721
+ ' </tabset>' ,
722
+ ' </tab>' ,
723
+ ' </tabset>' ,
724
+ ' </tab>' ,
725
+ ' </tabset>' ,
726
+ '</div>'
727
+ ] . join ( '\n' ) ) ( scope ) ;
728
+ scope . $apply ( ) ;
729
+
730
+ var outsideTabset = elm . find ( '.tabbable' ) . eq ( 0 ) ;
731
+ var nestedTabset = outsideTabset . find ( '.tabbable' ) ;
732
+
733
+ expect ( elm . find ( '.tabbable' ) . length ) . toEqual ( 4 ) ;
734
+ expect ( outsideTabset . find ( '.tab-pane' ) . eq ( 0 ) . find ( '.tab-1' ) . text ( ) . trim ( ) ) . toEqual ( scope . tab1Text ) ;
735
+ expect ( nestedTabset . find ( '.tab-pane' ) . eq ( 0 ) . text ( ) . trim ( ) ) . toEqual ( scope . tab1aText ) ;
736
+ expect ( nestedTabset . find ( 'ul.nav-tabs li' ) . eq ( 0 ) . text ( ) . trim ( ) ) . toEqual ( scope . tab1aHead ) ;
737
+ expect ( nestedTabset . eq ( 2 ) . find ( '.tab-pane' ) . eq ( 0 ) . find ( '.tab-2aa' ) . text ( ) . trim ( ) ) . toEqual ( scope . tab2aaText ) ;
738
+ } ) ) ;
739
+
740
+ it ( 'ng-repeat works with nested tabs' , inject ( function ( $compile , $rootScope ) {
741
+ var scope = $rootScope . $new ( ) ;
742
+ scope . tabs = [
743
+ {
744
+ tabs : [
745
+ {
746
+ content : 'tab1a'
747
+ } ,
748
+ {
749
+ content : 'tab2a'
750
+ }
751
+ ] ,
752
+ content : 'tab1'
753
+ }
754
+ ] ;
755
+ elm = $compile ( [
756
+ '<div>' ,
757
+ ' <tabset>' ,
758
+ ' <tab ng-repeat="tab in tabs">' ,
759
+ ' <tabset>' ,
760
+ ' <tab ng-repeat="innerTab in tab.tabs">' ,
761
+ ' <span class="inner-tab-content">{{ innerTab.content }}</span>' ,
762
+ ' </tab>' ,
763
+ ' </tabset>' ,
764
+ ' <span class="outer-tab-content">{{ tab.content }}</span>' ,
765
+ ' </tab>' ,
766
+ ' </tabset>' ,
767
+ '</div>'
768
+ ] . join ( '\n' ) ) ( scope ) ;
769
+ scope . $apply ( ) ;
770
+
771
+ expect ( elm . find ( '.inner-tab-content' ) . eq ( 0 ) . text ( ) . trim ( ) ) . toEqual ( scope . tabs [ 0 ] . tabs [ 0 ] . content ) ;
772
+ expect ( elm . find ( '.inner-tab-content' ) . eq ( 1 ) . text ( ) . trim ( ) ) . toEqual ( scope . tabs [ 0 ] . tabs [ 1 ] . content ) ;
773
+ expect ( elm . find ( '.outer-tab-content' ) . eq ( 0 ) . text ( ) . trim ( ) ) . toEqual ( scope . tabs [ 0 ] . content ) ;
774
+ } ) ) ;
775
+ } ) ;
667
776
} ) ;
0 commit comments