Browse Source

much better tests for minTime/slotDuration

Adam Shaw 8 years ago
parent
commit
fae4031923
3 changed files with 86 additions and 139 deletions
  1. 0 126
      tests/legacy/minTime.js
  2. 5 2
      tests/view-render/TimeGridRenderUtils.js
  3. 81 11
      tests/view-render/slotDuration.js

+ 0 - 126
tests/legacy/minTime.js

@@ -1,126 +0,0 @@
-describe('minTime', function() {
-
-	beforeEach(function() {
-		affix('#cal');
-	});
-
-	var numToStringConverter = function(timeIn, mins) {
-		var time = (timeIn % 12) || 12;
-		var amPm = 'am';
-		if ((timeIn % 24) > 11) {
-			amPm = 'pm';
-		}
-		return time + (mins != null ? ':' + mins : '') + amPm;
-	};
-
-	describe('when using the default settings', function() {
-
-		describe('in agendaWeek', function() {
-			it('should start at 12am', function() {
-				var options = {
-					defaultView: 'agendaWeek'
-				};
-				$('#cal').fullCalendar(options);
-				var firstSlotText = $('.fc-slats tr:eq(0) .fc-time').text();
-				expect(firstSlotText).toEqual('12am');
-			});
-		});
-
-		describe('in agendaDay', function() {
-			it('should start at 12am', function() {
-				var options = {
-					defaultView: 'agendaDay'
-				};
-				$('#cal').fullCalendar(options);
-				var firstSlotText = $('.fc-slats tr:eq(0) .fc-time').text();
-				expect(firstSlotText).toEqual('12am');
-			});
-		});
-	});
-
-	describe('when using a whole number', function() {
-
-		var hourNumbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ];
-
-		describe('in agendaWeek', function() {
-			beforeEach(function() {
-				affix('#cal2');
-			});
-			hourNumbers.forEach(function(hourNumber) {
-				it('should start at ' + hourNumber, function() {
-					var options = {
-						defaultView: 'agendaWeek',
-						minTime: { hours: hourNumber }
-					};
-					$('#cal2').fullCalendar(options);
-					var firstSlotText = $('.fc-slats tr:eq(0) .fc-time').text();
-					var expected = numToStringConverter(hourNumber);
-					expect(firstSlotText).toEqual(expected);
-				});
-			});
-		});
-
-		describe('in agendaDay', function() {
-			beforeEach(function() {
-				affix('#cal2');
-			});
-			hourNumbers.forEach(function(hourNumber) {
-				it('should start at ' + hourNumber, function() {
-					var options = {
-						defaultView: 'agendaDay',
-						minTime: hourNumber + ':00' // in addition, test string duration input
-					};
-					$('#cal2').fullCalendar(options);
-					var firstSlotText = $('.fc-slats tr:eq(0) .fc-time').text();
-					var expected = numToStringConverter(hourNumber);
-					expect(firstSlotText).toEqual(expected);
-				});
-			});
-		});
-	});
-
-	describe('when using default slotInterval and \'uneven\' minTime', function() {
-
-		var hourNumbers = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ];
-
-		describe('in agendaWeek', function() {
-			beforeEach(function() {
-				affix('#cal2');
-			});
-			hourNumbers.forEach(function(hourNumber) {
-				it('should start at ' + hourNumber + ':20', function() {
-					var options = {
-						defaultView: 'agendaWeek',
-						minTime: { hours: hourNumber, minutes: 20 }
-					};
-					$('#cal2').fullCalendar(options);
-					var slatRows = $('.fc-slats tr');
-					expect(slatRows.eq(0)).toHaveClass('fc-minor');
-					expect(slatRows.eq(1)).toHaveClass('fc-minor');
-					expect(slatRows.eq(2)).toHaveClass('fc-minor');
-					// TODO: fix bad behavior in src where no slots have text
-				});
-			});
-		});
-
-		describe('in agendaDay', function() {
-			beforeEach(function() {
-				affix('#cal2');
-			});
-			hourNumbers.forEach(function(hourNumber) {
-				it('should start at ' + hourNumber + ':20', function() {
-					var options = {
-						defaultView: 'agendaDay',
-						minTime: { hours: hourNumber, minutes: 20 }
-					};
-					$('#cal2').fullCalendar(options);
-					var slatRows = $('.fc-slats tr');
-					expect(slatRows.eq(0)).toHaveClass('fc-minor');
-					expect(slatRows.eq(1)).toHaveClass('fc-minor');
-					expect(slatRows.eq(2)).toHaveClass('fc-minor');
-					// TODO: fix bad behavior in src where no slots have text
-				});
-			});
-		});
-	});
-});

+ 5 - 2
tests/view-render/TimeGridRenderUtils.js

@@ -1,9 +1,12 @@
 
 var TimeGridRenderUtils = {
 
-	getTimeAxisText: function() {
+	getTimeAxisInfo: function() {
 		return $('.fc-slats tr[data-time]').map(function(i, tr) {
-			return $(tr).find('.fc-time').text();
+			return {
+				text: $(tr).find('.fc-time').text(),
+				isMajor: !$(tr).hasClass('fc-minor')
+			};
 		}).get();
 	}
 };

+ 81 - 11
tests/view-render/slotDuration.js

@@ -1,20 +1,90 @@
 
 describe('slotDuration', function() {
+	pushOptions({
+		defaultDate: '2017-07-17',
+		defaultView: 'agendaDay',
+		scrollTime: 0,
+		slotLabelFormat: 'HH:mm'
+	});
+
+	describe('when only major slots', function() {
+		pushOptions({
+			slotDuration: '01:00',
+			slotLabelInterval: '01:00'
+		});
+
+		describe('when in alignment with minTime', function() {
+			pushOptions({
+				minTime: '00:00',
+				maxTime: '03:00'
+			});
+			it('render slots correctly', function() {
+				initCalendar();
+				expect(TimeGridRenderUtils.getTimeAxisInfo()).toEqual([
+					{ text: '00:00', isMajor: true },
+					{ text: '01:00', isMajor: true },
+					{ text: '02:00', isMajor: true }
+				]);
+			});
+		});
 
-	describe('when out of alignment with minTime', function() {
+		describe('when out of alignment with minTime', function() {
+			pushOptions({
+				minTime: '00:20',
+				maxTime: '03:20'
+			});
+			it('render slots correctly', function() {
+				initCalendar();
+				expect(TimeGridRenderUtils.getTimeAxisInfo()).toEqual([
+					{ text: '00:20', isMajor: true },
+					{ text: '01:20', isMajor: true },
+					{ text: '02:20', isMajor: true }
+				]);
+			});
+		});
+	});
+
+	describe('when major and minor slots', function() {
 		pushOptions({
-			defaultDate: '2017-07-17',
-			defaultView: 'agendaDay',
-			minTime: '08:30:00',
-			maxTime: '12:30:00',
-			slotDuration: '01:00'
+			slotDuration: '00:30',
+			slotLabelInterval: '01:00'
 		});
 
-		it('still renders time axis text', function() {
-			initCalendar();
-			expect(TimeGridRenderUtils.getTimeAxisText()).toEqual([
-				'8:30am', '9:30am', '10:30am', '11:30am'
-			]);
+		describe('when in alignment with minTime', function() {
+			pushOptions({
+				minTime: '00:00',
+				maxTime: '03:00'
+			});
+			it('render slots correctly', function() {
+				initCalendar();
+				expect(TimeGridRenderUtils.getTimeAxisInfo()).toEqual([
+					{ text: '00:00', isMajor: true },
+					{ text: '', isMajor: false },
+					{ text: '01:00', isMajor: true },
+					{ text: '', isMajor: false },
+					{ text: '02:00', isMajor: true },
+					{ text: '', isMajor: false }
+				]);
+			});
+		});
+
+		describe('when out of alignment with minTime', function() {
+			pushOptions({
+				minTime: '00:20',
+				maxTime: '03:20'
+			});
+			it('render slots correctly', function() {
+				initCalendar();
+				expect(TimeGridRenderUtils.getTimeAxisInfo()).toEqual([
+					{ text: '00:20', isMajor: true },
+					{ text: '', isMajor: false },
+					{ text: '01:20', isMajor: true },
+					{ text: '', isMajor: false },
+					{ text: '02:20', isMajor: true },
+					{ text: '', isMajor: false }
+				]);
+			});
 		});
 	});
+
 });