test(navBar): add tests for changing title, left/right buttons

Closes #622. Closes #623.
This commit is contained in:
UniRing
2014-02-17 21:20:59 +01:00
committed by Andy Joslin
parent 39af0a7cf6
commit 3d7011eb19
2 changed files with 73 additions and 2 deletions

View File

@@ -42,7 +42,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
'<nav-back-button ng-if="backButtonEnabled && (backType || backLabel || backIcon)" ' +
'type="backType" label="backLabel" icon="backIcon" class="invisible" async-visible>' +
'</nav-back-button>' +
'<div class="buttons"> ' +
'<div class="buttons left-buttons"> ' +
'<button ng-click="button.tap($event)" ng-repeat="button in leftButtons" ' +
'class="button no-animation {{button.type}}" ' +
'bind-html-unsafe="button.content">' +
@@ -52,7 +52,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
//ng-repeat makes it easy to add new / remove old and have proper enter/leave anims
'<h1 ng-repeat="title in titles" bind-html-unsafe="title" class="title invisible" async-visible nav-bar-title></h1>' +
'<div class="buttons" ng-if="rightButtons.length"> ' +
'<div class="buttons right-buttons" ng-if="rightButtons.length"> ' +
'<button ng-click="button.tap($event)" ng-repeat="button in rightButtons" '+
'class="button no-animation {{button.type}}" ' +
'bind-html-unsafe="button.content">' +

View File

@@ -89,6 +89,77 @@ describe('Ionic View', function() {
expect(navBar.hasClass('invisible')).toEqual(true);
});
it('should show and update navBar title when using view attr or events', function() {
scope.viewTitle = 'Title';
var element = compile('<div><nav-bar></nav-bar><view title="viewTitle"></view></div>')(scope);
scope.$digest();
var navBar = element.find('header');
var title = navBar.find('h1');
expect(title.text().trim()).toEqual('Title');
scope.viewTitle = 'New Title';
scope.$digest();
navBar = element.find('header');
title = navBar.find('h1');
expect(title.text().trim()).toEqual('New Title');
scope.$broadcast('viewState.titleUpdated', { title: 'Event Title' });
scope.$digest();
navBar = element.find('header');
title = navBar.find('h1');
expect(title.text().trim()).toEqual('Event Title');
});
it('should show / update navBar left and right buttons when using view attr or events', function() {
scope.leftButtons = [{
type: 'button',
content: 'Left Button'
}];
scope.rightButtons = [{
type: 'button',
content: 'Right Button'
}];
var element = compile('<div><nav-bar></nav-bar><view left-buttons="leftButtons" right-buttons="rightButtons"></view></div>')(scope);
scope.$digest();
var leftButton = angular.element(element[0].querySelector('.left-buttons')).find('button');
expect(leftButton.text().trim()).toBe('Left Button');
var rightButton = angular.element(element[0].querySelector('.right-buttons')).find('button');
expect(rightButton.text().trim()).toBe('Right Button');
scope.leftButtons = [{
type: 'button',
content: 'New Left Button'
}];
scope.rightButtons = [{
type: 'button',
content: 'New Right Button'
}];
scope.$digest();
leftButton = angular.element(element[0].querySelector('.left-buttons')).find('button');
expect(leftButton.text().trim()).toBe('New Left Button');
rightButton = angular.element(element[0].querySelector('.right-buttons')).find('button');
expect(rightButton.text().trim()).toBe('New Right Button');
scope.$broadcast('viewState.leftButtonsChanged', [{
type: 'button',
content: 'Event Left Button'
}]);
scope.$broadcast('viewState.rightButtonsChanged', [{
type: 'button',
content: 'Event Right Button'
}]);
scope.$digest();
leftButton = angular.element(element[0].querySelector('.left-buttons')).find('button');
expect(leftButton.text().trim()).toBe('Event Left Button');
rightButton = angular.element(element[0].querySelector('.right-buttons')).find('button');
expect(rightButton.text().trim()).toBe('Event Right Button');
});
it('should show navbar when not using view attr', function() {
var element = compile('<div><nav-bar></nav-bar><view></view></div>')(scope);
scope.$digest();