mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2026-03-13 10:22:08 +08:00
test(ionNavBar): add test for $destroy() -> $hasHeader = false
This commit is contained in:
15
js/ext/angular/src/directive/ionicNavBar.js
vendored
15
js/ext/angular/src/directive/ionicNavBar.js
vendored
@@ -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);
|
||||
});
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user