|
|
@@ -1,11 +1,9 @@
|
|
|
|
|
|
-// TODO: revive
|
|
|
-// Google removes holidays that are old, and returns no results, breaking these tests
|
|
|
-xdescribe('Google Calendar plugin', function() {
|
|
|
+describe('Google Calendar plugin', function() {
|
|
|
|
|
|
var API_KEY = 'AIzaSyDcnW6WejpTOCffshGDDb4neIrXVUA1EAE';
|
|
|
+ var HOLIDAY_CALENDAR_ID = 'en.usa#[email protected]';
|
|
|
var options;
|
|
|
- var currentRequest;
|
|
|
var currentWarnArgs;
|
|
|
var oldConsoleWarn;
|
|
|
|
|
|
@@ -14,24 +12,9 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
|
|
|
options = {
|
|
|
defaultView: 'month',
|
|
|
- defaultDate: '2014-11-01'
|
|
|
+ defaultDate: '2016-11-01'
|
|
|
};
|
|
|
|
|
|
- // Mockjax is bad with JSONP (https://github.com/jakerella/jquery-mockjax/issues/136)
|
|
|
- // Workaround. Wanted to use mockedAjaxCalls(), but JSONP requests get mangled later on.
|
|
|
- currentRequest = null;
|
|
|
- $.mockjaxSettings.log = function(mockHandler, request) {
|
|
|
- currentRequest = currentRequest || $.extend({}, request); // copy
|
|
|
- };
|
|
|
-
|
|
|
- // Will cause all requests to go through $.mockjaxSettings.log, but will not actually handle
|
|
|
- // any of the requests due to the JSONP bug mentioned above.
|
|
|
- // THE REAL REQUESTS WILL GO THROUGH TO THE GOOGLE CALENDAR API!
|
|
|
- $.mockjax({
|
|
|
- url: '*',
|
|
|
- responseText: {}
|
|
|
- });
|
|
|
-
|
|
|
// Intercept calls to console.warn
|
|
|
currentWarnArgs = null;
|
|
|
oldConsoleWarn = console.warn;
|
|
|
@@ -41,24 +24,25 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
});
|
|
|
|
|
|
afterEach(function() {
|
|
|
- $.mockjaxClear();
|
|
|
+ $.mockjax.clear();
|
|
|
$.mockjaxSettings.log = function() { };
|
|
|
console.warn = oldConsoleWarn;
|
|
|
});
|
|
|
|
|
|
it('request/receives correctly when local timezone', function(done) {
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
- options.events = { googleCalendarId: '[email protected]' };
|
|
|
+ options.events = { googleCalendarId: HOLIDAY_CALENDAR_ID };
|
|
|
options.timezone = 'local';
|
|
|
options.eventAfterAllRender = function() {
|
|
|
+ var currentRequest = $.mockjax.unmockedAjaxCalls()[0];
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
var i;
|
|
|
|
|
|
- expect(currentRequest.data.timeMin).toEqual('2014-10-25T00:00:00+00:00'); // one day before, by design
|
|
|
- expect(currentRequest.data.timeMax).toEqual('2014-12-08T00:00:00+00:00'); // one day after, by design
|
|
|
+ expect(currentRequest.data.timeMin).toEqual('2016-10-29T00:00:00Z'); // one day before, by design
|
|
|
+ expect(currentRequest.data.timeMax).toEqual('2016-12-12T00:00:00Z'); // one day after, by design
|
|
|
expect(currentRequest.data.timeZone).toBeUndefined();
|
|
|
|
|
|
- expect(events.length).toBe(4);
|
|
|
+ expect(events.length).toBe(5);
|
|
|
for (i = 0; i < events.length; i++) {
|
|
|
expect(events[i].url).not.toMatch('ctz=');
|
|
|
}
|
|
|
@@ -70,17 +54,18 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
|
|
|
it('request/receives correctly when UTC timezone', function(done) {
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
- options.events = { googleCalendarId: '[email protected]' };
|
|
|
+ options.events = { googleCalendarId: HOLIDAY_CALENDAR_ID };
|
|
|
options.timezone = 'UTC';
|
|
|
options.eventAfterAllRender = function() {
|
|
|
+ var currentRequest = $.mockjax.unmockedAjaxCalls()[0];
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
var i;
|
|
|
|
|
|
- expect(currentRequest.data.timeMin).toEqual('2014-10-25T00:00:00+00:00'); // one day before, by design
|
|
|
- expect(currentRequest.data.timeMax).toEqual('2014-12-08T00:00:00+00:00'); // one day after, by design
|
|
|
+ expect(currentRequest.data.timeMin).toEqual('2016-10-29T00:00:00Z'); // one day before, by design
|
|
|
+ expect(currentRequest.data.timeMax).toEqual('2016-12-12T00:00:00Z'); // one day after, by design
|
|
|
expect(currentRequest.data.timeZone).toEqual('UTC');
|
|
|
|
|
|
- expect(events.length).toBe(4);
|
|
|
+ expect(events.length).toBe(5);
|
|
|
for (i = 0; i < events.length; i++) {
|
|
|
expect(events[i].url).toMatch('ctz=UTC');
|
|
|
}
|
|
|
@@ -92,17 +77,18 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
|
|
|
it('request/receives correctly when custom timezone', function(done) {
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
- options.events = { googleCalendarId: '[email protected]' };
|
|
|
+ options.events = { googleCalendarId: HOLIDAY_CALENDAR_ID };
|
|
|
options.timezone = 'America/New York';
|
|
|
options.eventAfterAllRender = function() {
|
|
|
+ var currentRequest = $.mockjax.unmockedAjaxCalls()[0];
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
var i;
|
|
|
|
|
|
- expect(currentRequest.data.timeMin).toEqual('2014-10-25T00:00:00+00:00'); // one day before, by design
|
|
|
- expect(currentRequest.data.timeMax).toEqual('2014-12-08T00:00:00+00:00'); // one day after, by design
|
|
|
+ expect(currentRequest.data.timeMin).toEqual('2016-10-29T00:00:00Z'); // one day before, by design
|
|
|
+ expect(currentRequest.data.timeMax).toEqual('2016-12-12T00:00:00Z'); // one day after, by design
|
|
|
expect(currentRequest.data.timeZone).toEqual('America/New_York'); // space should be escaped
|
|
|
|
|
|
- expect(events.length).toBe(4);
|
|
|
+ expect(events.length).toBe(5);
|
|
|
for (i = 0; i < events.length; i++) {
|
|
|
expect(events[i].url).toMatch('ctz=America/New_York');
|
|
|
}
|
|
|
@@ -114,22 +100,23 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
|
|
|
it('requests/receives correctly when no timezone, defaults to not editable', function(done) {
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
- options.events = { googleCalendarId: '[email protected]' };
|
|
|
+ options.events = { googleCalendarId: HOLIDAY_CALENDAR_ID };
|
|
|
options.eventAfterAllRender = function() {
|
|
|
+ var currentRequest = $.mockjax.unmockedAjaxCalls()[0];
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
var eventEls = $('.fc-event');
|
|
|
var i;
|
|
|
|
|
|
- expect(currentRequest.data.timeMin).toEqual('2014-10-25T00:00:00+00:00'); // one day before, by design
|
|
|
- expect(currentRequest.data.timeMax).toEqual('2014-12-08T00:00:00+00:00'); // one day after, by design
|
|
|
+ expect(currentRequest.data.timeMin).toEqual('2016-10-29T00:00:00Z'); // one day before, by design
|
|
|
+ expect(currentRequest.data.timeMax).toEqual('2016-12-12T00:00:00Z'); // one day after, by design
|
|
|
expect(currentRequest.data.timeZone).toBeUndefined();
|
|
|
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
for (i = 0; i < events.length; i++) {
|
|
|
expect(events[i].url).not.toMatch('ctz=');
|
|
|
}
|
|
|
|
|
|
- expect(eventEls.length).toBe(4);
|
|
|
+ expect(eventEls.length).toBe(5);
|
|
|
expect(eventEls.find('.fc-resizer').length).toBe(0); // not editable
|
|
|
|
|
|
done();
|
|
|
@@ -140,12 +127,12 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
it('allows editable to explicitly be set to true', function(done) {
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
options.events = {
|
|
|
- googleCalendarId: '[email protected]',
|
|
|
+ googleCalendarId: HOLIDAY_CALENDAR_ID,
|
|
|
editable: true
|
|
|
};
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var eventEls = $('.fc-event');
|
|
|
- expect(eventEls.length).toBe(4);
|
|
|
+ expect(eventEls.length).toBe(5);
|
|
|
expect(eventEls.find('.fc-resizer').length).toBeGreaterThan(0); // editable!
|
|
|
done();
|
|
|
};
|
|
|
@@ -154,12 +141,12 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
|
|
|
it('fetches events correctly when API key is in the event source', function(done) {
|
|
|
options.events = {
|
|
|
- googleCalendarId: '[email protected]',
|
|
|
+ googleCalendarId: HOLIDAY_CALENDAR_ID,
|
|
|
googleCalendarApiKey: API_KEY
|
|
|
};
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
done();
|
|
|
};
|
|
|
$('#cal').fullCalendar(options);
|
|
|
@@ -174,15 +161,17 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
googleCalendarError: function(err) {
|
|
|
expect(typeof err).toBe('object');
|
|
|
},
|
|
|
- googleCalendarId: '[email protected]'
|
|
|
+ googleCalendarId: HOLIDAY_CALENDAR_ID
|
|
|
};
|
|
|
options.eventAfterAllRender = function() {
|
|
|
+ var currentRequest = $.mockjax.unmockedAjaxCalls()[0];
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
+
|
|
|
expect(events.length).toBe(0);
|
|
|
expect(currentWarnArgs.length).toBeGreaterThan(0);
|
|
|
expect(options.googleCalendarError).toHaveBeenCalled();
|
|
|
expect(options.events.googleCalendarError).toHaveBeenCalled();
|
|
|
- expect(currentRequest).toBeNull(); // AJAX request should have never been made!
|
|
|
+ expect(currentRequest).toBeUndefined(); // AJAX request should have never been made!
|
|
|
done();
|
|
|
};
|
|
|
spyOn(options, 'googleCalendarError').and.callThrough();
|
|
|
@@ -201,10 +190,12 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
googleCalendarError: function(err) {
|
|
|
expect(typeof err).toBe('object');
|
|
|
},
|
|
|
- googleCalendarId: '[email protected]'
|
|
|
+ googleCalendarId: HOLIDAY_CALENDAR_ID
|
|
|
};
|
|
|
options.eventAfterAllRender = function() {
|
|
|
+ var currentRequest = $.mockjax.unmockedAjaxCalls()[0];
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
+
|
|
|
expect(events.length).toBe(0);
|
|
|
expect(currentWarnArgs.length).toBeGreaterThan(0);
|
|
|
expect(options.googleCalendarError).toHaveBeenCalled();
|
|
|
@@ -220,10 +211,10 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
|
|
|
it('works when `events` is the actual calendar ID', function(done) {
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
- options.events = '[email protected]';
|
|
|
+ options.events = HOLIDAY_CALENDAR_ID;
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
done();
|
|
|
};
|
|
|
$('#cal').fullCalendar(options);
|
|
|
@@ -278,7 +269,7 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
options.events = 'http://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic';
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
done();
|
|
|
};
|
|
|
$('#cal').fullCalendar(options);
|
|
|
@@ -289,7 +280,7 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
options.events = 'https://www.google.com/calendar/feeds/usa__en%40holiday.calendar.google.com/public/basic';
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
done();
|
|
|
};
|
|
|
$('#cal').fullCalendar(options);
|
|
|
@@ -301,7 +292,7 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
'https://www.googleapis.com/calendar/v3/calendars/usa__en%40holiday.calendar.google.com/events';
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
done();
|
|
|
};
|
|
|
$('#cal').fullCalendar(options);
|
|
|
@@ -310,11 +301,11 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
describe('removeEventSource', function() {
|
|
|
|
|
|
it('works when specifying only the Google Calendar ID', function(done) {
|
|
|
- var CALENDAR_ID = '[email protected]';
|
|
|
+ var CALENDAR_ID = HOLIDAY_CALENDAR_ID;
|
|
|
var called = false;
|
|
|
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
- options.eventSources = [ { googleCalendarId: CALENDAR_ID } ];
|
|
|
+ options.eventSources = [ { googleCalendarId: HOLIDAY_CALENDAR_ID } ];
|
|
|
options.eventAfterAllRender = function() {
|
|
|
var events;
|
|
|
|
|
|
@@ -322,10 +313,10 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
called = true;
|
|
|
|
|
|
events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
|
|
|
setTimeout(function() {
|
|
|
- $('#cal').fullCalendar('removeEventSource', CALENDAR_ID);
|
|
|
+ $('#cal').fullCalendar('removeEventSource', HOLIDAY_CALENDAR_ID);
|
|
|
events = $('#cal').fullCalendar('clientEvents');
|
|
|
expect(events.length).toBe(0);
|
|
|
done();
|
|
|
@@ -336,8 +327,7 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
});
|
|
|
|
|
|
it('works when specifying a raw Google Calendar source object', function(done) {
|
|
|
- var CALENDAR_ID = '[email protected]';
|
|
|
- var googleSource = { googleCalendarId: CALENDAR_ID };
|
|
|
+ var googleSource = { googleCalendarId: HOLIDAY_CALENDAR_ID };
|
|
|
var called = false;
|
|
|
|
|
|
options.googleCalendarApiKey = API_KEY;
|
|
|
@@ -349,7 +339,7 @@ xdescribe('Google Calendar plugin', function() {
|
|
|
called = true;
|
|
|
|
|
|
events = $('#cal').fullCalendar('clientEvents');
|
|
|
- expect(events.length).toBe(4); // 4 holidays in November 2014
|
|
|
+ expect(events.length).toBe(5); // 5 holidays in November 2016 (and end of Oct)
|
|
|
|
|
|
setTimeout(function() {
|
|
|
$('#cal').fullCalendar('removeEventSource', googleSource);
|