Kaynağa Gözat

Update tests

acerix 8 yıl önce
ebeveyn
işleme
e4f23d7c91

+ 23 - 27
tests/legacy/dayPopoverFormat.js

@@ -1,43 +1,39 @@
-
 describe('dayPopoverFormat', function() {
 describe('dayPopoverFormat', function() {
 
 
-	var options;
-
-	beforeEach(function() {
-		affix('#cal');
-		options = {
-			defaultDate: '2014-08-01',
-			eventLimit: 3,
-			events: [
-				{ title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
-				{ title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
-				{ title: 'event3', start: '2014-07-29', className: 'event3' },
-				{ title: 'event4', start: '2014-07-29', className: 'event4' }
-			]
-		};
+	pushOptions({
+		defaultDate: '2014-08-01',
+		eventLimit: 3,
+		events: [
+			{ title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
+			{ title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
+			{ title: 'event3', start: '2014-07-29', className: 'event3' },
+			{ title: 'event4', start: '2014-07-29', className: 'event4' }
+		]
 	});
 	});
 
 
-	function init() {
-		$('#cal').fullCalendar(options);
-		$('.fc-more').simulate('click');
-	}
-
 	it('can be set to a custom value', function() {
 	it('can be set to a custom value', function() {
-		options.dayPopoverFormat = 'ddd, MMMM';
-		init();
+		initCalendar({
+			dayPopoverFormat: 'ddd, MMMM'
+		});
+		$('.fc-more').simulate('click');
 		expect($('.fc-more-popover > .fc-header .fc-title')).toHaveText('Tue, July');
 		expect($('.fc-more-popover > .fc-header .fc-title')).toHaveText('Tue, July');
 	});
 	});
 
 
 	it('is affected by the current locale when the value is default', function() {
 	it('is affected by the current locale when the value is default', function() {
-		options.locale = 'fr';
-		init();
+		initCalendar({
+			locale: 'fr'
+		});
+		$('.fc-more').simulate('click');
 		expect($('.fc-more-popover > .fc-header .fc-title')).toHaveText('29 juillet 2014');
 		expect($('.fc-more-popover > .fc-header .fc-title')).toHaveText('29 juillet 2014');
 	});
 	});
 
 
 	it('still maintains the same format when explicitly set, and there is a locale', function() {
 	it('still maintains the same format when explicitly set, and there is a locale', function() {
-		options.locale = 'fr';
-		options.dayPopoverFormat = 'YYYY';
-		init();
+		initCalendar({
+			locale: 'fr',
+			dayPopoverFormat: 'YYYY',
+		});
+		$('.fc-more').simulate('click');
 		expect($('.fc-more-popover > .fc-header .fc-title')).toHaveText('2014');
 		expect($('.fc-more-popover > .fc-header .fc-title')).toHaveText('2014');
 	});
 	});
+
 });
 });

+ 17 - 20
tests/legacy/eventDestroy.js

@@ -1,34 +1,31 @@
-
 describe('eventDestroy', function() {
 describe('eventDestroy', function() {
-	var options;
 
 
-	beforeEach(function() {
-		affix('#cal');
-		options = {
-			defaultDate: '2014-08-01'
-		};
+	pushOptions({
+		defaultDate: '2014-08-01'
 	});
 	});
 
 
 	function testSingleEvent(singleEventData, done) {
 	function testSingleEvent(singleEventData, done) {
 		var callCnt = 0;
 		var callCnt = 0;
 
 
 		expect(singleEventData.id).toBeTruthy();
 		expect(singleEventData.id).toBeTruthy();
-		options.events = [ singleEventData ];
-		options.eventDestroy = function(event, element) {
-			if (callCnt++ === 0) { // only care about the first call. gets called again when calendar is destroyed
-				expect(event.id).toBe(singleEventData.id);
-				done();
+
+		initCalendar({
+			events: [ singleEventData ],
+			eventDestroy: function(event, element) {
+				if (callCnt++ === 0) { // only care about the first call. gets called again when calendar is destroyed
+					expect(event.id).toBe(singleEventData.id);
+					done();
+				}
 			}
 			}
-		};
+		});
 
 
-		$('#cal').fullCalendar(options);
-		$('#cal').fullCalendar('removeEvents', singleEventData.id);
+		currentCalendar.removeEvents(singleEventData.id);
 	}
 	}
 
 
 	describe('when in month view', function() { // for issue 2017
 	describe('when in month view', function() { // for issue 2017
 
 
-		beforeEach(function() {
-			options.defaultView = 'month';
+		pushOptions({
+			defaultView: 'month'
 		});
 		});
 
 
 		it('gets called with removeEvents method', function(done) {
 		it('gets called with removeEvents method', function(done) {
@@ -42,9 +39,9 @@ describe('eventDestroy', function() {
 
 
 	describe('when in agendaWeek view', function() { // for issue 2017
 	describe('when in agendaWeek view', function() { // for issue 2017
 
 
-		beforeEach(function() {
-			options.defaultView = 'agendaWeek';
-			options.scrollTime = '00:00:00';
+		pushOptions({
+			defaultView: 'agendaWeek',
+			scrollTime: '00:00:00'
 		});
 		});
 
 
 		it('gets called with removeEvents method', function(done) {
 		it('gets called with removeEvents method', function(done) {

+ 35 - 35
tests/legacy/events-array.js

@@ -1,57 +1,57 @@
-
 describe('events as an array', function() {
 describe('events as an array', function() {
 
 
-	var options;
-	var eventArray;
+	pushOptions({
+		defaultView: 'month',
+		defaultDate: '2014-05-01'
+	});
 
 
-	beforeEach(function() {
-		affix('#cal');
-		options = {
-			defaultView: 'month',
-			defaultDate: '2014-05-01'
-		};
-		eventArray = [
+	function getEventArray() {
+		return [
 			{
 			{
 				title: 'my event',
 				title: 'my event',
 				start: '2014-05-21'
 				start: '2014-05-21'
 			}
 			}
 		];
 		];
-	});
+	}
 
 
 	it('accepts an event using basic form', function(done) {
 	it('accepts an event using basic form', function(done) {
-		options.events = eventArray;
-		options.eventRender = function(eventObj, eventElm) {
-			expect(eventObj.title).toEqual('my event');
-			done();
-		};
-		$('#cal').fullCalendar(options);
+		initCalendar({
+			events: getEventArray(),
+			eventRender: function(eventObj, eventElm) {
+				expect(eventObj.title).toEqual('my event');
+				done();
+			}
+		});
 	});
 	});
 
 
 	it('accepts an event using extended form', function(done) {
 	it('accepts an event using extended form', function(done) {
-		options.eventSources = [
-			{
-				className: 'customeventclass',
-				events: eventArray
+		initCalendar({
+			eventSources: [
+				{
+					className: 'customeventclass',
+					events: getEventArray()
+				}
+			],
+			eventRender: function(eventObj, eventElm) {
+				expect(eventObj.title).toEqual('my event');
+				expect(eventElm).toHaveClass('customeventclass');
+				done();
 			}
 			}
-		];
-		options.eventRender = function(eventObj, eventElm) {
-			expect(eventObj.title).toEqual('my event');
-			expect(eventElm).toHaveClass('customeventclass');
-			done();
-		};
-		$('#cal').fullCalendar(options);
+		});
 	});
 	});
 
 
 	it('doesn\'t mutate the original array', function(done) {
 	it('doesn\'t mutate the original array', function(done) {
+		var eventArray = getEventArray();
 		var origArray = eventArray;
 		var origArray = eventArray;
 		var origEvent = eventArray[0];
 		var origEvent = eventArray[0];
-		options.events = eventArray;
-		options.eventRender = function(eventObj, eventElm) {
-			expect(origArray).toEqual(eventArray);
-			expect(origEvent).toEqual(eventArray[0]);
-			done();
-		};
-		$('#cal').fullCalendar(options);
+		initCalendar({
+			events: eventArray,
+			eventRender: function(eventObj, eventElm) {
+				expect(origArray).toEqual(eventArray);
+				expect(origEvent).toEqual(eventArray[0]);
+				done();
+			}
+		});
 	});
 	});
 
 
 });
 });

+ 12 - 19
tests/legacy/footer-rendering.js

@@ -1,50 +1,43 @@
-
 describe('footer rendering', function() {
 describe('footer rendering', function() {
 
 
-	beforeEach(function() {
-		affix('#calendar');
+	pushOptions({
+		defaultDate: '2014-06-04',
+		defaultView: 'agendaWeek'
 	});
 	});
 
 
 	describe('when supplying footer options', function() {
 	describe('when supplying footer options', function() {
-		beforeEach(function() {
-			var options = {
+		it('should append a .fc-footer-toolbar to the DOM', function() {
+			initCalendar({
 				footer: {
 				footer: {
 					left: 'next,prev',
 					left: 'next,prev',
 					center: 'prevYear today nextYear agendaView,dayView',
 					center: 'prevYear today nextYear agendaView,dayView',
 					right: 'title'
 					right: 'title'
 				}
 				}
-			};
-			$('#calendar').fullCalendar(options);
-		});
-		it('should append a .fc-footer-toolbar to the DOM', function() {
+			});
 			var footer = $('#calendar .fc-footer-toolbar');
 			var footer = $('#calendar .fc-footer-toolbar');
 			expect(footer.length).toBe(1);
 			expect(footer.length).toBe(1);
 		});
 		});
 	});
 	});
 
 
 	describe('when setting footer to false', function() {
 	describe('when setting footer to false', function() {
-		beforeEach(function() {
-			var options = {
-				footer: false
-			};
-			$('#calendar').fullCalendar(options);
-		});
 		it('should not have footer table', function() {
 		it('should not have footer table', function() {
+			initCalendar({
+				footer: false
+			});
 			expect($('.fc-footer-toolbar')).not.toBeInDOM();
 			expect($('.fc-footer-toolbar')).not.toBeInDOM();
 		});
 		});
 	});
 	});
 
 
 	it('allow for dynamically changing', function() {
 	it('allow for dynamically changing', function() {
-		var options = {
+		initCalendar({
 			footer: {
 			footer: {
 				left: 'next,prev',
 				left: 'next,prev',
 				center: 'prevYear today nextYear agendaView,dayView',
 				center: 'prevYear today nextYear agendaView,dayView',
 				right: 'title'
 				right: 'title'
 			}
 			}
-		};
-		$('#calendar').fullCalendar(options);
+		});
 		expect($('.fc-footer-toolbar')).toBeInDOM();
 		expect($('.fc-footer-toolbar')).toBeInDOM();
-		$('#calendar').fullCalendar('option', 'footer', false);
+		currentCalendar.option('footer', false);
 		expect($('.fc-footer-toolbar')).not.toBeInDOM();
 		expect($('.fc-footer-toolbar')).not.toBeInDOM();
 	});
 	});
 
 

+ 13 - 17
tests/legacy/removeEventSources.js

@@ -1,26 +1,22 @@
 describe('removeEventSources', function() {
 describe('removeEventSources', function() {
-	var options;
-
-	beforeEach(function() {
-		affix('#cal');
-		options = {
-			defaultDate: '2014-08-01',
-			defaultView: 'agendaDay',
-			eventSources: [
-				buildEventSource(1),
-				buildEventSource(2),
-				buildEventSource(3)
-			]
-		};
+
+	pushOptions({
+		defaultDate: '2014-08-01',
+		defaultView: 'agendaDay',
+		eventSources: [
+			buildEventSource(1),
+			buildEventSource(2),
+			buildEventSource(3)
+		]
 	});
 	});
 
 
 	describe('when called with no arguments', function() {
 	describe('when called with no arguments', function() {
 		it('removes all sources', function() {
 		it('removes all sources', function() {
 
 
-			$('#cal').fullCalendar(options);
+			initCalendar();
 			expect($('.fc-event').length).toBe(3);
 			expect($('.fc-event').length).toBe(3);
 
 
-			$('#cal').fullCalendar('removeEventSources');
+			currentCalendar.removeEventSources();
 			expect($('.fc-event').length).toBe(0);
 			expect($('.fc-event').length).toBe(0);
 		});
 		});
 	});
 	});
@@ -28,10 +24,10 @@ describe('removeEventSources', function() {
 	describe('when called with specific IDs', function() {
 	describe('when called with specific IDs', function() {
 		it('removes only events with matching sources', function() {
 		it('removes only events with matching sources', function() {
 
 
-			$('#cal').fullCalendar(options);
+			initCalendar();
 			expect($('.fc-event').length).toBe(3);
 			expect($('.fc-event').length).toBe(3);
 
 
-			$('#cal').fullCalendar('removeEventSources', [ 1, 3 ]);
+			currentCalendar.removeEventSources([ 1, 3 ]);
 			expect($('.fc-event').length).toBe(1);
 			expect($('.fc-event').length).toBe(1);
 			expect($('.event2').length).toBe(1);
 			expect($('.event2').length).toBe(1);
 		});
 		});

+ 10 - 13
tests/legacy/scrollTime.js

@@ -1,18 +1,14 @@
 describe('scrollTime', function() {
 describe('scrollTime', function() {
 
 
-	var options;
-
-	beforeEach(function() {
-		affix('#cal');
-		options = {
-			defaultView: 'agendaWeek'
-		};
+	pushOptions({
+		defaultView: 'agendaWeek'
 	});
 	});
 
 
 	it('accepts a string Duration', function() {
 	it('accepts a string Duration', function() {
-		options.scrollTime = '02:00:00';
-		options.height = 400; // short enough to make scrolling happen
-		$('#cal').fullCalendar(options);
+		initCalendar({
+			scrollTime: '02:00:00',
+			height: 400 // short enough to make scrolling happen
+		});
 		var slotCell = $('.fc-slats tr:eq(4)'); // 2am slot
 		var slotCell = $('.fc-slats tr:eq(4)'); // 2am slot
 		var slotTop = slotCell.position().top;
 		var slotTop = slotCell.position().top;
 		var scrollContainer = $('.fc-time-grid-container');
 		var scrollContainer = $('.fc-time-grid-container');
@@ -24,9 +20,10 @@ describe('scrollTime', function() {
 	});
 	});
 
 
 	it('accepts a Duration object', function() {
 	it('accepts a Duration object', function() {
-		options.scrollTime = { hours: 2 };
-		options.height = 400; // short enough to make scrolling happen
-		$('#cal').fullCalendar(options);
+		initCalendar({
+			scrollTime: { hours: 2 },
+			height: 400 // short enough to make scrolling happen
+		});
 		var slotCell = $('.fc-slats tr:eq(4)'); // 2am slot
 		var slotCell = $('.fc-slats tr:eq(4)'); // 2am slot
 		var slotTop = slotCell.position().top;
 		var slotTop = slotCell.position().top;
 		var scrollContainer = $('.fc-time-grid-container');
 		var scrollContainer = $('.fc-time-grid-container');