From d6bf79b461b021c7a35e5757b901762a4beac929 Mon Sep 17 00:00:00 2001 From: Chris Chua Date: Thu, 5 Dec 2013 13:21:55 -0800 Subject: [PATCH] chore(tabs): Add tests for nested tabs Relates to #783 --- src/tabs/test/tabs.spec.js | 109 +++++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/src/tabs/test/tabs.spec.js b/src/tabs/test/tabs.spec.js index 244c907066..8e7f41f813 100644 --- a/src/tabs/test/tabs.spec.js +++ b/src/tabs/test/tabs.spec.js @@ -664,4 +664,113 @@ describe('tabs', function() { expect(contents.eq(2).text().trim()).toEqual('3,4,5,'); })); }); + + //https://github.com/angular-ui/bootstrap/issues/783 + describe('nested tabs', function() { + var elm; + it('should render without errors', inject(function($compile, $rootScope) { + var scope = $rootScope.$new(); + elm = $compile([ + '
', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '
' + ].join('\n'))(scope); + scope.$apply(); + + // 1 outside tabset, 2 nested tabsets + expect(elm.find('.tabbable').length).toEqual(3); + })); + + it('should render with the correct scopes', inject(function($compile, $rootScope) { + var scope = $rootScope.$new(); + scope.tab1Text = 'abc'; + scope.tab1aText = '123'; + scope.tab1aHead = '123'; + scope.tab2aaText = '456'; + elm = $compile([ + '
', + ' ', + ' ', + ' ', + ' ', + ' {{ tab1aText }}', + ' ', + ' ', + ' {{ tab1Text }}', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + ' {{ tab2aaText }}', + ' ', + ' ', + ' ', + ' ', + ' ', + ' ', + '
' + ].join('\n'))(scope); + scope.$apply(); + + var outsideTabset = elm.find('.tabbable').eq(0); + var nestedTabset = outsideTabset.find('.tabbable'); + + expect(elm.find('.tabbable').length).toEqual(4); + expect(outsideTabset.find('.tab-pane').eq(0).find('.tab-1').text().trim()).toEqual(scope.tab1Text); + expect(nestedTabset.find('.tab-pane').eq(0).text().trim()).toEqual(scope.tab1aText); + expect(nestedTabset.find('ul.nav-tabs li').eq(0).text().trim()).toEqual(scope.tab1aHead); + expect(nestedTabset.eq(2).find('.tab-pane').eq(0).find('.tab-2aa').text().trim()).toEqual(scope.tab2aaText); + })); + + it('ng-repeat works with nested tabs', inject(function($compile, $rootScope) { + var scope = $rootScope.$new(); + scope.tabs = [ + { + tabs: [ + { + content: 'tab1a' + }, + { + content: 'tab2a' + } + ], + content: 'tab1' + } + ]; + elm = $compile([ + '
', + ' ', + ' ', + ' ', + ' ', + ' {{ innerTab.content }}', + ' ', + ' ', + ' {{ tab.content }}', + ' ', + ' ', + '
' + ].join('\n'))(scope); + scope.$apply(); + + expect(elm.find('.inner-tab-content').eq(0).text().trim()).toEqual(scope.tabs[0].tabs[0].content); + expect(elm.find('.inner-tab-content').eq(1).text().trim()).toEqual(scope.tabs[0].tabs[1].content); + expect(elm.find('.outer-tab-content').eq(0).text().trim()).toEqual(scope.tabs[0].content); + })); + }); });