From 282613c61c407c21de25b100b74eb1d473223284 Mon Sep 17 00:00:00 2001 From: Micah Williamson Date: Mon, 9 Feb 2015 08:50:07 -0600 Subject: [PATCH] using $watchCollection instead of $watch undid demo.js changes. added unit test that uses document.body as the appendTo removed gitignore changes --- .gitignore | 2 +- src/sortable.js | 2 +- test/sortable.e2e.spec.js | 30 ++++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index ac65240..378c898 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,4 @@ node_modules/ coverage/ junit/ dist/ -out/ \ No newline at end of file +out/ diff --git a/src/sortable.js b/src/sortable.js index 14c2679..1136a76 100644 --- a/src/sortable.js +++ b/src/sortable.js @@ -294,7 +294,7 @@ angular.module('ui.sortable', []) return inner; }; - scope.$watch('uiSortable', function(newVal /*, oldVal*/) { + scope.$watchCollection('uiSortable', function(newVal /*, oldVal*/) { // ensure that the jquery-ui-sortable widget instance // is still bound to the directive's element var sortableWidgetInstance = getSortableWidgetInstance(element); diff --git a/test/sortable.e2e.spec.js b/test/sortable.e2e.spec.js index 1be9306..65c12dd 100644 --- a/test/sortable.e2e.spec.js +++ b/test/sortable.e2e.spec.js @@ -446,6 +446,36 @@ describe('uiSortable', function() { }); }); + it('should work when "helper: clone" and "appendTo" options are used together', function() { + inject(function($compile, $rootScope) { + var element; + element = $compile('')($rootScope); + $rootScope.$apply(function() { + $rootScope.opts = { + helper: 'clone', + appendTo: document.body + }; + $rootScope.items = ['One', 'Two', 'Three']; + }); + + host.append(element); + + var li = element.find(':eq(1)'); + var dy = (1 + EXTRA_DY_PERCENTAGE) * li.outerHeight(); + li.simulate('drag', { dy: dy }); + expect($rootScope.items).toEqual(['One', 'Three', 'Two']); + expect($rootScope.items).toEqual(listContent(element)); + + li = element.find(':eq(2)'); + dy = -(1 + EXTRA_DY_PERCENTAGE) * li.outerHeight(); + li.simulate('drag', { dy: dy }); + expect($rootScope.items).toEqual(['One', 'Two', 'Three']); + expect($rootScope.items).toEqual(listContent(element)); + + $(element).remove(); + }); + }); + it('should work when "helper: clone" and "placeholder" options are used together.', function() { inject(function($compile, $rootScope) { var element;