2
0
Эх сурвалжийг харах

Refactor and extend automated test for weekNumbers

Peter Nowee 10 жил өмнө
parent
commit
3a405bf32b
1 өөрчлөгдсөн 292 нэмэгдсэн , 53 устгасан
  1. 292 53
      tests/automated/weekNumbers.js

+ 292 - 53
tests/automated/weekNumbers.js

@@ -1,118 +1,357 @@
 
 describe('weekNumbers', function() {
 
+	var options;
+	var counts;
+
 	beforeEach(function() {
 		affix('#cal');
+		counts = {};
+		options = {};
+	});
+
+	afterEach(function() {
+		$('#cal').fullCalendar('destroy');
 	});
 
 	describe('when using month view', function() {
 
+		beforeEach(function() {
+			options.defaultView = 'month';
+			options.weekMode = 'fixed'; // will make 6 rows
+		});
+
 		describe('with default weekNumbers', function() {
-			it('should not display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'month'
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should not display week numbers at all', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-content-skeleton thead .fc-week-number').length;
-				expect(weekNumbersCount).toEqual(0);
 			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
 		});
 
 		describe('with weekNumbers to false', function() {
-			it('should not display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'month',
-					weekNumbers: false
+
+			beforeEach(function() {
+				options.weekNumbers = false;
+			});
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should not display week numbers at all', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-content-skeleton thead .fc-week-number').length;
-				expect(weekNumbersCount).toEqual(0);
 			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
 		});
 
 		describe('with weekNumbers to true', function() {
-			it('should display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'month',
-					weekNumbers: true,
-					weekMode: 'fixed' // will make 6 rows
+
+			beforeEach(function() {
+				options.weekNumbers = true;
+			});
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should display week numbers along the side only', function() {
+					counts = getCounts();
+					// TODO: Is it possible to remove class fc-week-number from
+					// headers and fillers, bringing allWeekNumbers down to 6?
+					expect(counts.allWeekNumbers).toEqual(19);
+					expect(counts.colWeekNumbers).toEqual(6);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should display week numbers along the side only', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					// TODO: Is it possible to remove class fc-week-number from
+					// headers and fillers, bringing allWeekNumbers down to 6?
+					expect(counts.allWeekNumbers).toEqual(19);
+					expect(counts.colWeekNumbers).toEqual(6);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should display week numbers in the day cells only', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(6);
+					expect(counts.colWeekNumbers).toEqual(0);
+					expect(counts.cellWeekNumbers).toEqual(6);
+					expect(counts.cornerWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-content-skeleton thead .fc-week-number').length;
-				expect(weekNumbersCount).toEqual(6);
 			});
+
 		});
 
 	});
 
 	describe('when using basicWeek view', function() {
 
+		beforeEach(function() {
+			options.defaultView = 'basicWeek';
+		});
+
 		describe('with default weekNumbers', function() {
-			it('should not display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'basicWeek'
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should not display week numbers at all', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-content-skeleton thead .fc-week-number').length;
-				expect(weekNumbersCount).toEqual(0);
 			});
+
 		});
 
 		describe('with weekNumbers to false', function() {
-			it('should not display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'basicWeek',
-					weekNumbers: false
+
+			beforeEach(function() {
+				options.weekNumbers = false;
+			});
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should not display week numbers at all', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-content-skeleton thead .fc-week-number').length;
-				expect(weekNumbersCount).toEqual(0);
 			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
 		});
 
 		describe('with weekNumbers to true', function() {
-			it('should display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'basicWeek',
-					weekNumbers: true
+
+			beforeEach(function() {
+				options.weekNumbers = true;
+			});
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should display week numbers along the side only', function() {
+					counts = getCounts();
+					// TODO: Is it possible to remove class fc-week-number from
+					// headers and fillers, bringing allWeekNumbers down to 1?
+					expect(counts.allWeekNumbers).toEqual(4);
+					expect(counts.colWeekNumbers).toEqual(1);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should display week numbers along the side only', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					// TODO: Is it possible to remove class fc-week-number from
+					// headers and fillers, bringing allWeekNumbers down to 1?
+					expect(counts.allWeekNumbers).toEqual(4);
+					expect(counts.colWeekNumbers).toEqual(1);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should display week numbers in the day cells only', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(1);
+					expect(counts.colWeekNumbers).toEqual(0);
+					expect(counts.cellWeekNumbers).toEqual(1);
+					expect(counts.cornerWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-content-skeleton thead .fc-week-number').length;
-				expect(weekNumbersCount).toEqual(1);
 			});
+
 		});
 
 	});
 
 	describe('when using an agenda view', function() {
 
+		beforeEach(function() {
+			options.defaultView = 'agendaWeek';
+		});
+
 		describe('with default weekNumbers', function() {
-			it('should not display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'agendaWeek'
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should not display week numbers at all', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-week-number').length;
-				expect(weekNumbersCount).toEqual(0);
 			});
+
 		});
 
 		describe('with weekNumbers to false', function() {
-			it('should not display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'agendaWeek',
-					weekNumbers: false
+
+			beforeEach(function() {
+				options.weekNumbers = false;
+			});
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should not display week numbers at all', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
 				});
-				var weekNumbersCount = $('.fc-week-number').length;
-				expect(weekNumbersCount).toEqual(0);
 			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should not display week numbers at all', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(0);
+				});
+			});
+
 		});
 
 		describe('with weekNumbers to true', function() {
-			it('should display weekNumbers', function() {
-				$('#cal').fullCalendar({
-					defaultView: 'agendaWeek',
-					weekNumbers: true
+
+			beforeEach(function() {
+				options.weekNumbers = true;
+			});
+
+			describe('and default basicViewWeekNrPosition', function() {
+				it('should display week numbers in the top left corner only', function() {
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(1);
+					expect(counts.colWeekNumbers).toEqual(0);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(1);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrSeparateColumn', function() {
+				it('should display week numbers in the top left corner only', function() {
+					options.basicViewWeekNrPosition = 'weekNrSeparateColumn';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(1);
+					expect(counts.colWeekNumbers).toEqual(0);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(1);
+				});
+			});
+
+			describe('and basicViewWeekNrPosition set to weekNrDayCell', function() {
+				it('should display week numbers in the top left corner only', function() {
+					options.basicViewWeekNrPosition = 'weekNrDayCell';
+					counts = getCounts();
+					expect(counts.allWeekNumbers).toEqual(1);
+					expect(counts.colWeekNumbers).toEqual(0);
+					expect(counts.cellWeekNumbers).toEqual(0);
+					expect(counts.cornerWeekNumbers).toEqual(1);
 				});
-				var weekNumbersCount = $('.fc-week-number').length;
-				// 1 row is axis
-				expect(weekNumbersCount).toEqual(1);
 			});
+
 		});
 
 	});
 
+	function getCounts() {
+		var t = {};
+
+		$('#cal').fullCalendar(options);
+
+		t.allWeekNumbers = $('.fc-week-number').length;
+		t.colWeekNumbers = $('.fc-content-skeleton thead td.fc-week-number').length;
+		t.cellWeekNumbers = $('.fc-content-skeleton thead .fc-numbercell span.fc-week-number').length;
+		t.cornerWeekNumbers = $('.fc-axis.fc-widget-header.fc-week-number').length;
+
+		return t;
+	}
+
 });