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

Commit 76ec328

Browse files
committed
tests(calendar.spec) reconfigured the tests and added one more for changing the title of an event
also reverted karma back a couple versions because the latest does not do console logs Signed-off-by: Josh Kurz <josh.kurz@turner.com>
1 parent 0a9d6d6 commit 76ec328

File tree

2 files changed

+62
-89
lines changed

2 files changed

+62
-89
lines changed

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
"dependencies": {},
1010
"devDependencies": {
1111
"grunt": "~0.4",
12-
"grunt-karma": "~0.7",
12+
"grunt-karma": "0.7.0",
1313
"grunt-contrib-jshint": "~0.2",
1414
"matchdep": "~0.1",
15-
"karma": "~0.11",
15+
"karma": "~0.10",
1616
"karma-coverage": "~0.1",
1717
"load-grunt-tasks": "~0.2",
1818
"karma-jasmine": "0.1",

test/calendar.spec.js

Lines changed: 60 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -81,72 +81,25 @@ describe('uiCalendar', function () {
8181
}));
8282

8383
describe('compiling this directive and checking for events inside the calendar', function () {
84-
85-
it('sets names for $locale by default', function() {
84+
85+
beforeEach(function(){
8686
spyOn($.fn, 'fullCalendar');
87-
$locale.DATETIME_FORMATS.MONTH[0] = 'enero';
8887
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
8988
scope.$apply();
90-
expect($.fn.fullCalendar.mostRecentCall.args[0].monthNames[0]).toBe('enero');
91-
});
92-
93-
it('allows overriding names for $locale', function() {
94-
spyOn($.fn, 'fullCalendar');
95-
scope.uiConfig.calendar.monthNames = $locale.DATETIME_FORMATS.MONTH.slice();
96-
scope.uiConfig.calendar.monthNames[0] = 'custom name';
97-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
98-
scope.$apply();
99-
expect($.fn.fullCalendar.mostRecentCall.args[0].monthNames[0]).toBe('custom name');
10089
});
10190

102-
/* test the calendar's events length */
103-
it('expects to load 4 events to scope', function () {
104-
spyOn($.fn, 'fullCalendar');
105-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
106-
scope.$apply();
91+
/* test the calendar's initial setup */
92+
it('expects the calendar to be set up with the correct options and events', function () {
10793
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toBe(4);
108-
});
109-
/* test to check the title of the first event. */
110-
it('expects to be All Day Event', function () {
111-
spyOn($.fn, 'fullCalendar');
112-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
113-
scope.$apply();
11494
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][0].title).toBe('All Day Event');
115-
});
116-
/* test to make sure the event has a url assigned to it. */
117-
it('expects the url to = http://www.angularjs.org', function () {
118-
spyOn($.fn, 'fullCalendar');
119-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
120-
scope.$apply();
12195
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][0].url).toBe('http://www.angularjs.org');
12296
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[1][0].url).toBe('http://www.atlantacarlocksmith.com');
123-
});
124-
/* test the 3rd events' allDay field. */
125-
it('expects the fourth Events all Day field to equal true', function () {
126-
spyOn($.fn, 'fullCalendar');
127-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
128-
scope.$apply();
12997
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0][3].allDay).toNotBe(false);
130-
});
131-
/* Tests the height of the calendar. */
132-
it('expects the calendar attribute height to be 200', function () {
133-
spyOn($.fn, 'fullCalendar');
134-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
135-
scope.$apply();
13698
expect($.fn.fullCalendar.mostRecentCall.args[0].height).toEqual(200);
137-
});
138-
/* Tests the weekends boolean of the calendar. */
139-
it('expects the calendar attribute weekends to be false', function () {
140-
spyOn($.fn, 'fullCalendar');
141-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
142-
scope.$apply();
14399
expect($.fn.fullCalendar.mostRecentCall.args[0].weekends).toEqual(false);
144100
});
145101
/* Test to make sure that when an event is added to the calendar everything is updated with the new event. */
146102
it('expects that when events are added to the calendar the fullcalendar will call its addEvents method', function () {
147-
spyOn($.fn, 'fullCalendar');
148-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
149-
scope.$apply();
150103
expect($.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length).toEqual(4);
151104
expect($.fn.fullCalendar.callCount).toEqual(1);
152105
scope.addChild(scope.events);
@@ -158,11 +111,8 @@ describe('uiCalendar', function () {
158111
expect($.fn.fullCalendar.callCount).toEqual(3);
159112
expect($.fn.fullCalendar.mostRecentCall.args[0]).toEqual('renderEvent');
160113
});
161-
/* Test to make sure the calendar is updating itself on changes to events length. */
162-
it('expects the calendar to update itself with new events', function () {
163-
spyOn($.fn, 'fullCalendar');
164-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
165-
scope.$apply();
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 () {
166116
var clientCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
167117
expect(clientCalls).toEqual(4);
168118
//remove an event from the scope.
@@ -172,25 +122,8 @@ describe('uiCalendar', function () {
172122
clientCalls = $.fn.fullCalendar.mostRecentCall.args[0];
173123
expect(clientCalls).toEqual('removeEvents');
174124
});
175-
/* Test to make sure header options can be overwritten */
176-
it('overwrites default header options', function () {
177-
spyOn($.fn, 'fullCalendar');
178-
scope.uiConfig2 = {
179-
calendar:{
180-
header: {center: 'title'}
181-
}
182-
};
183-
$compile('<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>')(scope);
184-
scope.$apply();
185-
expect($.fn.fullCalendar.mostRecentCall.args[0].hasOwnProperty('header')).toEqual(true);
186-
var header = $.fn.fullCalendar.mostRecentCall.args[0].header;
187-
expect(header).toEqual({center: 'title'});
188-
});
189125
/* Test to see if calendar is watching all eventSources for changes. */
190126
it('updates the calendar if any eventSource array contains a delta', function () {
191-
spyOn($.fn, 'fullCalendar');
192-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
193-
scope.$apply();
194127
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
195128
var clientEventsLength2 = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[1].length;
196129
var callCount = $.fn.fullCalendar.callCount;
@@ -214,9 +147,6 @@ describe('uiCalendar', function () {
214147
});
215148
/* Test to see if calendar is updating when a new eventSource is added. */
216149
it('updates the calendar if an eventSource is Added', function () {
217-
spyOn($.fn, 'fullCalendar');
218-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
219-
scope.$apply();
220150
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources.length;
221151
expect(calendarCalls).toEqual(2);
222152
//add new source to calendar
@@ -228,9 +158,6 @@ describe('uiCalendar', function () {
228158
});
229159
/* Test to see if calendar is updating when an eventSource replaces another with an equal length. */
230160
it('updates the calendar if an eventSource has same length as prior eventSource', function () {
231-
spyOn($.fn, 'fullCalendar');
232-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
233-
scope.$apply();
234161
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
235162
var callCount = $.fn.fullCalendar.callCount;
236163
expect(calendarCalls[0].length).toEqual(4);
@@ -254,22 +181,19 @@ describe('uiCalendar', function () {
254181
});
255182

256183
it('make sure the calendar can work with extended event sources', function () {
257-
spyOn($.fn, 'fullCalendar');
258-
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
259-
scope.$apply();
260184
var calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0].eventSources;
261-
var clientEventsLength = $.fn.fullCalendar.mostRecentCall.args[0].eventSources[0].length;
262185
scope.eventSources.push(scope.calEventsExt);
263186
scope.$apply();
264187
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
265188
expect(calendarCalls).toEqual('rerenderEvents');
266189
});
267190

268-
it('make sure the calendar sets the myCalendar object to defining scope', function () {
269-
expect(scope.myCalendar).toBe(undefined);
270-
$compile('<div ui-calendar="uiConfig.calendar" calendar="myCalendar" ng-model="eventSources"></div>')(scope);
191+
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;
193+
scope.events[0].title = 'change title';
271194
scope.$apply();
272-
expect(scope.myCalendar).not.toBe(undefined);
195+
calendarCalls = $.fn.fullCalendar.mostRecentCall.args[0];
196+
expect(calendarCalls).toEqual('updateEvent');
273197
});
274198

275199
});
@@ -385,4 +309,53 @@ describe('uiCalendar', function () {
385309

386310
});
387311

312+
describe('Testing the ability to add calendars to the scope', function(){
313+
314+
beforeEach(function(){
315+
spyOn($.fn, 'fullCalendar');
316+
expect(scope.myCalendar).toBe(undefined);
317+
$compile('<div ui-calendar="uiConfig.calendar" calendar="myCalendar" ng-model="eventSources"></div>')(scope);
318+
scope.$apply();
319+
});
320+
321+
it('make sure the calendar sets the myCalendar object to the defining scope', function () {
322+
expect(scope.myCalendar).not.toBe(undefined);
323+
});
324+
});
325+
326+
describe('Local variable config testing and option overriding', function(){
327+
328+
it('sets names for $locale by default', function() {
329+
spyOn($.fn, 'fullCalendar');
330+
$locale.DATETIME_FORMATS.MONTH[0] = 'enero';
331+
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
332+
scope.$apply();
333+
expect($.fn.fullCalendar.mostRecentCall.args[0].monthNames[0]).toBe('enero');
334+
});
335+
336+
it('allows overriding names for $locale', function() {
337+
spyOn($.fn, 'fullCalendar');
338+
scope.uiConfig.calendar.monthNames = $locale.DATETIME_FORMATS.MONTH.slice();
339+
scope.uiConfig.calendar.monthNames[0] = 'custom name';
340+
$compile('<div ui-calendar="uiConfig.calendar" ng-model="eventSources"></div>')(scope);
341+
scope.$apply();
342+
expect($.fn.fullCalendar.mostRecentCall.args[0].monthNames[0]).toBe('custom name');
343+
});
344+
345+
/* Test to make sure header options can be overwritten */
346+
it('overwrites default header options', function () {
347+
spyOn($.fn, 'fullCalendar');
348+
scope.uiConfig2 = {
349+
calendar:{
350+
header: {center: 'title'}
351+
}
352+
};
353+
$compile('<div ui-calendar="uiConfig2.calendar" ng-model="eventSources"></div>')(scope);
354+
scope.$apply();
355+
expect($.fn.fullCalendar.mostRecentCall.args[0].hasOwnProperty('header')).toEqual(true);
356+
var header = $.fn.fullCalendar.mostRecentCall.args[0].header;
357+
expect(header).toEqual({center: 'title'});
358+
});
359+
});
360+
388361
});

0 commit comments

Comments
 (0)