From 79c2c3b5745675d7f9a886f56e2da21b1763389e Mon Sep 17 00:00:00 2001 From: Rob Pocklington Date: Tue, 10 May 2016 22:47:25 +1000 Subject: [PATCH] Cleaned up tests and tab is_active method. --- src/ui-router-tabs.js | 18 +++++++++--------- src/ui-router-tabs.spec.js | 18 +++++------------- 2 files changed, 14 insertions(+), 22 deletions(-) diff --git a/src/ui-router-tabs.js b/src/ui-router-tabs.js index 93a6b22..8547403 100644 --- a/src/ui-router-tabs.js +++ b/src/ui-router-tabs.js @@ -77,7 +77,7 @@ angular.module('ui.router.tabs').directive( }; /* whether to highlight given route as part of the current state */ - $scope.active = function(tab) { + $scope.is_active = function(tab) { var isAncestorOfCurrentRoute = $state.includes(tab.route, tab.params, tab.options); return isAncestorOfCurrentRoute; @@ -90,9 +90,9 @@ angular.module('ui.router.tabs').directive( tab.params = tab.params || {}; tab.options = tab.options || {}; tab.class = tab.class || ''; - tab.active = $scope.active(tab); - if ($scope.active(tab)) { + tab.active = $scope.is_active(tab); + if (tab.active) { $scope.tabs.active = index; } }); @@ -108,18 +108,18 @@ angular.module('ui.router.tabs').directive( ).run( ['$templateCache', function($templateCache) { var CUSTOM_UI_VIEW_TEMPLATE = '
' + - '' + - '' + + '' + + '' + '' + '' + '' + '
'; var INLINE_TEMPLATE = - '' + - '' + + '' + + '' + '' + '' + '' + diff --git a/src/ui-router-tabs.spec.js b/src/ui-router-tabs.spec.js index 6cbe905..69646df 100644 --- a/src/ui-router-tabs.spec.js +++ b/src/ui-router-tabs.spec.js @@ -20,27 +20,23 @@ beforeEach(function() { $stateProvider .state('menu', { url: '/menu', - class: 'menu', resolve: { data: loadData } }) .state('menu.route1', { url: '/route1', - class: 'route1', resolve: { data: loadData } }).state('menu.route2', { url: '/route2', - class: 'route2', resolve: { data: loadData } }) .state('notabs', { url: '/notabs', - class: 'notabs', resolve: { data: loadData } @@ -155,16 +151,12 @@ describe('Directive : UI Router : Tabs', function() { var tabIndex = 2; var route = scope.tabConfiguration[tabIndex].route; - //var route = _.find(scope.tabConfiguration, { - // route: 'menu.route2' - //}); - //console.log(route); state.go(route); scope.$apply(); expect(get_current_state()).toEqual(route); - expect($ngView.find('.nav li ' + scope.tabConfiguration[tabIndex].class).attr('class')).toMatch('active'); + expect(scope.tabConfiguration[tabIndex].active).toBeTruthy(); }); it('should change the route and update the tabs when selecting a different tab', function() { @@ -178,7 +170,7 @@ describe('Directive : UI Router : Tabs', function() { expect(get_current_state()).not.toEqual(previous_state); }); - iit('should not change the route or active tab heading if a $stateChangeStart handler cancels the route change', function() { + it('should not change the route or active tab heading if a $stateChangeStart handler cancels the route change', function() { view = ''; renderView(); @@ -200,7 +192,7 @@ describe('Directive : UI Router : Tabs', function() { scope.$apply(); expect(get_current_state()).toEqual(initialRoute); - expect($ngView.find('.nav li' + scope.tabConfiguration[initialTabIndex].class).attr('class')).toMatch('active'); + expect(scope.tabConfiguration[initialTabIndex].active).toBeTruthy(); }); it('should not change the route or active tab heading if a $stateChangeError event triggers during the route change', function() { @@ -223,7 +215,7 @@ describe('Directive : UI Router : Tabs', function() { scope.$apply(); expect(get_current_state()).toEqual(initialRoute); - expect($ngView.find('.nav li' + scope.tabConfiguration[initialTabIndex].class).attr('class')).toMatch('active'); + expect(scope.tabConfiguration[initialTabIndex].active).toBeTruthy(); }); it('should not change the route or active tab heading if a $stateNotFound event triggers during the route change', function() { @@ -250,7 +242,7 @@ describe('Directive : UI Router : Tabs', function() { scope.$apply(); expect(get_current_state()).toEqual(initialRoute); - expect($ngView.find('.nav li' + scope.tabConfiguration[initialTabIndex].class).attr('class')).toMatch('active'); + expect(scope.tabConfiguration[initialTabIndex].active).toBeTruthy(); }); it('should not change the route when selecting the current tab', function() {