From 3b0af6c3394a88e8e306015b198fabb489a75843 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Tue, 25 Mar 2014 07:46:25 -0600 Subject: [PATCH] test(ionNavBar): add test for $destroy() -> $hasHeader = false --- js/ext/angular/src/directive/ionicNavBar.js | 15 ++++++++------- js/ext/angular/test/directive/ionicNavBar.unit.js | 7 +++++-- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/js/ext/angular/src/directive/ionicNavBar.js b/js/ext/angular/src/directive/ionicNavBar.js index 432b65d667..f0d497be34 100644 --- a/js/ext/angular/src/directive/ionicNavBar.js +++ b/js/ext/angular/src/directive/ionicNavBar.js @@ -259,8 +259,8 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic * @param align-title {string=} Where to align the title of the navbar. * Available: 'left', 'right', 'center'. Defaults to 'center'. */ -.directive('ionNavBar', ['$ionicViewService', '$rootScope', '$animate', '$compile', '$parse', -function($ionicViewService, $rootScope, $animate, $compile, $parse) { +.directive('ionNavBar', ['$ionicViewService', '$rootScope', '$animate', '$compile', +function($ionicViewService, $rootScope, $animate, $compile) { return { restrict: 'E', @@ -285,9 +285,6 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) { alignTitle: $attr.alignTitle || 'center' }); - $parse($attr.controllerBind || '$$ionicNavBarDelegateController') - .assign($scope, navBarCtrl); - //defaults $scope.backButtonShown = false; $scope.shouldAnimate = true; @@ -295,6 +292,10 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) { $scope.isInvisible = true; $scope.$parent.$hasHeader = true; + $scope.$on('$destroy', function() { + $scope.$parent.$hasHeader = false; + }); + $scope.$watch(function() { return ($scope.isReverse ? ' reverse' : '') + ($scope.isInvisible ? ' invisible' : '') + @@ -395,8 +396,8 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) { //Make sure both that a backButton is allowed in the first place, //and that it is shown by the current view. - $scope.$watch('!!(backButtonShown && hasBackButton)', function(val) { - $element.toggleClass('hide', !val); + $scope.$watch('!!(backButtonShown && hasBackButton)', function(show) { + $element.toggleClass('hide', !show); }); }; } diff --git a/js/ext/angular/test/directive/ionicNavBar.unit.js b/js/ext/angular/test/directive/ionicNavBar.unit.js index 621f84d5c9..fd46841876 100644 --- a/js/ext/angular/test/directive/ionicNavBar.unit.js +++ b/js/ext/angular/test/directive/ionicNavBar.unit.js @@ -230,9 +230,12 @@ describe('ionNavBar', function() { expect(el.children().eq(0).html()).toBe('super content 4'); }); - it('should $parent.$hasHeader', function() { + it('should $parent.$hasHeader and unset on $destroy', function() { var el = setup(); - expect(el.scope().$parent.$hasHeader).toBe(true); + var parentScope = el.scope().$parent; + expect(parentScope.$hasHeader).toBe(true); + el.scope().$destroy(); + expect(parentScope.$hasHeader).toBe(false); }); it('should register with $ionicNavBarDelegate', inject(function($ionicNavBarDelegate) {