From 215b1c1ea058bb76e4950d06e3e7e127c5a43cc6 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Sat, 15 Mar 2014 13:41:02 -0600 Subject: [PATCH] feat(ionicNavBar): add getTitle() and getPreviousTitle() methods --- js/ext/angular/src/directive/ionicNavBar.js | 17 +++++++ .../test/directive/ionicNavBar.unit.js | 44 ++++++++++++++----- 2 files changed, 51 insertions(+), 10 deletions(-) diff --git a/js/ext/angular/src/directive/ionicNavBar.js b/js/ext/angular/src/directive/ionicNavBar.js index 643ca1864c..f0a6243ad2 100644 --- a/js/ext/angular/src/directive/ionicNavBar.js +++ b/js/ext/angular/src/directive/ionicNavBar.js @@ -107,6 +107,23 @@ function($scope, $element, $ionicViewService, $animate, $compile) { return true; }; + /** + * @ngdoc method + * @name ionicNavBar#getTitle + * @returns {string} The current title of the navbar. + */ + this.getTitle = function() { + return $scope.title || ''; + }; + /** + * @ngdoc method + * @name ionicNavBar#getPreviousTitle + * @returns {string} The previous title of the navbar. + */ + this.getPreviousTitle = function() { + return $scope.oldTitle || ''; + }; + /** * @private * Exposed for testing diff --git a/js/ext/angular/test/directive/ionicNavBar.unit.js b/js/ext/angular/test/directive/ionicNavBar.unit.js index f0cce79f1b..2c110fa8fd 100644 --- a/js/ext/angular/test/directive/ionicNavBar.unit.js +++ b/js/ext/angular/test/directive/ionicNavBar.unit.js @@ -84,13 +84,39 @@ describe('ionNavBar', function() { it('should setTitle', function() { var ctrl = setup(); - expect($scope.title).toBeUndefined(); + expect($scope.title).toBeFalsy(); + expect($scope.oldTitle).toBeFalsy(); ctrl.setTitle('foo'); expect($scope.title).toBe('foo'); - ctrl.setTitle(null); - expect($scope.title).toBe(''); + expect($scope.oldTitle).toBeFalsy(); + ctrl.setTitle('bar'); + expect($scope.title).toBe('bar'); + expect($scope.oldTitle).toBe('foo'); + ctrl.setTitle('baz'); + expect($scope.title).toBe('baz'); + expect($scope.oldTitle).toBe('bar'); }) + it('should getTitle', function() { + var ctrl = setup(); + expect(ctrl.getTitle()).toBeFalsy(); + ctrl.setTitle('bar'); + expect(ctrl.getTitle()).toBe('bar'); + ctrl.setTitle('baz'); + expect(ctrl.getTitle()).toBe('baz'); + }); + + it('should getPreviousTitle', function() { + var ctrl = setup(); + expect(ctrl.getPreviousTitle()).toBeFalsy(); + ctrl.setTitle('foo'); + expect(ctrl.getPreviousTitle()).toBeFalsy(); + ctrl.setTitle('bar'); + expect(ctrl.getPreviousTitle()).toBe('foo'); + ctrl.setTitle('baz'); + expect(ctrl.getPreviousTitle()).toBe('bar'); + }); + describe('changeTitle', function() { var ctrl; beforeEach(function() { @@ -120,15 +146,13 @@ describe('ionNavBar', function() { expect($scope.shouldAnimate).toBe(false); }); - it('should set title & oldTitle', function() { + it('should call setTitle', function() { expect($scope.oldTitle).toBeFalsy(); - ctrl.setTitle('title1'); + spyOn(ctrl, 'setTitle'); + ctrl.changeTitle('title1'); + expect(ctrl.setTitle).toHaveBeenCalledWith('title1'); ctrl.changeTitle('title2'); - expect($scope.oldTitle).toBe('title1'); - expect($scope.title).toBe('title2'); - ctrl.changeTitle('title3'); - expect($scope.oldTitle).toBe('title2'); - expect($scope.title).toBe('title3'); + expect(ctrl.setTitle).toHaveBeenCalledWith('title2'); }); it('should only align if no navDirection', function() {