mirror of
https://github.com/wassname/fullcalendar.git
synced 2026-09-11 12:10:23 +08:00
events (array/function/feed) tests. timezone tests
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
|
||||
describe('events as an array', function() {
|
||||
|
||||
var options;
|
||||
var eventArray;
|
||||
|
||||
beforeEach(function() {
|
||||
affix('#cal');
|
||||
options = {
|
||||
defaultView: 'month',
|
||||
defaultDate: '2014-05-01'
|
||||
};
|
||||
eventArray = [
|
||||
{
|
||||
title: 'my event',
|
||||
start: '2014-05-21'
|
||||
}
|
||||
];
|
||||
});
|
||||
|
||||
it('accepts an event using basic form', function(done) {
|
||||
options.events = eventArray;
|
||||
options.eventRender = function(eventObj, eventElm) {
|
||||
expect(eventObj.title).toEqual('my event');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('accepts an event using extended form', function(done) {
|
||||
options.eventSources = [
|
||||
{
|
||||
className: 'customeventclass',
|
||||
events: eventArray
|
||||
}
|
||||
];
|
||||
options.eventRender = function(eventObj, eventElm) {
|
||||
expect(eventObj.title).toEqual('my event');
|
||||
expect(eventElm).toHaveClass('customeventclass');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('doesn\'t mutate the original array', function(done) {
|
||||
var origArray = eventArray;
|
||||
var origEvent = eventArray[0];
|
||||
options.events = eventArray;
|
||||
options.eventRender = function(eventObj, eventElm) {
|
||||
expect(origArray).toEqual(eventArray);
|
||||
expect(origEvent).toEqual(eventArray[0]);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,121 @@
|
||||
|
||||
describe('events as a function', function() {
|
||||
|
||||
var options;
|
||||
|
||||
beforeEach(function() {
|
||||
affix('#cal');
|
||||
options = {
|
||||
defaultView: 'month',
|
||||
defaultDate: '2014-05-01'
|
||||
};
|
||||
});
|
||||
|
||||
it('requests correctly when no timezone', function(done) {
|
||||
options.events = function(start, end, timezone, callback) {
|
||||
expect(moment.isMoment(start)).toEqual(true);
|
||||
expect(start.hasTime()).toEqual(false);
|
||||
expect(start.hasZone()).toEqual(false);
|
||||
expect(start.format()).toEqual('2014-04-27');
|
||||
expect(moment.isMoment(end)).toEqual(true);
|
||||
expect(end.hasTime()).toEqual(false);
|
||||
expect(end.hasZone()).toEqual(false);
|
||||
expect(end.format()).toEqual('2014-06-08');
|
||||
expect(timezone).toEqual(false);
|
||||
expect(typeof callback).toEqual('function');
|
||||
callback([]);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('requests correctly when local timezone', function(done) {
|
||||
options.timezone = 'local';
|
||||
options.events = function(start, end, timezone, callback) {
|
||||
expect(moment.isMoment(start)).toEqual(true);
|
||||
expect(start.hasTime()).toEqual(false);
|
||||
expect(start.hasZone()).toEqual(false);
|
||||
expect(start.format()).toEqual('2014-04-27');
|
||||
expect(moment.isMoment(end)).toEqual(true);
|
||||
expect(end.hasTime()).toEqual(false);
|
||||
expect(end.hasZone()).toEqual(false);
|
||||
expect(end.format()).toEqual('2014-06-08');
|
||||
expect(timezone).toEqual('local');
|
||||
expect(typeof callback).toEqual('function');
|
||||
callback([]);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('requests correctly when UTC timezone', function(done) {
|
||||
options.timezone = 'UTC';
|
||||
options.events = function(start, end, timezone, callback) {
|
||||
expect(moment.isMoment(start)).toEqual(true);
|
||||
expect(start.hasTime()).toEqual(false);
|
||||
expect(start.hasZone()).toEqual(false);
|
||||
expect(start.format()).toEqual('2014-04-27');
|
||||
expect(moment.isMoment(end)).toEqual(true);
|
||||
expect(end.hasTime()).toEqual(false);
|
||||
expect(end.hasZone()).toEqual(false);
|
||||
expect(end.format()).toEqual('2014-06-08');
|
||||
expect(timezone).toEqual('UTC');
|
||||
expect(typeof callback).toEqual('function');
|
||||
callback([]);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('requests correctly when custom timezone', function(done) {
|
||||
options.timezone = 'America/Chicago';
|
||||
options.events = function(start, end, timezone, callback) {
|
||||
expect(moment.isMoment(start)).toEqual(true);
|
||||
expect(start.hasTime()).toEqual(false);
|
||||
expect(start.hasZone()).toEqual(false);
|
||||
expect(start.format()).toEqual('2014-04-27');
|
||||
expect(moment.isMoment(end)).toEqual(true);
|
||||
expect(end.hasTime()).toEqual(false);
|
||||
expect(end.hasZone()).toEqual(false);
|
||||
expect(end.format()).toEqual('2014-06-08');
|
||||
expect(timezone).toEqual('America/Chicago');
|
||||
expect(typeof callback).toEqual('function');
|
||||
callback([]);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('requests correctly with event source extended form', function(done) {
|
||||
var eventSource = {
|
||||
className: 'customeventclass',
|
||||
events: function(start, end, timezone, callback) {
|
||||
expect(moment.isMoment(start)).toEqual(true);
|
||||
expect(start.hasTime()).toEqual(false);
|
||||
expect(start.hasZone()).toEqual(false);
|
||||
expect(start.format()).toEqual('2014-04-27');
|
||||
expect(moment.isMoment(end)).toEqual(true);
|
||||
expect(end.hasTime()).toEqual(false);
|
||||
expect(end.hasZone()).toEqual(false);
|
||||
expect(end.format()).toEqual('2014-06-08');
|
||||
expect(timezone).toEqual(false);
|
||||
expect(typeof callback).toEqual('function');
|
||||
callback([
|
||||
{
|
||||
title: 'event1',
|
||||
start: '2014-05-10'
|
||||
}
|
||||
]);
|
||||
}
|
||||
};
|
||||
spyOn(eventSource, 'events').and.callThrough();
|
||||
options.eventSources = [ eventSource ];
|
||||
options.eventRender = function(eventObj, eventElm) {
|
||||
expect(eventSource.events.calls.count()).toEqual(1);
|
||||
expect(eventElm).toHaveClass('customeventclass');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,117 @@
|
||||
|
||||
describe('events as a json feed', function() {
|
||||
|
||||
var options;
|
||||
var sampleResponse;
|
||||
|
||||
beforeEach(function() {
|
||||
jasmine.Ajax.install();
|
||||
affix('#cal');
|
||||
options = {
|
||||
defaultDate: '2014-05-01',
|
||||
defaultView: 'month'
|
||||
};
|
||||
sampleResponse = {
|
||||
status: 200,
|
||||
responseText: JSON.stringify([
|
||||
{
|
||||
title: 'my event',
|
||||
start: '2014-05-21'
|
||||
}
|
||||
])
|
||||
};
|
||||
});
|
||||
|
||||
it('requests correctly when no timezone', function() {
|
||||
options.events = 'my-feed.php';
|
||||
$('#cal').fullCalendar(options);
|
||||
var request = jasmine.Ajax.requests.mostRecent();
|
||||
expect(request.url).toMatch(/^my-feed\.php\?start=2014-04-27&end=2014-06-08&_=/);
|
||||
});
|
||||
|
||||
it('requests correctly when local timezone', function() {
|
||||
options.events = 'my-feed.php';
|
||||
options.timezone = 'local';
|
||||
$('#cal').fullCalendar(options);
|
||||
var request = jasmine.Ajax.requests.mostRecent();
|
||||
expect(request.url).toMatch(/^my-feed\.php\?start=2014-04-27&end=2014-06-08&_=/);
|
||||
});
|
||||
|
||||
it('requests correctly when UTC timezone', function() {
|
||||
options.events = 'my-feed.php';
|
||||
options.timezone = 'UTC';
|
||||
$('#cal').fullCalendar(options);
|
||||
var request = jasmine.Ajax.requests.mostRecent();
|
||||
expect(request.url).toMatch(/^my-feed\.php\?start=2014-04-27&end=2014-06-08&timezone=UTC&_=/);
|
||||
});
|
||||
|
||||
it('requests correctly when custom timezone', function() {
|
||||
options.events = 'my-feed.php';
|
||||
options.timezone = 'America/Chicago';
|
||||
$('#cal').fullCalendar(options);
|
||||
var request = jasmine.Ajax.requests.mostRecent();
|
||||
expect(request.url).toMatch(/^my-feed\.php\?start=2014-04-27&end=2014-06-08&timezone=America%2FChicago&_=/);
|
||||
});
|
||||
|
||||
it('requests correctly with event source extended form', function(done) {
|
||||
var request;
|
||||
var eventSource = {
|
||||
url: 'my-feed.php',
|
||||
className: 'customeventclass'
|
||||
};
|
||||
options.eventSources = [ eventSource ];
|
||||
options.timezone = 'America/Chicago';
|
||||
options.eventRender = function(eventObj, eventElm) {
|
||||
expect(request.url).toMatch(/^my-feed\.php\?start=2014-04-27&end=2014-06-08&timezone=America%2FChicago&_=/);
|
||||
expect(eventElm).toHaveClass('customeventclass');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
request.response(sampleResponse);
|
||||
});
|
||||
|
||||
it('accepts jQuery.ajax params', function(done) {
|
||||
var request;
|
||||
var eventSource = {
|
||||
url: 'my-feed.php',
|
||||
data: {
|
||||
customParam: 'yes'
|
||||
},
|
||||
success: function() { }
|
||||
};
|
||||
spyOn(eventSource, 'success').and.callThrough();
|
||||
options.eventSources = [ eventSource ];
|
||||
options.eventAfterAllRender = function() {
|
||||
expect(request.url).toMatch(/^my-feed\.php/);
|
||||
expect(request.url).toMatch(/[?&]customParam=yes/);
|
||||
expect(eventSource.success.calls.count()).toEqual(1);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
request.response(sampleResponse); // needed to trigger eventAfterAllRender (bad)
|
||||
});
|
||||
|
||||
it('accepts a dynamic data function', function(done) {
|
||||
var request;
|
||||
var eventSource = {
|
||||
url: 'my-feed.php',
|
||||
data: function() {
|
||||
return {
|
||||
customParam: 'heckyeah'
|
||||
};
|
||||
}
|
||||
};
|
||||
options.eventSources = [ eventSource ];
|
||||
options.eventAfterAllRender = function() {
|
||||
expect(request.url).toMatch(/^my-feed\.php/);
|
||||
expect(request.url).toMatch(/[?&]customParam=heckyeah/);
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
request = jasmine.Ajax.requests.mostRecent();
|
||||
request.response(sampleResponse); // needed to trigger eventAfterAllRender (bad)
|
||||
});
|
||||
|
||||
});
|
||||
@@ -0,0 +1,113 @@
|
||||
|
||||
describe('timezone', function() {
|
||||
|
||||
// NOTE: Only deals with the processing of *received* events.
|
||||
// Verification of a correct AJAX *request* is done in events-json-feed.js
|
||||
|
||||
var options;
|
||||
|
||||
beforeEach(function() {
|
||||
affix('#cal');
|
||||
options = {
|
||||
defaultView: 'month',
|
||||
defaultDate: '2014-05-01',
|
||||
events: [
|
||||
{
|
||||
id: '1',
|
||||
title: 'all day event',
|
||||
start: '2014-05-02'
|
||||
},
|
||||
{
|
||||
id: '2',
|
||||
title: 'timed event',
|
||||
start: '2014-05-10T12:00:00'
|
||||
},
|
||||
{
|
||||
id: '3',
|
||||
title: 'timed and zoned event',
|
||||
start: '2014-05-10T14:00:00+11:00'
|
||||
}
|
||||
]
|
||||
};
|
||||
});
|
||||
|
||||
it('receives events correctly when no timezone', function(done) {
|
||||
options.eventAfterAllRender = function() {
|
||||
var allDayEvent = $('#cal').fullCalendar('clientEvents', '1')[0];
|
||||
var timedEvent = $('#cal').fullCalendar('clientEvents', '2')[0];
|
||||
var zonedEvent = $('#cal').fullCalendar('clientEvents', '3')[0];
|
||||
expect(allDayEvent.start.hasZone()).toEqual(false);
|
||||
expect(allDayEvent.start.hasTime()).toEqual(false);
|
||||
expect(allDayEvent.start.format()).toEqual('2014-05-02');
|
||||
expect(timedEvent.start.hasZone()).toEqual(false);
|
||||
expect(timedEvent.start.hasTime()).toEqual(true);
|
||||
expect(timedEvent.start.format()).toEqual('2014-05-10T12:00:00');
|
||||
expect(zonedEvent.start.hasZone()).toEqual(true);
|
||||
expect(zonedEvent.start.hasTime()).toEqual(true);
|
||||
expect(zonedEvent.start.format()).toEqual('2014-05-10T14:00:00+11:00');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('receives events correctly when local timezone', function(done) {
|
||||
options.timezone = 'local';
|
||||
options.eventAfterAllRender = function() {
|
||||
var allDayEvent = $('#cal').fullCalendar('clientEvents', '1')[0];
|
||||
var timedEvent = $('#cal').fullCalendar('clientEvents', '2')[0];
|
||||
var zonedEvent = $('#cal').fullCalendar('clientEvents', '3')[0];
|
||||
expect(allDayEvent.start.hasZone()).toEqual(false);
|
||||
expect(allDayEvent.start.hasTime()).toEqual(false);
|
||||
expect(allDayEvent.start.format()).toEqual('2014-05-02');
|
||||
expect(timedEvent.start.hasZone()).toEqual(true);
|
||||
expect(timedEvent.start.hasTime()).toEqual(true);
|
||||
expect(timedEvent.start.zone()).toEqual(new Date(2014, 4, 10, 12).getTimezoneOffset());
|
||||
expect(zonedEvent.start.hasZone()).toEqual(true);
|
||||
expect(zonedEvent.start.hasTime()).toEqual(true);
|
||||
expect(zonedEvent.start.zone()).toEqual(new Date('Sat May 10 2014 14:00:00 GMT+1100').getTimezoneOffset());
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('receives events correctly when UTC timezone', function(done) {
|
||||
options.timezone = 'UTC';
|
||||
options.eventAfterAllRender = function() {
|
||||
var allDayEvent = $('#cal').fullCalendar('clientEvents', '1')[0];
|
||||
var timedEvent = $('#cal').fullCalendar('clientEvents', '2')[0];
|
||||
var zonedEvent = $('#cal').fullCalendar('clientEvents', '3')[0];
|
||||
expect(allDayEvent.start.hasZone()).toEqual(false);
|
||||
expect(allDayEvent.start.hasTime()).toEqual(false);
|
||||
expect(allDayEvent.start.format()).toEqual('2014-05-02');
|
||||
expect(timedEvent.start.hasZone()).toEqual(true);
|
||||
expect(timedEvent.start.hasTime()).toEqual(true);
|
||||
expect(timedEvent.start.format()).toEqual('2014-05-10T12:00:00+00:00');
|
||||
expect(zonedEvent.start.hasZone()).toEqual(true);
|
||||
expect(zonedEvent.start.hasTime()).toEqual(true);
|
||||
expect(zonedEvent.start.format()).toEqual('2014-05-10T03:00:00+00:00');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
it('receives events correctly when custom timezone', function(done) {
|
||||
options.timezone = 'America/Chicago';
|
||||
options.eventAfterAllRender = function() {
|
||||
var allDayEvent = $('#cal').fullCalendar('clientEvents', '1')[0];
|
||||
var timedEvent = $('#cal').fullCalendar('clientEvents', '2')[0];
|
||||
var zonedEvent = $('#cal').fullCalendar('clientEvents', '3')[0];
|
||||
expect(allDayEvent.start.hasZone()).toEqual(false);
|
||||
expect(allDayEvent.start.hasTime()).toEqual(false);
|
||||
expect(allDayEvent.start.format()).toEqual('2014-05-02');
|
||||
expect(timedEvent.start.hasZone()).toEqual(false);
|
||||
expect(timedEvent.start.hasTime()).toEqual(true);
|
||||
expect(timedEvent.start.format()).toEqual('2014-05-10T12:00:00');
|
||||
expect(zonedEvent.start.hasZone()).toEqual(true);
|
||||
expect(zonedEvent.start.hasTime()).toEqual(true);
|
||||
expect(zonedEvent.start.format()).toEqual('2014-05-10T14:00:00+11:00');
|
||||
done();
|
||||
};
|
||||
$('#cal').fullCalendar(options);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in New Issue
Block a user