@@ -457,6 +457,64 @@ describe('uiSortable', function() {
457
457
} ) ;
458
458
} ) ;
459
459
460
+ it ( 'should provide the item.sortable properties on helper callback' , function ( ) {
461
+ inject ( function ( $compile , $rootScope ) {
462
+ var element , helperItem , itemSortable_Restore , sortableAfterRestore , helperCallbackExpectations ;
463
+ element = $compile ( '' . concat (
464
+ '<ul ui-sortable="opts" ng-model="items">' ,
465
+ beforeLiElement ,
466
+ '<li ng-repeat="item in items" id="s-{{$index}}">{{ item }}</li>' ,
467
+ afterLiElement +
468
+ '</ul>' ) ) ( $rootScope ) ;
469
+ $rootScope . $apply ( function ( ) {
470
+ $rootScope . opts = {
471
+ helper : function ( e , item ) {
472
+ helperItem = item ;
473
+
474
+ var oldRestore = item . sortable . _restore ;
475
+ item . sortable . _restore = function ( ) {
476
+ oldRestore . apply ( this , arguments ) ;
477
+ // hold the value of the sortable object
478
+ // right after the _restore method completes
479
+ sortableAfterRestore = item . sortable ;
480
+ } ;
481
+
482
+ spyOn ( item . sortable , '_restore' ) . and . callThrough ( ) ;
483
+ itemSortable_Restore = item . sortable . _restore ;
484
+ helperCallbackExpectations ( item . sortable ) ;
485
+ return item . clone ( ) ;
486
+ }
487
+ } ;
488
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
489
+ } ) ;
490
+
491
+ host . append ( element ) ;
492
+
493
+ $rootScope . $apply ( function ( ) {
494
+ } ) ;
495
+
496
+ var li = element . find ( '[ng-repeat]:eq(0)' ) ;
497
+ var dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
498
+ helperCallbackExpectations = function ( helperItemSortable ) {
499
+ expect ( helperItemSortable . model ) . toEqual ( 'One' ) ;
500
+ expect ( helperItemSortable . index ) . toEqual ( 0 ) ;
501
+ expect ( helperItemSortable . source . length ) . toEqual ( 1 ) ;
502
+ expect ( helperItemSortable . source [ 0 ] ) . toBe ( host . children ( ) [ 0 ] ) ;
503
+ expect ( helperItemSortable . sourceModel ) . toBe ( $rootScope . items ) ;
504
+ } ;
505
+ li . simulate ( 'drag' , { dy : dy } ) ;
506
+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
507
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
508
+ expect ( itemSortable_Restore ) . toHaveBeenCalled ( ) ;
509
+ expect ( hasUndefinedProperties ( helperItem . sortable ) ) . toBe ( true ) ;
510
+ // this happens after the update callback, so everything is udnefined
511
+ expect ( typeof sortableAfterRestore ) . toBe ( 'function' ) ;
512
+ helperItem = itemSortable_Restore = sortableAfterRestore = helperCallbackExpectations = undefined ;
513
+
514
+ $ ( element ) . remove ( ) ;
515
+ } ) ;
516
+ } ) ;
517
+
460
518
it ( 'should properly reset a deleted callback option' , function ( ) {
461
519
inject ( function ( $compile , $rootScope ) {
462
520
var element , logsElement ;
0 commit comments