Преглед изворни кода

extensive event color tests

Adam Shaw пре 11 година
родитељ
комит
f86c0c66af
2 измењених фајлова са 207 додато и 56 уклоњено
  1. 2 56
      tests/automated/background-events.js
  2. 205 0
      tests/automated/event-coloring.js

+ 2 - 56
tests/automated/background-events.js

@@ -1,6 +1,8 @@
 
 describe('background events', function() {
 
+	// SEE ALSO: event-color.js
+
 	var options;
 
 	beforeEach(function() {
@@ -325,62 +327,6 @@ describe('background events', function() {
 			});
 		});
 
-		it('can have custom Event Object color', function(done) {
-			options.events = [ {
-				start: '2014-11-04',
-				rendering: 'background',
-				color: 'red'
-			} ];
-			options.eventAfterAllRender = function() {
-				expect($('.fc-bgevent').css('background-color')).toMatch(RED_REGEX);
-				done();
-			};
-			$('#cal').fullCalendar(options);
-		});
-
-		it('can have custom Event Object backgroundColor', function(done) {
-			options.events = [ {
-				start: '2014-11-04',
-				rendering: 'background',
-				backgroundColor: 'red'
-			} ];
-			options.eventAfterAllRender = function() {
-				expect($('.fc-bgevent').css('background-color')).toMatch(RED_REGEX);
-				done();
-			};
-			$('#cal').fullCalendar(options);
-		});
-
-		it('can have custom Event Source color', function(done) {
-			options.eventSources = [ {
-				color: 'red',
-				events: [ {
-					start: '2014-11-04',
-					rendering: 'background'
-				} ]
-			} ];
-			options.eventAfterAllRender = function() {
-				expect($('.fc-bgevent').css('background-color')).toMatch(RED_REGEX);
-				done();
-			};
-			$('#cal').fullCalendar(options);
-		});
-
-		it('can have custom Event Source backgroundColor', function(done) {
-			options.eventSources = [ {
-				backgroundColor: 'red',
-				events: [ {
-					start: '2014-11-04',
-					rendering: 'background'
-				} ]
-			} ];
-			options.eventAfterAllRender = function() {
-				expect($('.fc-bgevent').css('background-color')).toMatch(RED_REGEX);
-				done();
-			};
-			$('#cal').fullCalendar(options);
-		});
-
 		describe('when in month view', function() {
 			it('can be activated when rendering set on the source', function(done) {
 				options.defaultView = 'month';

+ 205 - 0
tests/automated/event-coloring.js

@@ -0,0 +1,205 @@
+
+describe('event coloring', function() {
+
+	var eventInput;
+	var options;
+
+	beforeEach(function() {
+		eventInput = {};
+		options = {
+			defaultDate: '2014-11-04'
+		};
+		affix('#cal');
+	});
+
+	describe('when in month view', function() {
+		beforeEach(function() {
+			options.defaultView = 'month';
+			eventInput = { start: '2014-11-04' };
+		});
+		defineTests();
+	});
+
+	describe('when in agendaWeek view', function() {
+		beforeEach(function() {
+			options.defaultView = 'agendaWeek';
+			options.allDaySlot = false;
+			eventInput = { start: '2014-11-04T01:00:00' };
+		});
+		defineTests();
+	});
+
+
+	function defineTests() {
+
+		describe('for foreground events', function() {
+			testTextColor();
+			testBorderColor();
+			testBackgroundColor();
+		});
+
+		describe('for background events', function() {
+			beforeEach(function() {
+				eventInput.rendering = 'background';
+			});
+
+			testBackgroundColor();
+		});
+	}
+
+
+	function testTextColor() {
+
+		it('should accept the global eventTextColor', function() {
+			options.eventTextColor = 'red';
+			options.events = [ eventInput ];
+			$('#cal').fullCalendar(options);
+			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);
+			expect(getEventCss('color')).toMatch(RED_REGEX);
+		});
+
+		it('should accept an event object\'s textColor', function() {
+			eventInput.textColor = 'red';
+			options.eventSources = [ {
+				textColor: 'blue', // even when there's a more general setting
+				events: [ eventInput ]
+			} ];
+			$('#cal').fullCalendar(options);
+			expect(getEventCss('color')).toMatch(RED_REGEX);
+		});
+	}
+
+
+	function testBorderColor() {
+
+		it('should accept the global eventColor for border color', function() {
+			options.eventColor = 'red';
+			options.events = [ eventInput ];
+			$('#cal').fullCalendar(options);
+			expect(getEventCss('border-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);
+			expect(getEventCss('border-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);
+			expect(getEventCss('border-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);
+			expect(getEventCss('border-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);
+			expect(getEventCss('border-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);
+			expect(getEventCss('border-color')).toMatch(RED_REGEX);
+		});
+	}
+
+
+	function testBackgroundColor() {
+
+		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);
+		});
+
+		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);
+		});
+
+		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);
+		});
+
+		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);
+		});
+
+		it('should accept an event object\'s color for the background', function() {
+			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);
+		});
+
+		it('should accept an event object\'s backgroundColor', function() {
+			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);
+		});
+	}
+
+
+	function getEventCss(prop) {
+		var el = $(eventInput.rendering == 'background' ? '.fc-bgevent' : '.fc-event');
+		return el.css(prop);
+	}
+
+});