From 919d4f8dcadd386a39f94dc817f6da757ca9e755 Mon Sep 17 00:00:00 2001 From: Andrew Joslin Date: Fri, 9 May 2014 08:43:15 -0600 Subject: [PATCH] fix(ionView): make it set navbar if title changes back to old value Fixes #1121 --- js/angular/controller/navBarController.js | 3 +++ js/angular/directive/view.js | 8 +------- test/unit/angular/directive/navBar.unit.js | 13 +++++++++++++ test/unit/angular/directive/view.unit.js | 4 ++-- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/js/angular/controller/navBarController.js b/js/angular/controller/navBarController.js index d025962dc1b..618c6a2ca33 100644 --- a/js/angular/controller/navBarController.js +++ b/js/angular/controller/navBarController.js @@ -52,6 +52,9 @@ function($scope, $element, $attrs, $ionicViewService, $animate, $compile, $ionic }; this.setTitle = function(title) { + if ($scope.title === title) { + return; + } $scope.oldTitle = $scope.title; $scope.title = title || ''; }; diff --git a/js/angular/directive/view.js b/js/angular/directive/view.js index f687c9749c6..1f2f8ae0d58 100644 --- a/js/angular/directive/view.js +++ b/js/angular/directive/view.js @@ -52,14 +52,8 @@ IonicModule // watch for changes in the title, don't set initial value as changeTitle does that $attr.$observe('title', function(val, oldVal) { - if (val !== initialTitle) { - navBarCtrl.setTitle(val); - } else { - //Safety to make sure the navbar's title is correct - navBarCtrl.setTitle(initialTitle); - } + navBarCtrl.setTitle(val); }); - } var hideBackAttr = angular.isDefined($attr.hideBackButton) ? diff --git a/test/unit/angular/directive/navBar.unit.js b/test/unit/angular/directive/navBar.unit.js index 0da3fd3d94e..15cc9be556e 100644 --- a/test/unit/angular/directive/navBar.unit.js +++ b/test/unit/angular/directive/navBar.unit.js @@ -107,6 +107,19 @@ describe('ionNavBar', function() { expect($scope.oldTitle).toBe('bar'); }); + it('setTitle should not change if title is same as old', function() { + var ctrl = setup(); + ctrl.setTitle('okay'); + expect($scope.title).toBe('okay'); + expect($scope.oldTitle).toBeFalsy(); + ctrl.setTitle('okay'); + expect($scope.title).toBe('okay'); + expect($scope.oldTitle).toBeFalsy(); + ctrl.setTitle('okay-2'); + expect($scope.title).toBe('okay-2'); + expect($scope.oldTitle).toBe('okay'); + }); + it('should getTitle', function() { var ctrl = setup(); expect(ctrl.getTitle()).toBeFalsy(); diff --git a/test/unit/angular/directive/view.unit.js b/test/unit/angular/directive/view.unit.js index c77235f8c5f..ba5228fb035 100644 --- a/test/unit/angular/directive/view.unit.js +++ b/test/unit/angular/directive/view.unit.js @@ -76,10 +76,10 @@ describe('ionView directive', function() { expect(el.controller('ionNavBar').showBar).toHaveBeenCalledWith(true); }); - it('should setTitle on change, but not with initial value', function() { + it('should setTitle on change', function() { var el = setup('title="{{something}}-1"'); //Should not setTitle with initial value - expect(el.controller('ionNavBar').setTitle).not.toHaveBeenCalled(); + expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('-1'); el.scope().$apply('something = 2'); expect(el.controller('ionNavBar').setTitle).toHaveBeenCalledWith('2-1'); });