From 0ffb748fc78f0e0f4422f79110b4b84796a47ed1 Mon Sep 17 00:00:00 2001 From: Andy Joslin Date: Sat, 15 Mar 2014 09:24:24 -0600 Subject: [PATCH] refactor(ionNavBackButton): make click handler use $ionicNgClick service Closes #802 --- js/ext/angular/src/directive/ionicNavBar.js | 5 +++-- .../test/directive/ionicNavBackButton.unit.js | 22 +++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/js/ext/angular/src/directive/ionicNavBar.js b/js/ext/angular/src/directive/ionicNavBar.js index cf8e94bf1e..33c6cc0e69 100644 --- a/js/ext/angular/src/directive/ionicNavBar.js +++ b/js/ext/angular/src/directive/ionicNavBar.js @@ -282,7 +282,7 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) { * * ``` */ -.directive('ionNavBackButton', [function() { +.directive('ionNavBackButton', ['$ionicNgClick', function($ionicNgClick) { return { restrict: 'E', require: '^ionNavBar', @@ -292,8 +292,9 @@ function($ionicViewService, $rootScope, $animate, $compile, $parse) { '', link: function($scope, $element, $attr, navBarCtrl) { + $scope.$navBack = navBarCtrl.back; if (!$attr.ngClick) { - ionic.on('tap', navBarCtrl.back, $element[0]); + $ionicNgClick($scope, $element, '$navBack($event)'); } //If the current viewstate does not allow a back button, diff --git a/js/ext/angular/test/directive/ionicNavBackButton.unit.js b/js/ext/angular/test/directive/ionicNavBackButton.unit.js index 0e77e7f59a..710e083ff3 100644 --- a/js/ext/angular/test/directive/ionicNavBackButton.unit.js +++ b/js/ext/angular/test/directive/ionicNavBackButton.unit.js @@ -1,5 +1,5 @@ describe('ionNavBackButton directive', function() { - beforeEach(module('ionic.ui.navBar')); + beforeEach(module('ionic')); function setup(attr, content) { var el; @@ -53,19 +53,19 @@ describe('ionNavBackButton directive', function() { expect(el.children().eq(0)[0].tagName.toLowerCase()).toBe('b'); }); - it('should add onTap if ngClick isnt defined', function() { - spyOn(ionic, 'on'); + it('should $navBack on click by default', function() { var el = setup(); - expect(ionic.on).toHaveBeenCalledWith( - 'tap', - el.controller('ionNavBar').back, - el[0] - ); + el.scope().$navBack = jasmine.createSpy('$navBack'); + el.triggerHandler('click'); + expect(el.scope().$navBack).toHaveBeenCalled(); }); - it('should not add onTap if ngClick is defined', function() { - spyOn(ionic, 'on'); + it('should do ngClick expression if defined', function() { var el = setup('ng-click="doSomething()"'); - expect(ionic.on).not.toHaveBeenCalled(); + el.scope().$navBack = jasmine.createSpy('$navBack'); + el.scope().doSomething = jasmine.createSpy('doSomething'); + el.triggerHandler('click'); + expect(el.scope().$navBack).not.toHaveBeenCalled(); + expect(el.scope().doSomething).toHaveBeenCalled(); }); });