@@ -366,72 +366,40 @@ describe('uiCalendar', function () {
366
366
scope . $apply ( ) ;
367
367
} ) ;
368
368
369
- it ( 'should make sure that all config functions are called in an angular context' , inject ( function ( $timeout , $rootScope ) {
370
- var functionCount = 0 ;
371
- scope . uiConfig = {
372
- calendar :{
373
- height : 200 ,
374
- weekends : false ,
375
- defaultView : 'month' ,
376
- dayClick : function ( ) { } ,
377
- eventClick : function ( ) { } ,
378
- eventDrop : function ( ) { } ,
379
- eventResize : function ( ) { } ,
380
- eventMouseover : function ( ) { }
381
- }
382
- } ;
383
-
384
- spyOn ( $rootScope , '$apply' ) ;
385
-
386
- angular . forEach ( scope . uiConfig . calendar , function ( value , key ) {
387
- if ( typeof value === 'function' ) {
388
- functionCount ++ ;
389
- spyOn ( scope . uiConfig . calendar , key ) ;
369
+ it ( 'should make sure that all config functions are called in an angular context' , inject ( function ( $rootScope ) {
370
+ scope . uiConfig = {
371
+ calendar :{
372
+ height : 200 ,
373
+ weekends : false ,
374
+ defaultView : 'month'
375
+ }
376
+ } ;
390
377
391
- var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
378
+ var keys = [ 'dayClick' , 'eventClick' , 'eventDrop' , 'eventResize' , 'eventMouseover' ] ;
379
+ angular . forEach ( keys , function ( key ) {
380
+ scope . uiConfig . calendar [ key ] = jasmine . createSpy ( ) . andReturn ( key ) ;
381
+ } ) ;
392
382
393
- fullCalendarConfig [ key ] ( ) ;
394
- $timeout . flush ( ) ;
395
- expect ( $rootScope . $apply . callCount ) . toBe ( functionCount ) ;
396
- expect ( scope . uiConfig . calendar [ key ] ) . toHaveBeenCalled ( ) ;
397
- $rootScope . $apply . isSpy = false ;
398
- }
399
- } ) ;
400
- } ) ) ;
383
+ var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
401
384
402
- it ( 'should check that any function that already has an apply in it does not break the calendar (backwards compatible)' , inject ( function ( $timeout , $rootScope ) {
403
-
404
- var functionCount = 0 ;
405
- scope . uiConfig = {
406
- calendar :{
407
- height : 200 ,
408
- weekends : false ,
409
- defaultView : 'month' ,
410
- dayClick : function ( ) { scope . $apply ( ) ; } ,
411
- eventClick : function ( ) { scope . $apply ( ) ; } ,
412
- eventDrop : function ( ) { scope . $apply ( ) ; } ,
413
- eventResize : function ( ) { scope . $apply ( ) ; } ,
414
- eventMouseover : function ( ) { scope . $apply ( ) ; }
415
- }
416
- } ;
385
+ spyOn ( $rootScope , '$apply' ) . andCallThrough ( ) ;
417
386
418
- spyOn ( $rootScope , '$apply' ) ;
387
+ angular . forEach ( keys , function ( key ) {
388
+ $rootScope . $apply . reset ( ) ;
419
389
420
- angular . forEach ( scope . uiConfig . calendar , function ( value , key ) {
421
- if ( typeof value === 'function' ) {
422
- functionCount ++ ;
423
- spyOn ( scope . uiConfig . calendar , key ) ;
390
+ var fn = fullCalendarConfig [ key ] ;
424
391
425
- var fullCalendarConfig = calendarCtrl . getFullCalendarConfig ( scope . uiConfig . calendar , { } ) ;
392
+ expect ( fn ( ) ) . toBe ( key ) ;
393
+ expect ( $rootScope . $apply . callCount ) . toBe ( 1 ) ;
394
+ expect ( scope . uiConfig . calendar [ key ] . callCount ) . toBe ( 1 ) ;
426
395
427
- fullCalendarConfig [ key ] ( ) ;
428
-
429
- scope . $apply ( ) ;
430
- $timeout . flush ( ) ;
431
- expect ( $rootScope . $apply . callCount ) . toBe ( functionCount * 2 ) ;
432
- expect ( scope . uiConfig . calendar [ key ] ) . toHaveBeenCalled ( ) ;
433
- }
434
- } ) ;
396
+ expect ( $rootScope . $apply ( function ( ) {
397
+ expect ( $rootScope . $apply . callCount ) . toBe ( 2 ) ;
398
+ return fn ( ) ;
399
+ } ) ) . toBe ( key ) ;
400
+ expect ( $rootScope . $apply . callCount ) . toBe ( 2 ) ;
401
+ expect ( scope . uiConfig . calendar [ key ] . callCount ) . toBe ( 2 ) ;
402
+ } ) ;
435
403
} ) ) ;
436
404
} ) ;
437
405
0 commit comments