Skip to content

Commit

Permalink
Cleaned up tests and tab is_active method.
Browse files Browse the repository at this point in the history
  • Loading branch information
rpocklin committed May 10, 2016
1 parent 8f61439 commit 79c2c3b
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
18 changes: 9 additions & 9 deletions src/ui-router-tabs.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
}
});
Expand All @@ -108,18 +108,18 @@ angular.module('ui.router.tabs').directive(
).run(
['$templateCache', function($templateCache) {
var CUSTOM_UI_VIEW_TEMPLATE = '<div>' +
'<uib-tabset class="tab-container" type="{{type}}" vertical="{{vertical}}" justified="{{justified}}" class="{{class}}">' +
'<uib-tab class="tab {{tab.class}}" ng-repeat="tab in tabs"' +
'active="tabs.active" disable="tab.disable" ng-click="go(tab)">' +
'<uib-tabset active="tabs.active" class="tab-container" type="{{type}}" vertical="{{vertical}}" justified="{{justified}}" class="{{class}}">' +
'<uib-tab class="tab {{tab.class}}" ng-repeat="tab in tabs" ' +
'disable="tab.disable" ng-click="go(tab)">' +
'<uib-tab-heading ng-bind-html="tab.heading"></uib-tab-heading>' +
'</uib-tab>' +
'</uib-tabset>' +
'</div>';

var INLINE_TEMPLATE =
'<uib-tabset class="tab-container" type="{{type}}" vertical="{{vertical}}" justified="{{justified}}" class="{{class}}">' +
'<uib-tab class="tab {{tab.class}}" ng-repeat="tab in tabs"' +
'active="tabs.active" disable="tab.disable" ng-click="go(tab)">' +
'<uib-tabset active="tabs.active" class="tab-container" type="{{type}}" vertical="{{vertical}}" justified="{{justified}}" class="{{class}}">' +
'<uib-tab class="tab {{tab.class}}" ng-repeat="tab in tabs" ' +
'disable="tab.disable" ng-click="go(tab)">' +
'<ui-view></ui-view>' +
'<uib-tab-heading ng-bind-html="tab.heading"></uib-tab-heading>' +
'</uib-tab>' +
Expand Down
18 changes: 5 additions & 13 deletions src/ui-router-tabs.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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 = '<tabs data="tabConfiguration"></tabs>';
renderView();
Expand All @@ -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() {
Expand All @@ -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() {
Expand All @@ -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() {
Expand Down

0 comments on commit 79c2c3b

Please sign in to comment.