@@ -270,6 +270,81 @@ describe('uiSortable', function() {
270270 } ) ;
271271 } ) ;
272272
273+ it ( 'should call all callbacks with the proper context' , function ( ) {
274+ inject ( function ( $compile , $rootScope ) {
275+ var element , callbackContexts = { } ;
276+ $rootScope . $apply ( function ( ) {
277+ $rootScope . opts = {
278+ helper : function ( e , item ) {
279+ callbackContexts . helper = this ;
280+ return item ;
281+ } ,
282+ create : function ( ) {
283+ callbackContexts . create = this ;
284+ } ,
285+ start : function ( ) {
286+ callbackContexts . start = this ;
287+ } ,
288+ activate : function ( ) {
289+ callbackContexts . activate = this ;
290+ } ,
291+ beforeStop : function ( ) {
292+ callbackContexts . beforeStop = this ;
293+ } ,
294+ update : function ( ) {
295+ callbackContexts . update = this ;
296+ } ,
297+ deactivate : function ( ) {
298+ callbackContexts . deactivate = this ;
299+ } ,
300+ stop : function ( ) {
301+ callbackContexts . stop = this ;
302+ }
303+ } ;
304+ spyOn ( $rootScope . opts , 'helper' ) . andCallThrough ( ) ;
305+ spyOn ( $rootScope . opts , 'create' ) . andCallThrough ( ) ;
306+ spyOn ( $rootScope . opts , 'start' ) . andCallThrough ( ) ;
307+ spyOn ( $rootScope . opts , 'activate' ) . andCallThrough ( ) ;
308+ spyOn ( $rootScope . opts , 'beforeStop' ) . andCallThrough ( ) ;
309+ spyOn ( $rootScope . opts , 'update' ) . andCallThrough ( ) ;
310+ spyOn ( $rootScope . opts , 'deactivate' ) . andCallThrough ( ) ;
311+ spyOn ( $rootScope . opts , 'stop' ) . andCallThrough ( ) ;
312+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
313+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li></ul>' ) ( $rootScope ) ;
314+ } ) ;
315+
316+ host . append ( element ) ;
317+
318+ $rootScope . $apply ( function ( ) {
319+ } ) ;
320+ var li = element . find ( ':eq(0)' ) ;
321+ var dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
322+ li . simulate ( 'drag' , { dy : dy } ) ;
323+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
324+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
325+
326+ expect ( $rootScope . opts . helper ) . toHaveBeenCalled ( ) ;
327+ expect ( $rootScope . opts . create ) . toHaveBeenCalled ( ) ;
328+ expect ( $rootScope . opts . start ) . toHaveBeenCalled ( ) ;
329+ expect ( $rootScope . opts . activate ) . toHaveBeenCalled ( ) ;
330+ expect ( $rootScope . opts . beforeStop ) . toHaveBeenCalled ( ) ;
331+ expect ( $rootScope . opts . update ) . toHaveBeenCalled ( ) ;
332+ expect ( $rootScope . opts . deactivate ) . toHaveBeenCalled ( ) ;
333+ expect ( $rootScope . opts . stop ) . toHaveBeenCalled ( ) ;
334+
335+ expect ( callbackContexts . helper ) . toEqual ( element [ 0 ] ) ;
336+ expect ( callbackContexts . create ) . toEqual ( element [ 0 ] ) ;
337+ expect ( callbackContexts . start ) . toEqual ( element [ 0 ] ) ;
338+ expect ( callbackContexts . activate ) . toEqual ( element [ 0 ] ) ;
339+ expect ( callbackContexts . beforeStop ) . toEqual ( element [ 0 ] ) ;
340+ expect ( callbackContexts . update ) . toEqual ( element [ 0 ] ) ;
341+ expect ( callbackContexts . deactivate ) . toEqual ( element [ 0 ] ) ;
342+ expect ( callbackContexts . stop ) . toEqual ( element [ 0 ] ) ;
343+
344+ $ ( element ) . remove ( ) ;
345+ } ) ;
346+ } ) ;
347+
273348 it ( 'should properly free ui.item.sortable object' , function ( ) {
274349 inject ( function ( $compile , $rootScope ) {
275350 var element , uiItem , uiItemSortable_Destroy ;
0 commit comments