test(ionNavBar): add test for $destroy() -> $hasHeader = false

This commit is contained in:
Andy Joslin
2014-03-25 07:46:25 -06:00
parent dd13e986d1
commit 3b0af6c339
2 changed files with 13 additions and 9 deletions

View File

@@ -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);
});
};
}

View File

@@ -230,9 +230,12 @@ describe('ionNavBar', function() {
expect(el.children().eq(0).html()).toBe('<b>super</b> 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) {