@@ -345,6 +345,76 @@ describe('uiSortable', function() {
345
345
} ) ;
346
346
} ) ;
347
347
348
+ it ( 'should work when "helper: clone" option is used' , function ( ) {
349
+ inject ( function ( $compile , $rootScope ) {
350
+ var element ;
351
+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
352
+ $rootScope . $apply ( function ( ) {
353
+ $rootScope . opts = {
354
+ helper : 'clone' ,
355
+ } ;
356
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
357
+ } ) ;
358
+
359
+ host . append ( element ) ;
360
+
361
+ var li = element . find ( ':eq(1)' ) ;
362
+ var dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
363
+ li . simulate ( 'drag' , { dy : dy } ) ;
364
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Three' , 'Two' ] ) ;
365
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
366
+
367
+ li = element . find ( ':eq(1)' ) ;
368
+ dy = - ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
369
+ li . simulate ( 'drag' , { dy : dy } ) ;
370
+ expect ( $rootScope . items ) . toEqual ( [ 'Three' , 'One' , 'Two' ] ) ;
371
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
372
+
373
+ $ ( element ) . remove ( ) ;
374
+ } ) ;
375
+ } ) ;
376
+
377
+ it ( 'should work when "helper: clone" option is used and a drag is reverted' , function ( ) {
378
+ inject ( function ( $compile , $rootScope ) {
379
+ var element ;
380
+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items" id="s-{{$index}}" class="sortable-item">{{ item }}</li></ul>' ) ( $rootScope ) ;
381
+ $rootScope . $apply ( function ( ) {
382
+ $rootScope . opts = {
383
+ helper : 'clone' ,
384
+ } ;
385
+ $rootScope . items = [ 'One' , 'Two' , 'Three' ] ;
386
+ } ) ;
387
+
388
+ host . append ( element ) ;
389
+
390
+ var li = element . find ( ':eq(0)' ) ;
391
+ var dy = ( 2 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
392
+ li . simulate ( 'dragAndRevert' , { dy : dy } ) ;
393
+ expect ( $rootScope . items ) . toEqual ( [ 'One' , 'Two' , 'Three' ] ) ;
394
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
395
+
396
+ li = element . find ( ':eq(0)' ) ;
397
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
398
+ li . simulate ( 'drag' , { dy : dy } ) ;
399
+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'One' , 'Three' ] ) ;
400
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
401
+
402
+ li = element . find ( ':eq(1)' ) ;
403
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
404
+ li . simulate ( 'drag' , { dy : dy } ) ;
405
+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'Three' , 'One' ] ) ;
406
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
407
+
408
+ li = element . find ( ':eq(1)' ) ;
409
+ dy = ( 1 + EXTRA_DY_PERCENTAGE ) * li . outerHeight ( ) ;
410
+ li . simulate ( 'drag' , { dy : dy } ) ;
411
+ expect ( $rootScope . items ) . toEqual ( [ 'Two' , 'One' , 'Three' ] ) ;
412
+ expect ( $rootScope . items ) . toEqual ( listContent ( element ) ) ;
413
+
414
+ $ ( element ) . remove ( ) ;
415
+ } ) ;
416
+ } ) ;
417
+
348
418
} ) ;
349
419
350
420
describe ( 'Multiple sortables related' , function ( ) {
0 commit comments