diff --git a/dist/js/ionic-angular.js b/dist/js/ionic-angular.js index b43e6d6264..e20813ee95 100644 --- a/dist/js/ionic-angular.js +++ b/dist/js/ionic-angular.js @@ -828,7 +828,7 @@ angular.module('ionic.ui.list', ['ngAnimate']) button.onButtonClicked && button.onButtonClicked($scope.item, button); }; - list.scope.$watch('isEditing', function(v) { + var deregisterListWatch = list.scope.$watch('isEditing', function(v) { $scope.isEditing = v; // Add a delay before we allow the options layer to show, to avoid any odd @@ -841,6 +841,10 @@ angular.module('ionic.ui.list', ['ngAnimate']) $scope.showOptions = false; } }); + + $scope.$on('$destroy', function () { + deregisterListWatch(); + }); } }; }]) @@ -899,7 +903,7 @@ angular.module('ionic.ui.list', ['ngAnimate']) button.onButtonClicked && button.onButtonClicked($scope.item, button); }; - list.scope.$watch('isEditing', function(v) { + var deregisterListWatch = list.scope.$watch('isEditing', function(v) { $scope.isEditing = v; // Add a delay before we allow the options layer to show, to avoid any odd @@ -912,6 +916,10 @@ angular.module('ionic.ui.list', ['ngAnimate']) $scope.showOptions = false; } }); + + $scope.$on('$destroy', function () { + deregisterListWatch(); + }); } }; }]) diff --git a/js/ext/angular/src/directive/ionicList.js b/js/ext/angular/src/directive/ionicList.js index 9736d2d851..a5fa63be98 100644 --- a/js/ext/angular/src/directive/ionicList.js +++ b/js/ext/angular/src/directive/ionicList.js @@ -62,7 +62,7 @@ angular.module('ionic.ui.list', ['ngAnimate']) button.onButtonClicked && button.onButtonClicked($scope.item, button); }; - list.scope.$watch('isEditing', function(v) { + var deregisterListWatch = list.scope.$watch('isEditing', function(v) { $scope.isEditing = v; // Add a delay before we allow the options layer to show, to avoid any odd @@ -75,6 +75,10 @@ angular.module('ionic.ui.list', ['ngAnimate']) $scope.showOptions = false; } }); + + $scope.$on('$destroy', function () { + deregisterListWatch(); + }); } }; }]) @@ -133,7 +137,7 @@ angular.module('ionic.ui.list', ['ngAnimate']) button.onButtonClicked && button.onButtonClicked($scope.item, button); }; - list.scope.$watch('isEditing', function(v) { + var deregisterListWatch = list.scope.$watch('isEditing', function(v) { $scope.isEditing = v; // Add a delay before we allow the options layer to show, to avoid any odd @@ -146,6 +150,10 @@ angular.module('ionic.ui.list', ['ngAnimate']) $scope.showOptions = false; } }); + + $scope.$on('$destroy', function () { + deregisterListWatch(); + }); } }; }]) diff --git a/js/ext/angular/test/directive/ionicList.unit.js b/js/ext/angular/test/directive/ionicList.unit.js index d43b41062a..08525c39e1 100644 --- a/js/ext/angular/test/directive/ionicList.unit.js +++ b/js/ext/angular/test/directive/ionicList.unit.js @@ -1,3 +1,5 @@ +'use strict'; + describe('Ionic List', function() { var compile, scope; @@ -9,7 +11,7 @@ describe('Ionic List', function() { })); it('Should init', function() { - element = compile('' + + var element = compile('' + '' + '' + '')(scope); @@ -17,3 +19,107 @@ describe('Ionic List', function() { expect(element.children().length).toBe(2); }); }); + +describe('Ionic Link Item Directive', function () { + var $rootScope, element, listCtrl, options, scope; + + beforeEach(module('ionic.ui.list')); + + beforeEach(inject(function (_$compile_, _$rootScope_) { + $rootScope = _$rootScope_; + $rootScope.isEditing = false; + + var list = angular.element(''); + list = _$compile_(list)($rootScope); + + listCtrl = list.controller('list'); + + $rootScope.buttons = []; + + element = angular.element('').appendTo(list); + element = _$compile_(element)($rootScope); + + $rootScope.$digest(); + scope = element.isolateScope(); + })); + + it('Should show options when the list is not in edit mode', inject(function ($timeout) { + scope.canSwipe = true; + $rootScope.$digest(); + $timeout.flush(); + + expect(scope.isEditing).toBe(false); + expect(element.find('.item-options').length).toBe(1); + })); + + it('Should hide options when the list is in edit mode', inject(function ($timeout) { + scope.canSwipe = true; + $rootScope.isEditing = true; + $rootScope.$digest(); + $timeout.flush(); + + expect(scope.isEditing).toBe(true); + expect(element.find('.item-options').length).toBe(0); + })); + + it('Should deregister watcher when scope destroyed', inject(function ($timeout) { + $rootScope.isEditing = true; + scope.$destroy(); + $rootScope.$digest(); + $timeout.flush(); + + expect(scope.isEditing).toBe(false); + })); +}); + +describe('Ionic Item Directive', function () { + var $rootScope, element, listCtrl, options, scope; + + beforeEach(module('ionic.ui.list')); + + beforeEach(inject(function (_$compile_, _$rootScope_) { + $rootScope = _$rootScope_; + $rootScope.isEditing = false; + + var list = angular.element(''); + list = _$compile_(list)($rootScope); + + listCtrl = list.controller('list'); + + $rootScope.buttons = []; + + element = angular.element('').appendTo(list); + element = _$compile_(element)($rootScope); + + $rootScope.$digest(); + scope = element.isolateScope(); + })); + + it('Should show options when the list is not in edit mode', inject(function ($timeout) { + scope.canSwipe = true; + $rootScope.$digest(); + $timeout.flush(); + + expect(scope.isEditing).toBe(false); + expect(element.find('.item-options').length).toBe(1); + })); + + it('Should hide options when the list is in edit mode', inject(function ($timeout) { + scope.canSwipe = true; + $rootScope.isEditing = true; + $rootScope.$digest(); + $timeout.flush(); + + expect(scope.isEditing).toBe(true); + expect(element.find('.item-options').length).toBe(0); + })); + + it('Should deregister watcher when scope destroyed', inject(function ($timeout) { + $rootScope.isEditing = true; + scope.$destroy(); + $rootScope.$digest(); + $timeout.flush(); + + expect(scope.isEditing).toBe(false); + })); +});