소스 검색

more automated tests related to new code

Adam Shaw 11 년 전
부모
커밋
7a81b5b2d0

+ 215 - 1
tests/automated/DayGrid-events.js

@@ -4,11 +4,167 @@ describe('DayGrid event rendering', function() {
 	beforeEach(function() {
 		affix('#cal');
 		options = {
-			defaultDate: '2014-08-01',
+			defaultDate: '2014-08-01', // 2014-07-27 - 2014-10-07 (excl)
 			defaultView: 'month'
 		};
 	});
 
+	describe('when LTR', function() {
+		initMonthTesting(false);
+	});
+	describe('when RTL', function() {
+		initMonthTesting(true);
+	});
+
+	function initMonthTesting(isRTL) {
+
+		it('correctly renders an event starting before view\'s start', function() {
+			options.events = [
+				{ start: '2014-07-26', end: '2014-07-30' }
+			];
+			testSeg({
+				firstCol: 0,
+				lastCol: 2,
+				isStart: false,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event starting at view\'s start', function() {
+			options.events = [
+				{ start: '2014-07-27', end: '2014-07-29' }
+			];
+			testSeg({
+				firstCol: 0,
+				lastCol: 1,
+				isStart: true,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event starting after view\'s start', function() {
+			options.events = [
+				{ start: '2014-08-01', end: '2014-08-02' }
+			];
+			testSeg({
+				firstCol: 5,
+				lastCol: 5,
+				isStart: true,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event starting on a hidden day at week start', function() {
+			options.weekends = false;
+			options.events = [
+				{ start: '2014-07-27', end: '2014-07-30' }
+			];
+			testSeg({
+				firstCol: 0,
+				lastCol: 1,
+				isStart: false,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event starting on a hidden day in middle of week', function() {
+			options.hiddenDays = [ 2 ]; // hide Tues
+			options.events = [
+				{ start: '2014-07-29', end: '2014-08-01' }
+			];
+			testSeg({
+				firstCol: 2,
+				lastCol: 3,
+				isStart: false,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event ending before view\'s end', function() {
+			options.events = [
+				{ start: '2014-09-02', end: '2014-09-05' }
+			];
+			testSeg({
+				row: 5,
+				firstCol: 2,
+				lastCol: 4,
+				isStart: true,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event ending at view\'s end', function() {
+			options.events = [
+				{ start: '2014-09-04', end: '2014-09-07' }
+			];
+			testSeg({
+				row: 5,
+				firstCol: 4,
+				lastCol: 6,
+				isStart: true,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event ending after view\'s end', function() {
+			options.events = [
+				{ start: '2014-09-04', end: '2014-09-08' }
+			];
+			testSeg({
+				row: 5,
+				firstCol: 4,
+				lastCol: 6,
+				isStart: true,
+				isEnd: false
+			});
+		});
+
+		it('correctly renders an event ending at a week\'s end', function() {
+			options.events = [
+				{ start: '2014-08-28', end: '2014-08-31' }
+			];
+			testSeg({
+				row: 4,
+				firstCol: 4,
+				lastCol: 6,
+				isStart: true,
+				isEnd: true
+			});
+		});
+
+		it('correctly renders an event ending on a hidden day at week end', function() {
+			options.weekends = false;
+			options.events = [
+				{ start: '2014-07-30', end: '2014-08-03' }
+			];
+			testSeg({
+				firstCol: 2,
+				lastCol: 4,
+				isStart: true,
+				isEnd: false
+			});
+		});
+
+		it('correctly renders an event ending on a hidden day in middle of week', function() {
+			options.hiddenDays = [ 4 ]; // Thurs
+			options.events = [
+				{ start: '2014-07-28', end: '2014-08-01' }
+			];
+			testSeg({
+				firstCol: 1,
+				lastCol: 3,
+				isStart: true,
+				isEnd: false
+			});
+		});
+
+		function testSeg(testSegOptions) {
+			options.isRTL = isRTL;
+			$('#cal').fullCalendar(options);
+			directionallyTestSeg(testSegOptions, isRTL);
+		}
+	}
+
 	it('rendering of events across weeks stays consistent', function() {
 		options.events = [
 			{
@@ -55,4 +211,62 @@ describe('DayGrid event rendering', function() {
 		var seg = $('.fc-event');
 		expect(seg).toHaveAttr('href');
 	});
+
+
+	/*
+	opts:
+		- el (optional)
+		- row (optional)
+		- firstCol
+		- lastCol
+		- isStart
+		- isEnd
+	*/
+	function directionallyTestSeg(opts, isRTL) {
+		var el = $(opts.el || '.fc-event:first');
+
+		var row = opts.row || 0;
+		var rowTds = $('.fc-day-grid .fc-row:eq(' + row + ') .fc-day');
+		expect(rowTds.length).toBeGreaterThan(1);
+
+		var leftCol;
+		var rightCol;
+		if (isRTL) {
+			leftCol = rowTds.length - opts.lastCol - 1;
+			rightCol = rowTds.length - opts.firstCol - 1;
+		}
+		else {
+			leftCol = opts.firstCol;
+			rightCol = opts.lastCol;
+		}
+
+		var col, td;
+
+		for (col = leftCol; col <= rightCol; col++) {
+			td = rowTds.eq(col);
+			expect(el).toIntersectWith(td);
+		}
+
+		for (col = 0; col < rowTds.length; col++) {
+			if (col < leftCol || col > rightCol) {
+				td = rowTds.eq(col);
+				expect(el).not.toIntersectWith(td);
+			}
+		}
+
+		if (opts.isStart) {
+			expect(el).toHaveClass('fc-start');
+		}
+		else {
+			expect(el).not.toHaveClass('fc-start');
+		}
+
+		if (opts.isEnd) {
+			expect(el).toHaveClass('fc-end');
+		}
+		else {
+			expect(el).not.toHaveClass('fc-end');
+		}
+	}
+
 });

+ 59 - 0
tests/automated/columnFormat.js

@@ -112,4 +112,63 @@ describe('columnFormat', function() {
             };
         });
     });
+
+    describe('using custom views', function() {
+
+        it('multi-year default only displays day-of-week', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiYear: {
+                        type: 'basic',
+                        duration: { years: 2 }
+                    }
+                },
+                defaultView: 'multiYear',
+                defaultDate: '2014-12-25'
+            });
+            expect($('.fc-day-header:first')).toHaveText('Sun');
+        });
+
+        it('multi-month default only displays day-of-week', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiMonth: {
+                        type: 'basic',
+                        duration: { months: 2 }
+                    }
+                },
+                defaultView: 'multiMonth',
+                defaultDate: '2014-12-25'
+            });
+            expect($('.fc-day-header:first')).toHaveText('Sun');
+        });
+
+        it('multi-week default only displays day-of-week', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiWeek: {
+                        type: 'basic',
+                        duration: { weeks: 2 }
+                    }
+                },
+                defaultView: 'multiWeek',
+                defaultDate: '2014-12-25'
+            });
+            expect($('.fc-day-header:first')).toHaveText('Sun');
+        });
+
+        it('multi-day default displays short full date', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiDay: {
+                        type: 'basic',
+                        duration: { days: 2 }
+                    }
+                },
+                defaultView: 'multiDay',
+                defaultDate: '2014-12-25'
+            });
+            expect($('.fc-day-header:first')).toHaveText('Thu 12/25');
+        });
+    });
 });

+ 51 - 0
tests/automated/destroy.js

@@ -24,4 +24,55 @@ describe('destroy', function() {
 		});
 	});
 
+	[ 'month', 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
+
+		describe('when in ' + viewName + ' view', function() {
+			var options;
+
+			beforeEach(function() {
+				options = {
+					defaultView: viewName,
+					defaultDate: '2014-12-01',
+					droppable: true, // likely to attach document handler
+					events: [
+						{ title: 'event1', start: '2014-12-01' }
+					]
+				};
+			});
+
+			it('leaves no handlers attached to DOM', function(done) {
+				var origDocCnt = countHandlers(document);
+				var origElCnt = countHandlers('#cal');
+
+				$('#cal').fullCalendar(options);
+
+				setTimeout(function() { // in case there are delayed attached handlers
+
+					$('#cal').fullCalendar('destroy');
+
+					expect(countHandlers(document)).toBe(origDocCnt);
+					expect(countHandlers('#cal')).toBe(origElCnt);
+
+					done();
+				}, 0);
+			});
+		});
+	});
+
+
+	function countHandlers(el) {
+		var hash = getAllHandlers(el);
+		var cnt = 0;
+
+		$.each(hash, function(name, handlers) {
+			cnt += handlers.length;
+		});
+
+		return cnt;
+	}
+
+	function getAllHandlers(el) {
+		return $._data($(el)[0], 'events') || {};
+	}
+
 });

+ 4 - 2
tests/automated/eventLimitClick.js

@@ -48,7 +48,8 @@ describe('eventLimitClick', function() { // simulate a click
 			$('#cal').fullCalendar(options);
 			$('.fc-more').simulate('click');
 			var view = $('#cal').fullCalendar('getView');
-			expect(view.name).toBe('basicWeek');
+			expect(view.name).toBe('basicWeek'); // .name should be deprecated
+			expect(view.type).toBe('basicWeek');
 		});
 
 		it('should go to agendaWeek if it is one of the available views', function() {
@@ -60,7 +61,8 @@ describe('eventLimitClick', function() { // simulate a click
 			$('#cal').fullCalendar(options);
 			$('.fc-more').simulate('click');
 			var view = $('#cal').fullCalendar('getView');
-			expect(view.name).toBe('agendaWeek');
+			expect(view.name).toBe('agendaWeek'); // .name should be deprecated
+			expect(view.type).toBe('agendaWeek');
 		});
 	});
 

+ 17 - 0
tests/automated/moment-construct.js

@@ -80,6 +80,7 @@ function testDefaultProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 
 		it('assumes first-of-month and ambiguous time when no date-of-month', function() {
@@ -87,6 +88,7 @@ function testDefaultProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 1, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 	});
 
@@ -146,6 +148,7 @@ function testDefaultProcessing(construct) {
 			expect(newMoment.toArray()).toEqual([ 2014, 4, 28, 0, 0, 0, 0 ]);
 			expect(newMoment.hasTime()).toBe(true);
 			expect(newMoment.hasZone()).toBe(false);
+			expect(newMoment.zone()).toBe(0);
 		});
 
 		it('remains ambiguously-timed', function() {
@@ -154,6 +157,7 @@ function testDefaultProcessing(construct) {
 			expect(newMoment.toArray()).toEqual([ 2014, 4, 28, 0, 0, 0, 0 ]);
 			expect(newMoment.hasTime()).toBe(false);
 			expect(newMoment.hasZone()).toBe(false);
+			expect(newMoment.zone()).toBe(0);
 		});
 	});
 
@@ -229,6 +233,7 @@ function testForcedLocalProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 
 		it('assumes first-of-month and ambiguous time when no date-of-month', function() {
@@ -236,6 +241,7 @@ function testForcedLocalProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 1, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 	});
 
@@ -305,6 +311,7 @@ function testForcedLocalProcessing(construct) {
 			expect(newMoment.toArray()).toEqual([ 2014, 4, 28, 0, 0, 0, 0 ]);
 			expect(newMoment.hasTime()).toBe(false);
 			expect(newMoment.hasZone()).toBe(false);
+			expect(newMoment.zone()).toBe(0);
 		});
 	});
 
@@ -380,6 +387,7 @@ function testForcedUTCProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 
 		it('assumes first-of-month and ambiguous time when no date-of-month', function() {
@@ -387,6 +395,7 @@ function testForcedUTCProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 1, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 	});
 
@@ -451,6 +460,7 @@ function testForcedUTCProcessing(construct) {
 			expect(newMoment.toArray()).toEqual([ 2014, 4, 28, 0, 0, 0, 0 ]);
 			expect(newMoment.hasTime()).toBe(false);
 			expect(newMoment.hasZone()).toBe(false);
+			expect(newMoment.zone()).toBe(0);
 		});
 	});
 
@@ -517,6 +527,7 @@ function testLiteralProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 11, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(true);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 
 		it('accepts an ambiguous time', function() {
@@ -524,6 +535,7 @@ function testLiteralProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 
 		it('assumes first-of-month and ambiguous time when no date-of-month', function() {
@@ -531,6 +543,7 @@ function testLiteralProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 1, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(false);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 	});
 
@@ -566,6 +579,7 @@ function testLiteralProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 11, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(true);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 
 		it('is ambiguously-zoned and has a time even when no hours/minutes/seconds', function() {
@@ -574,6 +588,7 @@ function testLiteralProcessing(construct) {
 			expect(mom.toArray()).toEqual([ 2014, 5, 8, 0, 0, 0, 0 ]);
 			expect(mom.hasTime()).toBe(true);
 			expect(mom.hasZone()).toBe(false);
+			expect(mom.zone()).toBe(0);
 		});
 	});
 
@@ -585,6 +600,7 @@ function testLiteralProcessing(construct) {
 			expect(newMoment.toArray()).toEqual([ 2014, 4, 28, 0, 0, 0, 0 ]);
 			expect(newMoment.hasTime()).toBe(true);
 			expect(newMoment.hasZone()).toBe(false);
+			expect(newMoment.zone()).toBe(0);
 		});
 
 		it('remains ambiguously-timed', function() {
@@ -593,6 +609,7 @@ function testLiteralProcessing(construct) {
 			expect(newMoment.toArray()).toEqual([ 2014, 4, 28, 0, 0, 0, 0 ]);
 			expect(newMoment.hasTime()).toBe(false);
 			expect(newMoment.hasZone()).toBe(false);
+			expect(newMoment.zone()).toBe(0);
 		});
 	});
 

+ 30 - 0
tests/automated/timeFormat.js

@@ -65,4 +65,34 @@ describe('timeFormat', function() {
 			expect(getRenderedEventTime()).toBe('153:00:00 - 175:00:00');
 		});
 	});
+
+	describe('when in multi-day custom basic view', function() {
+
+		beforeEach(function() {
+			options.views = {
+				basicTwoDay: {
+					type: 'basic',
+					duration: { days: 2 }
+				}
+			};
+			options.defaultView = 'basicTwoDay';
+		});
+
+		it('defaults to no end time', function() {
+			$('#cal').fullCalendar(options);
+			expect(getRenderedEventTime()).toBe('3p');
+		});
+	});
+
+	describe('when in basicDay view', function() {
+
+		beforeEach(function() {
+			options.defaultView = 'basicDay';
+		});
+
+		it('defaults to showing the end time', function() {
+			$('#cal').fullCalendar(options);
+			expect(getRenderedEventTime()).toBe('3p - 5p');
+		});
+	});
 });

+ 63 - 0
tests/automated/titleFormat.js

@@ -97,4 +97,67 @@ describe('titleFormat', function() {
             };
         });
     });
+
+    describe('using custom views', function() {
+
+        it('multi-year default only displays year', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiYear: {
+                        type: 'basic',
+                        duration: { years: 2 }
+                    }
+                },
+                defaultView: 'multiYear',
+                defaultDate: '2014-12-25',
+                titleRangeSeparator: ' - '
+            });
+            expect($('h2')).toHaveText('2014 - 2015');
+        });
+
+        it('multi-month default only displays month/year', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiMonth: {
+                        type: 'basic',
+                        duration: { months: 2 }
+                    }
+                },
+                defaultView: 'multiMonth',
+                defaultDate: '2014-12-25',
+                titleRangeSeparator: ' - '
+            });
+            expect($('h2')).toHaveText('December 2014 - January 2015');
+        });
+
+        it('multi-week default displays short full date', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiWeek: {
+                        type: 'basic',
+                        duration: { weeks: 2 }
+                    }
+                },
+                defaultView: 'multiWeek',
+                defaultDate: '2014-12-25',
+                titleRangeSeparator: ' - '
+            });
+            expect($('h2')).toHaveText('Dec 21, 2014 - Jan 3, 2015');
+        });
+
+        it('multi-day default displays short full date', function() {
+            $('#cal').fullCalendar({
+                views: {
+                    multiDay: {
+                        type: 'basic',
+                        duration: { days: 2 }
+                    }
+                },
+                defaultView: 'multiDay',
+                defaultDate: '2014-12-25',
+                titleRangeSeparator: ' - '
+            });
+            expect($('h2')).toHaveText('Dec 25 - 26, 2014');
+        });
+    });
 });

+ 56 - 0
tests/automated/unselectAuto.js

@@ -0,0 +1,56 @@
+
+describe('unselectAuto', function() {
+	var options;
+
+	beforeEach(function() {
+		options = {
+			selectable: true,
+			defaultDate: '2014-12-25',
+			defaultView: 'month'
+		};
+		affix('#cal');
+		affix('#otherthing');
+	});
+
+	describe('when enabled', function() {
+
+		beforeEach(function() {
+			options.unselectAuto = true;
+		});
+
+		it('unselects the current selection when clicking elsewhere in DOM', function() {
+			$('#cal').fullCalendar(options);
+			$('#cal').fullCalendar('select', '2014-12-01', '2014-12-03');
+
+			expect($('.fc-highlight').length).toBeGreaterThan(0);
+
+			$('#otherthing')
+				.simulate('mousedown')
+				.simulate('mouseup')
+				.simulate('click');
+
+			expect($('.fc-highlight').length).toBe(0);
+		});
+	});
+
+	describe('when disabled', function() {
+
+		beforeEach(function() {
+			options.unselectAuto = false;
+		});
+
+		it('keeps current selection when clicking elsewhere in DOM', function() {
+			$('#cal').fullCalendar(options);
+			$('#cal').fullCalendar('select', '2014-12-01', '2014-12-03');
+
+			expect($('.fc-highlight').length).toBeGreaterThan(0);
+
+			$('#otherthing')
+				.simulate('mousedown')
+				.simulate('mouseup')
+				.simulate('click');
+
+			expect($('.fc-highlight').length).toBeGreaterThan(0);
+		});
+	});
+});

+ 24 - 0
tests/automated/updateEvent.js

@@ -356,6 +356,30 @@ describe('updateEvent', function() {
 		expect(relatedEvent.end).toEqualMoment('2014-05-15T06:00:00');
 	});
 
+	it('should copy color-related properties to related events', function() {
+		options.events = [
+			{ id: '1', start: '2014-05-01', end: '2014-05-03', allDay: true },
+			{ id: '1', start: '2014-05-10', end: '2014-05-13', allDay: true }
+		];
+		init();
+		event.color = 'red';
+		$('#cal').fullCalendar('updateEvent', event);
+		expect(relatedEvent.color).toBe('red');
+	});
+
+	it('should non-standard properties to related events', function() {
+		options.events = [
+			{ id: '1', start: '2014-05-01', end: '2014-05-03', allDay: true },
+			{ id: '1', start: '2014-05-10', end: '2014-05-13', allDay: true }
+		];
+		init();
+		event.someForeignKey = '123';
+		event.myObj = {};
+		$('#cal').fullCalendar('updateEvent', event);
+		expect(relatedEvent.someForeignKey).toBe('123');
+		expect(relatedEvent.myObj).toBeUndefined();
+	});
+
 	function whenMovingStart(should) {
 		describe('when moving an timed event\'s start', function() {
 			beforeEach(function() {

+ 19 - 0
tests/lib/jasmine-ext.js

@@ -162,6 +162,25 @@ beforeEach(function() {
 					return result;
 				}
 			};
+		},
+		toIntersectWith: function() {
+			return {
+				compare: function(actual, expected) {
+					var subjectBounds = getBounds(actual);
+					var otherBounds = getBounds(expected);
+					var result = {
+						pass: subjectBounds && otherBounds &&
+							subjectBounds.right > otherBounds.left &&
+							subjectBounds.left < otherBounds.right &&
+							subjectBounds.bottom > otherBounds.top &&
+							subjectBounds.top < otherBounds.bottom
+					};
+					if (!result.pass) {
+						result.message = 'Element does not intersect with other element';
+					}
+					return result;
+				}
+			};
 		}
 
 	});