浏览代码

more automated tests

Adam Shaw 11 年之前
父节点
当前提交
fbb91d69fe

+ 67 - 1
tests/automated/constraint.js

@@ -28,6 +28,26 @@ describe('event constraint', function() {
 					} ];
 					testEventDrag(options, '2014-11-10T04:00:00', true, done);
 				});
+
+				describe('when in month view with timed event', function() {
+					it('allows a drag, respects time of day', function(done) {
+						options.defaultView = 'month';
+						options.events = [ {
+							start: '2014-11-10T05:00:00',
+							end: '2014-11-10T07:00:00',
+							constraint: {
+								start: '04:00',
+								end: '20:00'
+							}
+						} ];
+						testEventDrag(options, '2014-11-14', true, function() {
+							var event = $('#cal').fullCalendar('clientEvents')[0];
+							expect(event.start).toEqualMoment('2014-11-14T05:00:00');
+							expect(event.end).toEqualMoment('2014-11-14T07:00:00');
+							done();
+						});
+					});
+				});
 			});
 
 			describe('to the start of the constraint range', function() {
@@ -190,7 +210,6 @@ describe('event constraint', function() {
 				});
 			});
 
-
 			describe('intersecting the constraint start', function() {
 				describe('with no timezone', function() {
 					it('does not allow a drag', function(done) {
@@ -519,6 +538,37 @@ describe('event constraint', function() {
 					testEventDrag(options, '2014-11-13T04:00:00', false, done);
 				});
 			});
+
+			describe('when the event ID constraint matches no events', function() {
+				it('does not allow a drag', function(done) {
+					options.events = [
+						{
+							start: '2014-11-12T01:00:00',
+							end: '2014-11-12T03:00:00',
+							constraint: 'yo'
+						}
+					];
+					testEventDrag(options, '2014-11-13T04:00:00', false, done);
+				});
+			});
+
+			describe('when in month view', function() {
+				beforeEach(function() {
+					options.defaultView = 'month';
+				});
+				describe('when the event ID constraint matches no events', function() {
+					it('does not allow a drag', function(done) {
+						options.events = [
+							{
+								start: '2014-11-12',
+								end: '2014-11-12',
+								constraint: 'yo'
+							}
+						];
+						testEventDrag(options, '2014-11-13', false, done);
+					});
+				});
+			});
 		});
 	});
 });
@@ -727,5 +777,21 @@ describe('selectConstraint', function() {
 				testSelection(options, '03:00', '2014-11-12T06:00:00', false, done);
 			});
 		});
+
+		describe('when event ID does not match any events', function() {
+			describe('when in agendaWeek view', function() {
+				it('does not allow a selection', function(done) {
+					options.selectConstraint = 'yooo';
+					testSelection(options, '03:00', '2014-11-12T06:00:00', false, done);
+				});
+			});
+			describe('when in month view', function() {
+				it('does not allow a selection', function(done) {
+					options.defaultView = 'month';
+					options.selectConstraint = 'yooo';
+					testSelection(options, null, '2014-11-15', false, done);
+				});
+			});
+		});
 	});
 });

+ 10 - 0
tests/automated/eventLimit-popover.js

@@ -69,6 +69,16 @@ describe('eventLimit popover', function() {
 			var diff = Math.abs(popoverTop - rowTop);
 			expect(diff).toBeLessThan(2);
 		});
+
+		it('works with background events', function() {
+			options.events.push({
+				start: '2014-07-29',
+				rendering: 'background'
+			});
+			init();
+			expect($('.fc-more-popover .fc-event').length).toBeGreaterThan(1);
+			expect($('.fc-more-popover .fc-bgevent').length).toBe(0);
+		});
 	});
 
 	[ 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {

+ 293 - 0
tests/automated/eventRender.js

@@ -0,0 +1,293 @@
+describe('eventRender', function() {
+	var options;
+
+	beforeEach(function() {
+		options = {
+			defaultDate: '2014-11-12',
+			scrollTime: '00:00:00'
+		};
+		affix('#cal');
+	});
+
+	$.each({
+		'month': '.fc-day-grid',
+		'agendaWeek': '.fc-time-grid'
+	}, function(viewName, gridSelector) {
+		describe('when in ' + viewName + ' view', function() {
+			beforeEach(function() {
+				options.defaultView = viewName;
+			});
+			describe('with foreground event', function() {
+				it('receives correct args AND can modify the element', function(done) {
+					options.events = [ {
+						title: 'my event',
+						start: '2014-11-12T09:00:00'
+					} ];
+					options.eventRender = function(event, element, view) {
+						expect(typeof event).toBe('object');
+						expect(event.rendering).toBeUndefined();
+						expect(event.start).toBeDefined();
+						expect(typeof element).toBe('object');
+						expect(element.length).toBe(1);
+						expect(typeof view).toBe('object');
+						element.css('font-size', '20px');
+					};
+					options.eventAfterAllRender = function() {
+						expect($(gridSelector).find('.fc-event').css('font-size')).toBe('20px');
+						expect(options.eventRender).toHaveBeenCalled();
+						done();
+					};
+					spyOn(options, 'eventRender').and.callThrough();
+					$('#cal').fullCalendar(options);
+				});
+			});
+		});
+	});
+
+	describe('when in month view', function() {
+		beforeEach(function() {
+			options.defaultView = 'month';
+		});
+
+		describe('with a foreground event', function() {
+			beforeEach(function() {
+				options.events = [ {
+					title: 'my event',
+					start: '2014-11-12'
+				} ];
+			});
+			it('can return a new element', function(done) {
+				options.eventRender = function(event, element, view) {
+					return $('<div class="fc-event sup" style="background-color:green">sup g</div>');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .sup').length).toBe(1);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('can return false and cancel rendering', function(done) {
+				options.eventRender = function(event, element, view) {
+					return false;
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .fc-event').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+		});
+
+		describe('with an all-day background event', function() {
+			beforeEach(function() {
+				options.events = [ {
+					title: 'my event',
+					start: '2014-11-12',
+					rendering: 'background'
+				} ];
+			});
+			it('receives correct args AND can modify the element', function(done) {
+				options.eventRender = function(event, element, view) {
+					expect(typeof event).toBe('object');
+					expect(event.rendering).toBe('background');
+					expect(event.start).toBeDefined();
+					expect(typeof element).toBe('object');
+					expect(element.length).toBe(1);
+					expect(typeof view).toBe('object');
+					element.css('font-size', '20px');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .fc-bgevent').css('font-size')).toBe('20px');
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('can return a new element', function(done) {
+				options.eventRender = function(event, element, view) {
+					return $('<td class="sup" style="background-color:green">sup g</td>');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .sup').length).toBe(1);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('won\'t rendering when returning a new element of the wrong type', function(done) {
+				options.eventRender = function(event, element, view) {
+					return $('<div class="sup" style="background-color:green">sup g</div>');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .sup').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('can return false and cancel rendering', function(done) {
+				options.eventRender = function(event, element, view) {
+					return false;
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .fc-bgevent').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+		});
+
+		describe('with a timed background event', function() { // not exactly related to eventRender!
+			beforeEach(function() {
+				options.events = [ {
+					title: 'my event',
+					start: '2014-11-12T01:00:00',
+					rendering: 'background'
+				} ];
+			});
+			it('won\'t render or call eventRender', function(done) {
+				options.eventRender = function(event, element, view) { };
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .fc-bgevent').length).toBe(0);
+					expect(options.eventRender).not.toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+		});
+	});
+
+	describe('when in agendaWeek view', function() {
+		beforeEach(function() {
+			options.defaultView = 'agendaWeek';
+		});
+
+		describe('with a foreground event', function() {
+			beforeEach(function() {
+				options.events = [ {
+					title: 'my event',
+					start: '2014-11-12T01:00:00'
+				} ];
+			});
+			it('can return a new element', function(done) {
+				options.eventRender = function(event, element, view) {
+					return $('<div class="fc-event sup" style="background-color:green">sup g</div>');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-time-grid .sup').length).toBe(1);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('can return false and cancel rendering', function(done) {
+				options.eventRender = function(event, element, view) {
+					return false;
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-time-grid .fc-event').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+		});
+
+		describe('with a timed background event', function() {
+			beforeEach(function() {
+				options.events = [ {
+					title: 'my event',
+					start: '2014-11-12T01:00:00',
+					rendering: 'background'
+				} ];
+			});
+			it('receives correct args AND can modify the element', function(done) {
+				options.eventRender = function(event, element, view) {
+					expect(typeof event).toBe('object');
+					expect(event.rendering).toBe('background');
+					expect(event.start).toBeDefined();
+					expect(typeof element).toBe('object');
+					expect(element.length).toBe(1);
+					expect(typeof view).toBe('object');
+					element.css('font-size', '20px');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-time-grid .fc-bgevent').css('font-size')).toBe('20px');
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('can return a new element', function(done) {
+				options.eventRender = function(event, element, view) {
+					return $('<div class="fc-bgevent sup" style="background-color:green">sup g</div>');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-time-grid .sup').length).toBe(1);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('won\'t rendering when returning a new element of the wrong type', function(done) {
+				options.eventRender = function(event, element, view) {
+					return $('<p class="fc-bgevent sup" style="background-color:green">sup g</p>');
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-time-grid .sup').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+			it('can return false and cancel rendering', function(done) {
+				options.eventRender = function(event, element, view) {
+					return false;
+				};
+				options.eventAfterAllRender = function() {
+					expect($('.fc-time-grid .fc-bgevent').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+		});
+
+		describe('with an all-day background event', function() { // not exactly related to eventRender!
+			beforeEach(function() {
+				options.events = [ {
+					title: 'my event',
+					start: '2014-11-12',
+					rendering: 'background'
+				} ];
+			});
+			it('will render in the all-day slot', function(done) {
+				options.eventRender = function(event, element, view) { };
+				options.eventAfterAllRender = function() {
+					expect($('.fc-day-grid .fc-bgevent').length).toBe(1);
+					expect($('.fc-time-grid .fc-bgevent').length).toBe(0);
+					expect(options.eventRender).toHaveBeenCalled();
+					done();
+				};
+				spyOn(options, 'eventRender').and.callThrough();
+				$('#cal').fullCalendar(options);
+			});
+		});
+	});
+});

+ 18 - 0
tests/automated/overlap.js

@@ -232,6 +232,24 @@ describe('event overlap', function() {
 						testEventDrag(options, '2014-11-08', false, done, 'event-a');
 					});
 				});
+				describe('with timed subject and all-day other', function() {
+					it('does not allow dragging', function(done) {
+						options.events = [
+							{
+								title: 'Event A',
+								className: 'event-a',
+								start: '2014-11-04'
+							},
+							{
+								title: 'Event B',
+								className: 'event-b',
+								start: '2014-11-07T05:00:00',
+								overlap: false
+							}
+						];
+						testEventDrag(options, '2014-11-04', false, done, 'event-b');
+					});
+				});
 			});
 		});
 

+ 8 - 1
tests/lib/dnd-resize-utils.js

@@ -56,7 +56,14 @@ function testEventDrag(options, dropDate, expectSuccess, callback, eventClassNam
 						else {
 							eventObj = calendar.clientEvents()[0];
 						}
-						successfulDrop = eventObj.start.format() == dropDate.format();
+
+						if (dropDate.hasTime()) { // dropped on a slot
+							successfulDrop = eventObj.start.format() == dropDate.format(); // compare exact times
+						}
+						else { // dropped on a whole day
+							// only compare days
+							successfulDrop = eventObj.start.format('YYYY-MM-DD') == dropDate.format('YYYY-MM-DD');
+						}
 
 						expect(allowed).toBe(successfulDrop);
 						expect(allowed).toBe(expectSuccess);