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

Commit 4d4cc3d

Browse files
committed
tests(calendar.spec.js): updated the tests to be more optimized and more unitized
Signed-off-by: Josh Kurz <josh.kurz@turner.com>
1 parent 76ec328 commit 4d4cc3d

File tree

1 file changed

+23
-47
lines changed

1 file changed

+23
-47
lines changed

test/calendar.spec.js

Lines changed: 23 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ describe('uiCalendar', function () {
9999
expect($.fn.fullCalendar.mostRecentCall.args[0].weekends).toEqual(false);
100100
});
101101
/* Test to make sure that when an event is added to the calendar everything is updated with the new event. */
102-
it('expects that when events are added to the calendar the fullcalendar will call its addEvents method', function () {
102+
it('expects that when events are added to the calendar the fullcalendar will call its renderEvent method', function () {
103103
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(4);
104104
expect($.fn.fullCalendar.callCount).toEqual(1);
105105
scope.addChild(scope.events);
@@ -111,89 +111,65 @@ describe('uiCalendar', function () {
111111
expect($.fn.fullCalendar.callCount).toEqual(3);
112112
expect($.fn.fullCalendar.mostRecentCall.args[0]).toEqual('renderEvent');
113113
});
114-
/* Test to make sure the calendar is calling the removeEvent function. */
115-
it('expects the calendar to call removeEvents when some event is removed', function () {
116-
var clientCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
117-
expect(clientCalls).toEqual(4);
118-
//remove an event from the scope.
119-
scope.remove(scope.events,0);
120-
scope.$apply();
121-
//events should auto update inside the calendar.
122-
clientCalls = $.fn.fullCalendar.mostRecentCall.args[0];
123-
expect(clientCalls).toEqual('removeEvents');
124-
});
125-
/* Test to see if calendar is watching all eventSources for changes. */
126-
it('updates the calendar if any eventSource array contains a delta', function () {
127-
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
128-
var clientEventsLength2 = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[1].length;
129-
var callCount = $.fn.fullCalendar.callCount;
130-
expect(calendarCalls).toEqual(4);
131-
expect(clientEventsLength2).toEqual(4);
132-
expect(callCount).toEqual(1);
114+
/* Test to see if calendar is calling removeEvents when an event is removed */
115+
it('removes the correct event from the event source.', function () {
133116
//remove an event from the scope.
134117
scope.remove(scope.events2,0);
135118
scope.$apply();
136119
//events should auto update inside the calendar.
137-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
138-
callCount = $.fn.fullCalendar.callCount;
139-
expect(calendarCalls).toEqual('removeEvents');
120+
var fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
121+
var callCount = $.fn.fullCalendar.callCount;
122+
expect(fullCalendarParam).toEqual('removeEvents');
140123
expect(callCount).toEqual(2);
141124
scope.remove(scope.events,0);
142125
scope.$apply();
143-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
126+
fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
144127
callCount = $.fn.fullCalendar.callCount;
145-
expect(calendarCalls).toEqual('removeEvents');
128+
expect(fullCalendarParam).toEqual('removeEvents');
146129
expect(callCount).toEqual(3);
147130
});
148131
/* Test to see if calendar is updating when a new eventSource is added. */
149132
it('updates the calendar if an eventSource is Added', function () {
150-
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources.length;
151-
expect(calendarCalls).toEqual(2);
152-
//add new source to calendar
153133
scope.addSource(scope.events4);
154134
scope.$apply();
155135
//eventSources should auto update inside the calendar.
156-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
157-
expect(calendarCalls).toEqual('rerenderEvents');
136+
var fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
137+
expect(fullCalendarParam).toEqual('rerenderEvents');
158138
});
159139
/* Test to see if calendar is updating when an eventSource replaces another with an equal length. */
160140
it('updates the calendar if an eventSource has same length as prior eventSource', function () {
161-
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
162-
var callCount = $.fn.fullCalendar.callCount;
163-
expect(calendarCalls[0].length).toEqual(4);
164-
expect(calendarCalls.length).toEqual(2);
165-
expect(calendarCalls[1][0].title).toEqual('All Day Event 2');
166-
expect(callCount).toEqual(1);
167141
//replace source with one that has the same length
168142
scope.eventSources.splice(1,1,scope.events3);
169143
scope.$apply();
170144
//eventSources should update inside the calendar
171-
callCount = $.fn.fullCalendar.callCount;
172-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
173-
expect(calendarCalls).toEqual('rerenderEvents');
145+
var callCount = $.fn.fullCalendar.callCount;
146+
var fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
147+
expect(fullCalendarParam).toEqual('rerenderEvents');
174148
//fullcalendar has called 3 of its own events at this time. Remove, Add, and Rerender
175149
expect(callCount).toEqual(4);
176150
//remove an event to prove autobinding still works
177151
scope.remove(scope.events,0);
178152
scope.$apply();
179-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
180-
expect(calendarCalls).toEqual('removeEvents');
153+
fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
154+
callCount = $.fn.fullCalendar.callCount;
155+
expect(fullCalendarParam).toEqual('removeEvents');
156+
expect(callCount).toEqual(5);
181157
});
182158

183159
it('make sure the calendar can work with extended event sources', function () {
184-
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
185160
scope.eventSources.push(scope.calEventsExt);
186161
scope.$apply();
187-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
188-
expect(calendarCalls).toEqual('rerenderEvents');
162+
var fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
163+
expect(fullCalendarParam).toEqual('rerenderEvents');
189164
});
190165

191166
it('make sure that if we just change the title of the event that it updates itself', function () {
192-
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
193167
scope.events[0].title = 'change title';
194168
scope.$apply();
195-
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
196-
expect(calendarCalls).toEqual('updateEvent');
169+
var fullCalendarParam = $.fn.fullCalendar.mostRecentCall.args[0];
170+
var fullCalendarParam1 = $.fn.fullCalendar.mostRecentCall.args[1];
171+
expect(fullCalendarParam).toEqual('updateEvent');
172+
expect(fullCalendarParam1).toEqual(scope.events[0]);
197173
});
198174

199175
});

0 commit comments

Comments
 (0)