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

Commit 0a9d6d6

Browse files
committed
tests(calendar.spec.js) re wrote the tests to call apply after any model update and test for the correct fullcalendar spy function
Signed-off-by: Josh Kurz <josh.kurz@turner.com>
1 parent ab88d5f commit 0a9d6d6

File tree

1 file changed

+54
-39
lines changed

1 file changed

+54
-39
lines changed

test/calendar.spec.js

Lines changed: 54 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -143,27 +143,34 @@ describe('uiCalendar', function () {
143143
expect($.fn.fullCalendar.mostRecentCall.args[0].weekends).toEqual(false);
144144
});
145145
/* Test to make sure that when an event is added to the calendar everything is updated with the new event. */
146-
it('expects the scopes events to increase by 2', function () {
146+
it('expects that when events are added to the calendar the fullcalendar will call its addEvents method', function () {
147147
spyOn($.fn, 'fullCalendar');
148148
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
149149
scope.$apply();
150150
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(4);
151+
expect($.fn.fullCalendar.callCount).toEqual(1);
151152
scope.addChild(scope.events);
153+
scope.$apply();
154+
expect($.fn.fullCalendar.callCount).toEqual(2);
155+
expect($.fn.fullCalendar.mostRecentCall.args[0]).toEqual('renderEvent');
152156
scope.addChild(scope.events);
153-
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(6);
157+
scope.$apply();
158+
expect($.fn.fullCalendar.callCount).toEqual(3);
159+
expect($.fn.fullCalendar.mostRecentCall.args[0]).toEqual('renderEvent');
154160
});
155161
/* Test to make sure the calendar is updating itself on changes to events length. */
156162
it('expects the calendar to update itself with new events', function () {
157163
spyOn($.fn, 'fullCalendar');
158164
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
159165
scope.$apply();
160-
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
161-
expect(clientEventsLength).toEqual(4);
166+
var clientCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
167+
expect(clientCalls).toEqual(4);
162168
//remove an event from the scope.
163169
scope.remove(scope.events,0);
170+
scope.$apply();
164171
//events should auto update inside the calendar.
165-
clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
166-
expect(clientEventsLength).toEqual(3);
172+
clientCalls = $.fn.fullCalendar.mostRecentCall.args[0];
173+
expect(clientCalls).toEqual('removeEvents');
167174
});
168175
/* Test to make sure header options can be overwritten */
169176
it('overwrites default header options', function () {
@@ -173,7 +180,7 @@ describe('uiCalendar', function () {
173180
header: {center: 'title'}
174181
}
175182
};
176-
$compile('<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>')(scope);
183+
$compile('<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>')(scope);
177184
scope.$apply();
178185
expect($.fn.fullCalendar.mostRecentCall.args[0].hasOwnProperty('header')).toEqual(true);
179186
var header = $.fn.fullCalendar.mostRecentCall.args[0].header;
@@ -184,77 +191,85 @@ describe('uiCalendar', function () {
184191
spyOn($.fn, 'fullCalendar');
185192
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
186193
scope.$apply();
187-
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
194+
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
188195
var clientEventsLength2 = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[1].length;
189-
expect(clientEventsLength).toEqual(4);
196+
var callCount = $.fn.fullCalendar.callCount;
197+
expect(calendarCalls).toEqual(4);
190198
expect(clientEventsLength2).toEqual(4);
199+
expect(callCount).toEqual(1);
191200
//remove an event from the scope.
192201
scope.remove(scope.events2,0);
202+
scope.$apply();
193203
//events should auto update inside the calendar.
194-
clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
195-
clientEventsLength2 = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[1].length;
196-
expect(clientEventsLength).toEqual(4);
197-
expect(clientEventsLength2).toEqual(3);
204+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
205+
callCount = $.fn.fullCalendar.callCount;
206+
expect(calendarCalls).toEqual('removeEvents');
207+
expect(callCount).toEqual(2);
198208
scope.remove(scope.events,0);
199-
clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
200-
expect(clientEventsLength).toEqual(3);
209+
scope.$apply();
210+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
211+
callCount = $.fn.fullCalendar.callCount;
212+
expect(calendarCalls).toEqual('removeEvents');
213+
expect(callCount).toEqual(3);
201214
});
202215
/* Test to see if calendar is updating when a new eventSource is added. */
203216
it('updates the calendar if an eventSource is Added', function () {
204217
spyOn($.fn, 'fullCalendar');
205218
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
206219
scope.$apply();
207-
var clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources.length;
208-
expect(clientEventSources).toEqual(2);
220+
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources.length;
221+
expect(calendarCalls).toEqual(2);
209222
//add new source to calendar
210223
scope.addSource(scope.events4);
224+
scope.$apply();
211225
//eventSources should auto update inside the calendar.
212-
clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources.length;
213-
expect(clientEventSources).toEqual(3);
214-
//go ahead and add some more events to the array and check those too.
215-
scope.addChild(scope.events4);
216-
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[2].length;
217-
expect(clientEventsLength).toEqual(2);
226+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
227+
expect(calendarCalls).toEqual('rerenderEvents');
218228
});
219229
/* Test to see if calendar is updating when an eventSource replaces another with an equal length. */
220230
it('updates the calendar if an eventSource has same length as prior eventSource', function () {
221231
spyOn($.fn, 'fullCalendar');
222232
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
223233
scope.$apply();
224-
var clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
225-
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
226-
expect(clientEventsLength).toEqual(4);
227-
expect(clientEventSources.length).toEqual(2);
228-
expect(clientEventSources[1][0].title).toEqual('All Day Event 2');
234+
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
235+
var callCount = $.fn.fullCalendar.callCount;
236+
expect(calendarCalls[0].length).toEqual(4);
237+
expect(calendarCalls.length).toEqual(2);
238+
expect(calendarCalls[1][0].title).toEqual('All Day Event 2');
239+
expect(callCount).toEqual(1);
229240
//replace source with one that has the same length
230241
scope.eventSources.splice(1,1,scope.events3);
242+
scope.$apply();
231243
//eventSources should update inside the calendar
232-
clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
233-
expect(clientEventSources.length).toEqual(2);
234-
expect(clientEventSources[1][0].title).toEqual('All Day Event 3');
244+
callCount = $.fn.fullCalendar.callCount;
245+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
246+
expect(calendarCalls).toEqual('rerenderEvents');
247+
//fullcalendar has called 3 of its own events at this time. Remove, Add, and Rerender
248+
expect(callCount).toEqual(4);
235249
//remove an event to prove autobinding still works
236250
scope.remove(scope.events,0);
237-
clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
238-
expect(clientEventsLength).toEqual(3);
251+
scope.$apply();
252+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
253+
expect(calendarCalls).toEqual('removeEvents');
239254
});
240255

241256
it('make sure the calendar can work with extended event sources', function () {
242257
spyOn($.fn, 'fullCalendar');
243258
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
244259
scope.$apply();
245-
var clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
260+
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
246261
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
247262
scope.eventSources.push(scope.calEventsExt);
248-
clientEventSources = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
249-
expect(clientEventSources.length).toEqual(3);
250-
expect(clientEventSources[2].events[0].title).toEqual('Lunch');
263+
scope.$apply();
264+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
265+
expect(calendarCalls).toEqual('rerenderEvents');
251266
});
252267

253268
it('make sure the calendar sets the myCalendar object to defining scope', function () {
254269
expect(scope.myCalendar).toBe(undefined);
255270
$compile('<div ui-calendar="uiConfig.calendar" calendar="myCalendar" ng-model="eventSources"></div>')(scope);
256271
scope.$apply();
257-
expect(scope.myCalendar).not.toBe(undefined);
272+
expect(scope.myCalendar).not.toBe(undefined);
258273
});
259274

260275
});
@@ -370,4 +385,4 @@ describe('uiCalendar', function () {
370385

371386
});
372387

373-
});
388+
});

0 commit comments

Comments
 (0)