From 9942045fb2b33ea1ed98ff67d69bfa96bd6545ab Mon Sep 17 00:00:00 2001 From: Andrew Joslin Date: Thu, 5 Jun 2014 07:28:28 -0600 Subject: [PATCH] amend($ionicModal): if hardwareBackButtonClose false, back button is noop Addresses #1397 --- js/angular/service/modal.js | 10 ++++------ test/unit/angular/directive/gestures.js | 0 test/unit/angular/service/modal.unit.js | 8 ++++++-- 3 files changed, 10 insertions(+), 8 deletions(-) create mode 100644 test/unit/angular/directive/gestures.js diff --git a/js/angular/service/modal.js b/js/angular/service/modal.js index af8c20bf3d6..aa33c4a96a1 100644 --- a/js/angular/service/modal.js +++ b/js/angular/service/modal.js @@ -128,12 +128,10 @@ function($rootScope, $document, $compile, $timeout, $ionicPlatform, $ionicTempla .removeClass('ng-leave ng-leave-active'); self._isShown = true; - self._deregisterBackButton = self.hardwareBackButtonClose ? - $ionicPlatform.registerBackButtonAction( - angular.bind(self, self.hide), - PLATFORM_BACK_BUTTON_PRIORITY_MODAL - ) : - angular.noop; + self._deregisterBackButton = $ionicPlatform.registerBackButtonAction( + self.hardwareBackButtonClose ? angular.bind(self, self.hide) : angular.noop, + PLATFORM_BACK_BUTTON_PRIORITY_MODAL + ); self._isOpenPromise = $q.defer(); diff --git a/test/unit/angular/directive/gestures.js b/test/unit/angular/directive/gestures.js new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/unit/angular/service/modal.unit.js b/test/unit/angular/service/modal.unit.js index e77672a2afd..cbf926d3f75 100644 --- a/test/unit/angular/service/modal.unit.js +++ b/test/unit/angular/service/modal.unit.js @@ -106,10 +106,14 @@ describe('Ionic Modal', function() { var instance = modal.fromTemplate(template, { hardwareBackButtonClose: false }); - spyOn($ionicPlatform, 'registerBackButtonAction'); + spyOn($ionicPlatform, 'registerBackButtonAction').andCallThrough(); instance.show(); timeout.flush(); - expect($ionicPlatform.registerBackButtonAction).not.toHaveBeenCalled(); + expect($ionicPlatform.registerBackButtonAction).toHaveBeenCalledWith(jasmine.any(Function), PLATFORM_BACK_BUTTON_PRIORITY_MODAL); + + ionicPlatform.hardwareBackButtonClick(); + + expect(instance.isShown()).toBe(true); })); it('should call _deregisterBackButton on hide', function() {