Skip to content
This repository was archived by the owner on Sep 8, 2020. It is now read-only.

Commit ca43a85

Browse files
committed
merge(spec): merging conflicts
Signed-off-by: Josh Kurz <jkurz25@gmail.com>
2 parents 3cdd780 + bce2616 commit ca43a85

File tree

2 files changed

+37
-74
lines changed

2 files changed

+37
-74
lines changed

src/calendar.js

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,32 +11,27 @@
1111
angular.module('ui.calendar', [])
1212
.constant('uiCalendarConfig', {calendars: {}})
1313
.controller('uiCalendarCtrl', ['$scope',
14-
'$timeout',
1514
'$locale', function(
1615
$scope,
17-
$timeout,
1816
$locale){
1917

2018
var sources = $scope.eventSources,
2119
extraEventSignature = $scope.calendarWatchEvent ? $scope.calendarWatchEvent : angular.noop,
2220

2321
wrapFunctionWithScopeApply = function(functionToWrap){
24-
var wrapper;
25-
26-
if (functionToWrap){
27-
wrapper = function(){
28-
// This happens outside of angular context so we need to wrap it in a timeout which has an implied apply.
29-
// In this way the function will be safely executed on the next digest.
22+
return function(){
23+
// This may happen outside of angular context, so create one if outside.
3024

25+
if ($scope.$root.$$phase) {
26+
return functionToWrap.apply(this, arguments);
27+
} else {
3128
var args = arguments;
32-
var _this = this;
33-
$timeout(function(){
34-
functionToWrap.apply(_this, args);
29+
var self = this;
30+
return $scope.$root.$apply(function(){
31+
return functionToWrap.apply(self, args);
3532
});
36-
};
37-
}
38-
39-
return wrapper;
33+
}
34+
};
4035
};
4136

4237
var eventSerialId = 1;

test/calendar.spec.js

Lines changed: 27 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -366,72 +366,40 @@ describe('uiCalendar', function () {
366366
scope.$apply();
367367
});
368368

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+
};
390377

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+
});
392382

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, {});
401384

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();
417386

418-
spyOn($rootScope,'$apply');
387+
angular.forEach(keys, function(key){
388+
$rootScope.$apply.reset();
419389

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];
424391

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);
426395

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+
});
435403
}));
436404
});
437405

0 commit comments

Comments
 (0)