Skip to content

Commit

Permalink
fix(title): use defined viewTitle attrs
Browse files Browse the repository at this point in the history
  • Loading branch information
adamdbradley committed Nov 23, 2014
1 parent beb45c1 commit 72167b2
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 1 deletion.
2 changes: 1 addition & 1 deletion js/angular/controller/viewController.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
59 changes: 59 additions & 0 deletions test/unit/angular/controller/viewController.unit.js
Original file line number Diff line number Diff line change
@@ -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('<ion-view ' + (attrs || '') + '>');
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')
});

});

0 comments on commit 72167b2

Please sign in to comment.