@@ -143,27 +143,34 @@ describe('uiCalendar', function () {
143
143
expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . weekends ) . toEqual ( false ) ;
144
144
} ) ;
145
145
/* 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 ( ) {
147
147
spyOn ( $ . fn , 'fullCalendar' ) ;
148
148
$compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
149
149
scope . $apply ( ) ;
150
150
expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ) . toEqual ( 4 ) ;
151
+ expect ( $ . fn . fullCalendar . callCount ) . toEqual ( 1 ) ;
151
152
scope . addChild ( scope . events ) ;
153
+ scope . $apply ( ) ;
154
+ expect ( $ . fn . fullCalendar . callCount ) . toEqual ( 2 ) ;
155
+ expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] ) . toEqual ( 'renderEvent' ) ;
152
156
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' ) ;
154
160
} ) ;
155
161
/* Test to make sure the calendar is updating itself on changes to events length. */
156
162
it ( 'expects the calendar to update itself with new events' , function ( ) {
157
163
spyOn ( $ . fn , 'fullCalendar' ) ;
158
164
$compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
159
165
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 ) ;
162
168
//remove an event from the scope.
163
169
scope . remove ( scope . events , 0 ) ;
170
+ scope . $apply ( ) ;
164
171
//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' ) ;
167
174
} ) ;
168
175
/* Test to make sure header options can be overwritten */
169
176
it ( 'overwrites default header options' , function ( ) {
@@ -173,7 +180,7 @@ describe('uiCalendar', function () {
173
180
header : { center : 'title' }
174
181
}
175
182
} ;
176
- $compile ( '<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
183
+ $compile ( '<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
177
184
scope . $apply ( ) ;
178
185
expect ( $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . hasOwnProperty ( 'header' ) ) . toEqual ( true ) ;
179
186
var header = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . header ;
@@ -184,77 +191,85 @@ describe('uiCalendar', function () {
184
191
spyOn ( $ . fn , 'fullCalendar' ) ;
185
192
$compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
186
193
scope . $apply ( ) ;
187
- var clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
194
+ var calendarCalls = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
188
195
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 ) ;
190
198
expect ( clientEventsLength2 ) . toEqual ( 4 ) ;
199
+ expect ( callCount ) . toEqual ( 1 ) ;
191
200
//remove an event from the scope.
192
201
scope . remove ( scope . events2 , 0 ) ;
202
+ scope . $apply ( ) ;
193
203
//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 ) ;
198
208
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 ) ;
201
214
} ) ;
202
215
/* Test to see if calendar is updating when a new eventSource is added. */
203
216
it ( 'updates the calendar if an eventSource is Added' , function ( ) {
204
217
spyOn ( $ . fn , 'fullCalendar' ) ;
205
218
$compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
206
219
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 ) ;
209
222
//add new source to calendar
210
223
scope . addSource ( scope . events4 ) ;
224
+ scope . $apply ( ) ;
211
225
//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' ) ;
218
228
} ) ;
219
229
/* Test to see if calendar is updating when an eventSource replaces another with an equal length. */
220
230
it ( 'updates the calendar if an eventSource has same length as prior eventSource' , function ( ) {
221
231
spyOn ( $ . fn , 'fullCalendar' ) ;
222
232
$compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
223
233
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 ) ;
229
240
//replace source with one that has the same length
230
241
scope . eventSources . splice ( 1 , 1 , scope . events3 ) ;
242
+ scope . $apply ( ) ;
231
243
//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 ) ;
235
249
//remove an event to prove autobinding still works
236
250
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' ) ;
239
254
} ) ;
240
255
241
256
it ( 'make sure the calendar can work with extended event sources' , function ( ) {
242
257
spyOn ( $ . fn , 'fullCalendar' ) ;
243
258
$compile ( '<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>' ) ( scope ) ;
244
259
scope . $apply ( ) ;
245
- var clientEventSources = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources ;
260
+ var calendarCalls = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources ;
246
261
var clientEventsLength = $ . fn . fullCalendar . mostRecentCall . args [ 0 ] . eventSources [ 0 ] . length ;
247
262
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 ' ) ;
251
266
} ) ;
252
267
253
268
it ( 'make sure the calendar sets the myCalendar object to defining scope' , function ( ) {
254
269
expect ( scope . myCalendar ) . toBe ( undefined ) ;
255
270
$compile ( '<div ui-calendar="uiConfig.calendar" calendar="myCalendar" ng-model="eventSources"></div>' ) ( scope ) ;
256
271
scope . $apply ( ) ;
257
- expect ( scope . myCalendar ) . not . toBe ( undefined ) ;
272
+ expect ( scope . myCalendar ) . not . toBe ( undefined ) ;
258
273
} ) ;
259
274
260
275
} ) ;
@@ -370,4 +385,4 @@ describe('uiCalendar', function () {
370
385
371
386
} ) ;
372
387
373
- } ) ;
388
+ } ) ;
0 commit comments