Merge pull request #188 from sorich87/ionicList-cleanup

ionicList directives cleanup
This commit is contained in:
Adam Bradley
2013-11-27 06:36:32 -08:00
3 changed files with 127 additions and 5 deletions

View File

@@ -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();
});
}
};
}])

View File

@@ -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();
});
}
};
}])

View File

@@ -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('<list>' +
var element = compile('<list>' +
'<list-item></list-item>' +
'<list-item></list-item>' +
'</list>')(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 is-editing="isEditing">');
list = _$compile_(list)($rootScope);
listCtrl = list.controller('list');
$rootScope.buttons = [];
element = angular.element('<link-item>').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 is-editing="isEditing">');
list = _$compile_(list)($rootScope);
listCtrl = list.controller('list');
$rootScope.buttons = [];
element = angular.element('<item>').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);
}));
});