Browse Source

Update legacy tests

acerix 8 years ago
parent
commit
79fa0efb9d
1 changed files with 151 additions and 112 deletions
  1. 151 112
      tests/legacy/event-coloring.js

+ 151 - 112
tests/legacy/event-coloring.js

@@ -1,205 +1,244 @@
 
 describe('event coloring', function() {
 
-	var eventInput;
-	var options;
-
-	beforeEach(function() {
-		eventInput = {};
-		options = {
-			defaultDate: '2014-11-04'
-		};
-		affix('#cal');
+	pushOptions({
+		defaultDate: '2014-11-04'
 	});
 
 	describe('when in month view', function() {
-		beforeEach(function() {
-			options.defaultView = 'month';
-			eventInput = { start: '2014-11-04' };
+
+		pushOptions({
+			defaultView: 'month'
 		});
-		defineTests();
+
+		defineViewTests(false);
 	});
 
 	describe('when in agendaWeek view', function() {
-		beforeEach(function() {
-			options.defaultView = 'agendaWeek';
-			options.allDaySlot = false;
-			eventInput = { start: '2014-11-04T01:00:00' };
+
+		pushOptions({
+			defaultView: 'agendaWeek',
+			allDaySlot: false
 		});
-		defineTests();
-	});
 
+		defineViewTests(true);
+	});
 
-	function defineTests() {
+	function defineViewTests(eventHasTime) {
 
 		describe('for foreground events', function() {
-			testTextColor();
-			testBorderColor();
-			testBackgroundColor();
+			testTextColor(eventHasTime);
+			testBorderColor(eventHasTime);
+			testBackgroundColor(eventHasTime);
 		});
 
 		describe('for background events', function() {
-			beforeEach(function() {
-				eventInput.rendering = 'background';
-			});
-
-			testBackgroundColor();
+			testBackgroundColor(eventHasTime, 'background');
 		});
+
 	}
 
+	function testTextColor(eventHasTime) {
 
-	function testTextColor() {
+		var eventOptions = getEventOptions(eventHasTime);
 
 		it('should accept the global eventTextColor', function() {
-			options.eventTextColor = 'red';
-			options.events = [ eventInput ];
-			$('#cal').fullCalendar(options);
+			initCalendar({
+				eventTextColor: 'red',
+				events: [ getTestEvent(eventOptions) ]
+			});
 			expect(getEventCss('color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event source\'s textColor', function() {
-			options.eventTextColor = 'blue'; // even when there's a more general setting
-			options.eventSources = [ {
-				textColor: 'red',
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
+			initCalendar({
+				eventTextColor: 'blue', // even when there's a more general setting
+				eventSources: [ {
+					textColor: 'red',
+					events: [ getTestEvent(eventOptions) ]
+				} ]
+			});
 			expect(getEventCss('color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event object\'s textColor', function() {
-			eventInput.textColor = 'red';
-			options.eventSources = [ {
+			var eventInput = getTestEvent(eventOptions, {
+				textColor: 'red'
+			});
+			initCalendar({
 				textColor: 'blue', // even when there's a more general setting
 				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
+			});
 			expect(getEventCss('color')).toMatch(RED_REGEX);
 		});
 	}
 
+	function testBorderColor(eventHasTime) {
 
-	function testBorderColor() {
+		var eventOptions = getEventOptions(eventHasTime);
 
 		it('should accept the global eventColor for border color', function() {
-			options.eventColor = 'red';
-			options.events = [ eventInput ];
-			$('#cal').fullCalendar(options);
+			initCalendar({
+				eventColor: 'red',
+				events: [ getTestEvent(eventOptions) ]
+			});
 			expect(getEventCss('border-top-color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept the global eventBorderColor', function() {
-			options.eventColor = 'blue'; // even when there's a more general setting
-			options.eventBorderColor = 'red';
-			options.events = [ eventInput ];
-			$('#cal').fullCalendar(options);
+			initCalendar({
+				eventColor: 'blue',
+				eventBorderColor: 'red',
+				events: [ getTestEvent(eventOptions) ]
+			});
 			expect(getEventCss('border-top-color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event source\'s color for the border', function() {
-			options.eventBorderColor = 'blue'; // even when there's a more general setting
-			options.eventSources = [ {
-				color: 'red',
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
+			initCalendar({
+				eventBorderColor: 'blue', // even when there's a more general setting
+				eventSources: [ {
+					color: 'red',
+					events: [ getTestEvent(eventOptions) ]
+				} ]
+			});
 			expect(getEventCss('border-top-color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event source\'s borderColor', function() {
-			options.eventSources = [ {
-				color: 'blue', // even when there's a more general setting
-				borderColor: 'red',
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
+			initCalendar({
+				eventBorderColor: 'blue', // even when there's a more general setting
+				eventSources: [ {
+					color: 'blue',
+					borderColor: 'red',
+					events: [ getTestEvent(eventOptions) ]
+				} ]
+			});
 			expect(getEventCss('border-top-color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event object\'s color for the border', function() {
-			eventInput.color = 'red';
-			options.eventSources = [ {
-				borderColor: 'blue', // even when there's a more general setting
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
+			var eventInput = getTestEvent(eventOptions, {
+				color: 'red'
+			});
+			initCalendar({
+				eventSources: [ {
+					borderColor: 'blue', // even when there's a more general setting
+					events: [ eventInput ]
+				} ]
+			});
 			expect(getEventCss('border-top-color')).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event object\'s borderColor', function() {
-			eventInput.color = 'blue'; // even when there's a more general setting
-			eventInput.borderColor = 'red';
-			options.eventSources = [ {
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
+			var eventInput = getTestEvent(eventOptions, {
+				color: 'blue', // even when there's a more general setting
+				borderColor: 'red'
+			});
+			initCalendar({
+				eventSources: [ {
+					events: [ eventInput ]
+				} ]
+			});
 			expect(getEventCss('border-top-color')).toMatch(RED_REGEX);
 		});
 	}
 
 
-	function testBackgroundColor() {
+	function testBackgroundColor(eventHasTime, rendering) {
+
+		var eventOptions = getEventOptions(eventHasTime);
+
+		if (typeof rendering !== 'undefined') {
+			eventOptions.rendering = rendering;
+		}
 
 		it('should accept the global eventColor for background color', function() {
-			options.eventColor = 'red';
-			options.events = [ eventInput ];
-			$('#cal').fullCalendar(options);
-			expect(getEventCss('background-color')).toMatch(RED_REGEX);
+			initCalendar({
+				eventColor: 'red',
+				events: [ getTestEvent(eventOptions) ]
+			});
+			expect(getEventCss('background-color', rendering)).toMatch(RED_REGEX);
 		});
 
 		it('should accept the global eventBackgroundColor', function() {
-			options.eventColor = 'blue'; // even when there's a more general setting
-			options.eventBackgroundColor = 'red';
-			options.events = [ eventInput ];
-			$('#cal').fullCalendar(options);
-			expect(getEventCss('background-color')).toMatch(RED_REGEX);
+			initCalendar({
+				eventColor: 'blue', // even when there's a more general setting
+				eventBackgroundColor: 'red',
+				events: [ getTestEvent(eventOptions) ],
+			});
+			expect(getEventCss('background-color', rendering)).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event source\'s color for the background', function() {
-			options.eventBackgroundColor = 'blue'; // even when there's a more general setting
-			options.eventSources = [ {
-				color: 'red',
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
-			expect(getEventCss('background-color')).toMatch(RED_REGEX);
+			initCalendar({
+				eventBackgroundColor: 'blue', // even when there's a more general setting
+				eventSources: [ {
+					color: 'red',
+					events: [ getTestEvent(eventOptions) ]
+				} ]
+			});
+			expect(getEventCss('background-color', rendering)).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event source\'s backgroundColor', function() {
-			options.eventSources = [ {
-				color: 'blue', // even when there's a more general setting
-				backgroundColor: 'red',
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
-			expect(getEventCss('background-color')).toMatch(RED_REGEX);
+			initCalendar({
+				eventSources: [ {
+					color: 'blue', // even when there's a more general setting
+					backgroundColor: 'red',
+					events: [ getTestEvent(eventOptions) ]
+				} ]
+			});
+			expect(getEventCss('background-color', rendering)).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event object\'s color for the background', function() {
+			var eventInput = getTestEvent(eventOptions);
 			eventInput.color = 'red';
-			options.eventSources = [ {
-				backgroundColor: 'blue', // even when there's a more general setting
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
-			expect(getEventCss('background-color')).toMatch(RED_REGEX);
+			initCalendar({
+				eventSources: [ {
+					backgroundColor: 'blue', // even when there's a more general setting
+					events: [ eventInput ]
+				} ]
+			});
+			expect(getEventCss('background-color', rendering)).toMatch(RED_REGEX);
 		});
 
 		it('should accept an event object\'s backgroundColor', function() {
+			var eventInput = getTestEvent(eventOptions);
 			eventInput.color = 'blue'; // even when there's a more general setting
 			eventInput.backgroundColor = 'red';
-			options.eventSources = [ {
-				events: [ eventInput ]
-			} ];
-			$('#cal').fullCalendar(options);
-			expect(getEventCss('background-color')).toMatch(RED_REGEX);
+			initCalendar({
+				eventSources: [ {
+					events: [ eventInput ]
+				} ]
+			});
+			expect(getEventCss('background-color', rendering)).toMatch(RED_REGEX);
 		});
 	}
 
-
-	function getEventCss(prop) {
-		var el = $(eventInput.rendering == 'background' ? '.fc-bgevent' : '.fc-event');
+	function getEventCss(prop, rendering) {
+		var el = $(rendering === 'background' ? '.fc-bgevent' : '.fc-event');
 		return el.css(prop);
 	}
 
+	function getTestEvent(defaultOptions, extraOptions) {
+		var event = {};
+		$.extend( event, defaultOptions );
+		if (extraOptions) {
+			$.extend( event, extraOptions );
+		}
+		return event;
+	}
+
+	function getEventOptions(eventHasTime) {
+		var options = {
+			start: '2014-11-04'
+		};
+		if (eventHasTime) {
+			options.start += 'T01:00:00';
+		}
+		return options;
+	};
+
 });