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

Commit fea3e86

Browse files
author
Costin Zaharia
committed
Added unit tests for event wrappers and for refetchEvents command.
1 parent 3fc96af commit fea3e86

File tree

1 file changed

+86
-1
lines changed

1 file changed

+86
-1
lines changed

test/calendar.spec.js

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ describe('uiCalendar', function () {
7474
calendar:{
7575
height: 200,
7676
weekends: false,
77-
defaultView: 'month'
77+
defaultView: 'month',
78+
dayClick: function(){},
79+
eventClick: function(){},
80+
eventDrop: function(){},
81+
eventResize: function(){}
7882
}
7983
};
8084

@@ -291,6 +295,87 @@ describe('uiCalendar', function () {
291295
expect(sourcesChanged).toBe('removed');
292296
});
293297

298+
it('makes sure that dayClick is called in angular context', inject(function($timeout, $rootScope){
299+
spyOn(scope.uiConfig.calendar, 'dayClick');
300+
spyOn($rootScope,'$apply');
301+
302+
var fullCalendarConfig = calendarCtrl.getFullCalendarConfig(scope.uiConfig.calendar, {});
303+
304+
fullCalendarConfig.dayClick();
305+
306+
$timeout.flush();
307+
308+
expect($rootScope.$apply).toHaveBeenCalled();
309+
expect(scope.uiConfig.calendar.dayClick).toHaveBeenCalled();
310+
}));
311+
312+
it('makes sure that eventClick is called in angular context', inject(function($timeout, $rootScope){
313+
spyOn(scope.uiConfig.calendar, 'eventClick');
314+
spyOn($rootScope,'$apply');
315+
316+
var fullCalendarConfig = calendarCtrl.getFullCalendarConfig(scope.uiConfig.calendar, {});
317+
318+
fullCalendarConfig.eventClick();
319+
320+
$timeout.flush();
321+
322+
expect($rootScope.$apply).toHaveBeenCalled();
323+
expect(scope.uiConfig.calendar.eventClick).toHaveBeenCalled();
324+
}));
325+
326+
it('makes sure that eventDrop is called in angular context', inject(function($timeout, $rootScope){
327+
spyOn(scope.uiConfig.calendar, 'eventDrop');
328+
spyOn($rootScope,'$apply');
329+
330+
var fullCalendarConfig = calendarCtrl.getFullCalendarConfig(scope.uiConfig.calendar, {});
331+
332+
fullCalendarConfig.eventDrop();
333+
334+
$timeout.flush();
335+
336+
expect($rootScope.$apply).toHaveBeenCalled();
337+
expect(scope.uiConfig.calendar.eventDrop).toHaveBeenCalled();
338+
}));
339+
340+
it('makes sure that eventResize is called in angular context', inject(function($timeout, $rootScope){
341+
spyOn(scope.uiConfig.calendar, 'eventResize');
342+
spyOn($rootScope,'$apply');
343+
344+
var fullCalendarConfig = calendarCtrl.getFullCalendarConfig(scope.uiConfig.calendar, {});
345+
346+
fullCalendarConfig.eventResize();
347+
348+
$timeout.flush();
349+
350+
expect($rootScope.$apply).toHaveBeenCalled();
351+
expect(scope.uiConfig.calendar.eventResize).toHaveBeenCalled();
352+
}));
353+
354+
it('should not fail when addCommands is called with undefined settings ', function(){
355+
expect(calendarCtrl.addCommands).not.toThrow()
356+
});
357+
358+
it('makes sure that refetchEvents command is added on the configuration', function(){
359+
calendarCtrl.addCommands(scope.uiConfig.calendar, undefined);
360+
361+
expect(scope.uiConfig.calendar.refetchEvents).toBeDefined();
362+
});
363+
364+
it('makes sure that fullCallendar is called with \'refetchEvents\' when refetchEvents command is called', function(){
365+
var fakeCalendar ={
366+
fullCalendar: function(string){
367+
368+
}
369+
}
370+
371+
spyOn(fakeCalendar, 'fullCalendar');
372+
373+
calendarCtrl.addCommands(scope.uiConfig.calendar, fakeCalendar);
374+
375+
scope.uiConfig.calendar.refetchEvents()
376+
377+
expect(fakeCalendar.fullCalendar).toHaveBeenCalledWith('refetchEvents');
378+
});
294379
});
295380

296381
describe('Testing the ability to add calendars to the scope', function(){

0 commit comments

Comments
 (0)