From 72167b2a454f65a9ffa73bbb12031ed14ce33302 Mon Sep 17 00:00:00 2001 From: Adam Bradley Date: Sun, 23 Nov 2014 01:01:40 -0600 Subject: [PATCH] fix(title): use defined viewTitle attrs --- js/angular/controller/viewController.js | 2 +- .../angular/controller/viewController.unit.js | 59 +++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 test/unit/angular/controller/viewController.unit.js diff --git a/js/angular/controller/viewController.js b/js/angular/controller/viewController.js index f54ed68094..979ec1fb35 100644 --- a/js/angular/controller/viewController.js +++ b/js/angular/controller/viewController.js @@ -41,7 +41,7 @@ function($scope, $element, $attrs, $compile, $ionicViewSwitcher) { if (transData && !transData.viewNotified) { transData.viewNotified = true; - var viewTitle = $attrs.viewTitle || $attrs.title; + var viewTitle = isDefined($attrs.viewTitle) ? $attrs.viewTitle : $attrs.title; var buttons = {}; for (var n in navElementHtml) { diff --git a/test/unit/angular/controller/viewController.unit.js b/test/unit/angular/controller/viewController.unit.js new file mode 100644 index 0000000000..f260d68e1a --- /dev/null +++ b/test/unit/angular/controller/viewController.unit.js @@ -0,0 +1,59 @@ +describe('$ionicView controller', function() { + beforeEach(module('ionic')); + var ctrl, beforeEnterData; + + function setup(attrs, scope) { + var viewEle; + var navBarCtrl = { + beforeEnter: function(d){ beforeEnterData = d; } + }; + inject(function($rootScope, $compile){ + var transData; + viewEle = angular.element(''); + viewEle.data('$ionNavViewController', navBarCtrl); + $compile(viewEle)(scope || $rootScope); + }); + ctrl = viewEle.data('$ionViewController'); + } + + it('should send no title to navBarCtrl with no view-title attr', function() { + setup(); + ctrl.beforeEnter(null, {}); + expect(beforeEnterData.title).toBeUndefined(); + }); + + it('should send title to navBarCtrl with view-title attr', function() { + setup('view-title="Sweet Caroline"'); + ctrl.beforeEnter(null, {}); + expect(beforeEnterData.title).toEqual('Sweet Caroline') + }); + + it('should send interpolated title to navBarCtrl with view-title attr', inject(function($rootScope) { + var scope = $rootScope.$new(); + scope.color = 'Blue'; + setup('view-title="Song Sung {{ color }}"', scope); + ctrl.beforeEnter(null, {}); + expect(beforeEnterData.title).toEqual('Song Sung Blue') + })); + + it('should send title to navBarCtrl with title attr', function() { + setup('title="Holly Holy"'); + ctrl.beforeEnter(null, {}); + expect(beforeEnterData.title).toEqual('Holly Holy') + }); + + it('should send interpolated title to navBarCtrl with view-title attr', inject(function($rootScope) { + var scope = $rootScope.$new(); + scope.name = 'Rosie'; + setup('title="Cracklin {{ name }}"', scope); + ctrl.beforeEnter(null, {}); + expect(beforeEnterData.title).toEqual('Cracklin Rosie') + })); + + it('should prioritize view-title over title', function() { + setup('view-title="I Am" title="I Said"'); + ctrl.beforeEnter(null, {}); + expect(beforeEnterData.title).toEqual('I Am') + }); + +});