|
|
@@ -5,6 +5,7 @@ ddescribe('refetchEventSources', function() {
|
|
|
// used by createEventGenerator
|
|
|
var eventCount;
|
|
|
var fetchId;
|
|
|
+ var fetchDelay;
|
|
|
|
|
|
beforeEach(function() {
|
|
|
affix('#cal');
|
|
|
@@ -13,7 +14,8 @@ ddescribe('refetchEventSources', function() {
|
|
|
fetchId = 7;
|
|
|
options = {
|
|
|
now: '2015-08-07',
|
|
|
- defaultView: 'agendaWeek',
|
|
|
+ defaultView: 'agendaDay',
|
|
|
+ scrollTime: '00:00',
|
|
|
eventSources: [
|
|
|
{
|
|
|
events: createEventGenerator('source1-'),
|
|
|
@@ -25,7 +27,6 @@ ddescribe('refetchEventSources', function() {
|
|
|
},
|
|
|
{
|
|
|
events: createEventGenerator('source3-'),
|
|
|
- rendering: 'background',
|
|
|
color: 'green'
|
|
|
}
|
|
|
]
|
|
|
@@ -99,6 +100,66 @@ ddescribe('refetchEventSources', function() {
|
|
|
});
|
|
|
});
|
|
|
|
|
|
+ describe('when called while initial fetch is still pending', function() {
|
|
|
+ it('rerenders the new events', function(done) {
|
|
|
+
|
|
|
+ options.eventAfterAllRender = function() {
|
|
|
+
|
|
|
+ // events from old fetch were cleared
|
|
|
+ expect($('.source1-7').length).toEqual(0);
|
|
|
+ expect($('.source3-7').length).toEqual(0);
|
|
|
+
|
|
|
+ // events from new fetch were rendered
|
|
|
+ expect($('.source1-8').length).toEqual(2);
|
|
|
+ expect($('.source3-8').length).toEqual(2);
|
|
|
+
|
|
|
+ done();
|
|
|
+ };
|
|
|
+
|
|
|
+ fetchDelay = 100;
|
|
|
+ calendarEl.fullCalendar(options);
|
|
|
+
|
|
|
+ var allEventSources = calendarEl.fullCalendar('getEventSources');
|
|
|
+ var greenEventSources = $.grep(allEventSources, function(eventSource) {
|
|
|
+ return eventSource.color === 'green';
|
|
|
+ });
|
|
|
+
|
|
|
+ // increase the number of events for the refetched sources
|
|
|
+ eventCount = 2;
|
|
|
+ fetchId = 8;
|
|
|
+
|
|
|
+ calendarEl.fullCalendar('refetchEventSources', greenEventSources);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+ describe('when called while initial fetch is still pending', function() {
|
|
|
+ // TODO: once this is fixed, merge with above test
|
|
|
+ xit('maintains old events', function(done) {
|
|
|
+
|
|
|
+ options.eventAfterAllRender = function() {
|
|
|
+
|
|
|
+ // events from unaffected sources remain
|
|
|
+ expect($('.source2-7').length).toEqual(1);
|
|
|
+
|
|
|
+ done();
|
|
|
+ };
|
|
|
+
|
|
|
+ fetchDelay = 100;
|
|
|
+ calendarEl.fullCalendar(options);
|
|
|
+
|
|
|
+ var allEventSources = calendarEl.fullCalendar('getEventSources');
|
|
|
+ var greenEventSources = $.grep(allEventSources, function(eventSource) {
|
|
|
+ return eventSource.color === 'green';
|
|
|
+ });
|
|
|
+
|
|
|
+ // increase the number of events for the refetched sources
|
|
|
+ eventCount = 2;
|
|
|
+ fetchId = 8;
|
|
|
+
|
|
|
+ calendarEl.fullCalendar('refetchEventSources', greenEventSources);
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
function createEventGenerator(classNamePrefix) {
|
|
|
return function(start, end, timezone, callback) {
|
|
|
var events = [];
|
|
|
@@ -108,11 +169,18 @@ ddescribe('refetchEventSources', function() {
|
|
|
start: '2015-08-07T02:00:00',
|
|
|
end: '2015-08-07T03:00:00',
|
|
|
className: classNamePrefix + fetchId,
|
|
|
- title: classNamePrefix // also make it the title
|
|
|
+ title: classNamePrefix + fetchId // also make it the title
|
|
|
});
|
|
|
}
|
|
|
|
|
|
- callback(events);
|
|
|
+ if (fetchDelay) {
|
|
|
+ setTimeout(function() {
|
|
|
+ callback(events);
|
|
|
+ }, fetchDelay);
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ callback(events);
|
|
|
+ }
|
|
|
};
|
|
|
}
|
|
|
});
|