Skip to content

Commit

Permalink
fix(backButton): able to hide back button if any back button attr set…
Browse files Browse the repository at this point in the history
… in navBar, closes #564
  • Loading branch information
Adam Bradley committed Feb 10, 2014
1 parent de50ada commit 74a05a0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
2 changes: 1 addition & 1 deletion js/ext/angular/src/directive/ionicViewState.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ angular.module('ionic.ui.viewState', ['ionic.service.view', 'ionic.service.gestu
if(tAttrs.type) tElement.addClass(tAttrs.type);

return function link($scope, $element, $attr) {
var canHaveBackButton = !(!tAttrs.backButtonType && !tAttrs.backButtonLabel);
var canHaveBackButton = !(!tAttrs.backButtonType && !tAttrs.backButtonLabel && !tAttrs.backButtonIcon);
$scope.enableBackButton = canHaveBackButton;

$rootScope.$on('viewState.showNavBar', function(e, showNavBar) {
Expand Down
32 changes: 30 additions & 2 deletions js/ext/angular/test/directive/ionicView.unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,41 @@ describe('Ionic View', function() {
expect(element.hasClass('bar-positive')).toEqual(true);
});

it('should not show the back button if no back button attributes set', function() {
it('should not have the back button if no back button attributes set', function() {
var element = compile('<nav-bar></nav-bar>')(scope);
scope.$digest();
var backButton = element.find('div').find('button');
expect(backButton.length).toEqual(0);
});

it('should have the back button if back-button-type attributes set', function() {
var element = compile('<nav-bar back-button-type="button-icon"></nav-bar>')(scope);
scope.$digest();
var backButton = element.find('div').find('button');
expect(backButton.length).toEqual(1);
});

it('should have the back button if back-button-icon attributes set', function() {
var element = compile('<nav-bar back-button-icon="ion-back"></nav-bar>')(scope);
scope.$digest();
var backButton = element.find('div').find('button');
expect(backButton.length).toEqual(1);
});

it('should have the back button if back-button-label attributes set', function() {
var element = compile('<nav-bar back-button-label="Button"></nav-bar>')(scope);
scope.$digest();
var backButton = element.find('div').find('button');
expect(backButton.length).toEqual(1);
});

it('should have the back button if all back button attributes set', function() {
var element = compile('<nav-bar back-button-type="button-icon" back-button-icon="ion-back" back-button-label="Button"></nav-bar>')(scope);
scope.$digest();
var backButton = element.find('div').find('button');
expect(backButton.length).toEqual(1);
});

it('should set just a back button icon, no text', function() {
var element = compile('<nav-bar back-button-icon="ion-back" back-button-type="button-icon"></nav-bar>')(scope);
scope.$digest();
Expand All @@ -111,7 +139,7 @@ describe('Ionic View', function() {
expect(backButton.html()).toEqual('Back');
});

it('should set a back button with an icon and text, button-clear', function() {
it('should set a back button with an icon and text, button-icon', function() {
var element = compile('<nav-bar back-button-icon="ion-back" back-button-label="Back" back-button-type="button-icon"></nav-bar>')(scope);
scope.$digest();
var backButton = element.find('div').find('button');
Expand Down

0 comments on commit 74a05a0

Please sign in to comment.