소스 검색

fix for async refetchEvent source situation. tests (including 1 disabled)

Adam Shaw 9 년 전
부모
커밋
3e8ca9b196
2개의 변경된 파일74개의 추가작업 그리고 6개의 파일을 삭제
  1. 2 2
      src/EventManager.js
  2. 72 4
      tests/automated/refetchEventSources.js

+ 2 - 2
src/EventManager.js

@@ -39,7 +39,7 @@ function EventManager(options) { // assumed to be a calendar
 	var sources = [ stickySource ];
 	var rangeStart, rangeEnd;
 	var currentFetchID = 0;
-	var pendingSourceCnt = 0;
+	var pendingSourceCnt = 0; // for the current fetchID
 	var cache = []; // holds events that have already been expanded
 
 
@@ -86,7 +86,7 @@ function EventManager(options) { // assumed to be a calendar
 			cache = excludeEventsBySources(cache, specificSources);
 		}
 
-		pendingSourceCnt += len;
+		pendingSourceCnt = len;
 		for (i = 0; i < len; i++) {
 			fetchEventSource(specificSources[i], fetchID);
 		}

+ 72 - 4
tests/automated/refetchEventSources.js

@@ -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);
+			}
 		};
 	}
 });