@@ -319,7 +319,7 @@ describe('uiSortable', function() {
319
319
} ) ;
320
320
321
321
it ( 'should lazily initialize a latelly enabled sortable (set disabled = false)' , function ( ) {
322
- inject ( function ( $compile , $rootScope ) {
322
+ inject ( function ( $compile , $rootScope , $timeout ) {
323
323
var element ;
324
324
var childScope = $rootScope . $new ( ) ;
325
325
spyOn ( angular . element . fn , 'sortable' ) ;
@@ -336,12 +336,45 @@ describe('uiSortable', function() {
336
336
childScope . opts . disabled = false ;
337
337
} ) ;
338
338
339
+ expect ( function ( ) {
340
+ $timeout . flush ( ) ;
341
+ } ) . not . toThrow ( ) ;
342
+
339
343
expect ( angular . element . fn . sortable ) . toHaveBeenCalled ( ) ;
340
344
} ) ;
341
345
} ) ;
342
346
347
+ it ( 'should lazily initialize a sortable enabled in $timeout (set disabled = false)' , function ( ) {
348
+ inject ( function ( $compile , $rootScope , $timeout ) {
349
+ var element ;
350
+ var childScope = $rootScope . $new ( ) ;
351
+ spyOn ( angular . element . fn , 'sortable' ) ;
352
+
353
+ childScope . items = [ 'One' , 'Two' , 'Three' ] ;
354
+ childScope . opts = {
355
+ disabled : true
356
+ } ;
357
+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul>' ) ( childScope ) ;
358
+
359
+ expect ( angular . element . fn . sortable ) . not . toHaveBeenCalled ( ) ;
360
+
361
+ $timeout ( function ( ) {
362
+ childScope . opts . disabled = false ;
363
+ } ) ;
364
+
365
+ $timeout ( function ( ) {
366
+ expect ( angular . element . fn . sortable ) . toHaveBeenCalled ( ) ;
367
+ } ) ;
368
+
369
+ expect ( function ( ) {
370
+ $timeout . flush ( ) ;
371
+ } ) . not . toThrow ( ) ;
372
+
373
+ } ) ;
374
+ } ) ;
375
+
343
376
it ( 'should lazily initialize a latelly enabled sortable (delete disabled option)' , function ( ) {
344
- inject ( function ( $compile , $rootScope ) {
377
+ inject ( function ( $compile , $rootScope , $timeout ) {
345
378
var element ;
346
379
var childScope = $rootScope . $new ( ) ;
347
380
spyOn ( angular . element . fn , 'sortable' ) ;
@@ -358,10 +391,46 @@ describe('uiSortable', function() {
358
391
childScope . opts = { } ;
359
392
} ) ;
360
393
394
+ expect ( function ( ) {
395
+ $timeout . flush ( ) ;
396
+ } ) . not . toThrow ( ) ;
397
+
361
398
expect ( angular . element . fn . sortable ) . toHaveBeenCalled ( ) ;
362
399
} ) ;
363
400
} ) ;
364
401
402
+ it ( 'should lazily initialize a sortable enabled in $timeout (delete disabled option)' , function ( ) {
403
+ inject ( function ( $compile , $rootScope , $timeout ) {
404
+ var element ;
405
+ var childScope = $rootScope . $new ( ) ;
406
+ spyOn ( angular . element . fn , 'sortable' ) ;
407
+
408
+ childScope . items = [ 'One' , 'Two' , 'Three' ] ;
409
+ childScope . opts = {
410
+ disabled : true
411
+ } ;
412
+ element = $compile ( '<ul ui-sortable="opts" ng-model="items"><li ng-repeat="item in items">{{ item }}</li></ul>' ) ( childScope ) ;
413
+
414
+ expect ( angular . element . fn . sortable ) . not . toHaveBeenCalled ( ) ;
415
+
416
+ expect ( function ( ) {
417
+ $timeout . flush ( ) ;
418
+ } ) . not . toThrow ( ) ;
419
+
420
+ $timeout ( function ( ) {
421
+ childScope . opts = { } ;
422
+ } ) ;
423
+
424
+ $timeout ( function ( ) {
425
+ expect ( angular . element . fn . sortable ) . toHaveBeenCalled ( ) ;
426
+ } ) ;
427
+
428
+ expect ( function ( ) {
429
+ $timeout . flush ( ) ;
430
+ } ) . not . toThrow ( ) ;
431
+
432
+ } ) ;
433
+ } ) ;
365
434
366
435
} ) ;
367
436
0 commit comments