Parcourir la source

automated tests for new features

Adam Shaw il y a 11 ans
Parent
commit
21a3560681

+ 85 - 0
tests/automated/custom-view-class.js

@@ -0,0 +1,85 @@
+describe('custom view class', function() {
+
+	beforeEach(function() {
+		affix('#cal');
+	});
+
+	it('calls all standard methods with correct parameters', function() {
+		var FC = $.fullCalendar;
+		var View = FC.View;
+		var CustomView;
+
+		var methods = {
+			initialize: function() {
+			},
+			render: function() {
+			},
+			setHeight: function(height, isAuto) {
+				expect(typeof height).toBe('number');
+				expect(typeof isAuto).toBe('boolean');
+			},
+			renderEvents: function(events) {
+				expect($.type(events)).toBe('array');
+				expect(events.length).toBe(1);
+				expect(moment.isMoment(events[0].start)).toBe(true);
+				expect(moment.isMoment(events[0].end)).toBe(true);
+			},
+			getEventSegs: function() {
+				return [];
+			},
+			destroyEvents: function() {
+			},
+			renderSelection: function(range) {
+				expect($.type(range)).toBe('object');
+				expect(moment.isMoment(range.start)).toBe(true);
+				expect(moment.isMoment(range.end)).toBe(true);
+			},
+			destroySelection: function() {
+			}
+		};
+
+		spyOn(methods, 'initialize').and.callThrough();
+		spyOn(methods, 'render').and.callThrough();
+		spyOn(methods, 'setHeight').and.callThrough();
+		spyOn(methods, 'renderEvents').and.callThrough();
+		spyOn(methods, 'getEventSegs').and.callThrough();
+		spyOn(methods, 'destroyEvents').and.callThrough();
+		spyOn(methods, 'renderSelection').and.callThrough();
+		spyOn(methods, 'destroySelection').and.callThrough();
+
+		CustomView = View.extend(methods);
+		FC.views.custom = CustomView;
+
+		$('#cal').fullCalendar({
+			defaultView: 'custom',
+			events: [
+				{
+					title: 'Holidays',
+					start: '2014-12-24',
+					end: '2014-12-26'
+				}
+			]
+		});
+
+		expect(methods.initialize).toHaveBeenCalled();
+		expect(methods.render).toHaveBeenCalled();
+		expect(methods.setHeight).toHaveBeenCalled();
+		expect(methods.renderEvents).toHaveBeenCalled();
+		expect(methods.getEventSegs).toHaveBeenCalled();
+
+		$('#cal').fullCalendar('rerenderEvents');
+
+		expect(methods.destroyEvents).toHaveBeenCalled();
+
+		$('#cal').fullCalendar('select', '2014-12-25', '2014-01-01');
+
+		expect(methods.renderSelection).toHaveBeenCalled();
+
+		$('#cal').fullCalendar('unselect');
+
+		expect(methods.destroySelection).toHaveBeenCalled();
+
+		delete FC.views.custom;
+	});
+
+});

+ 148 - 0
tests/automated/custom-view-duration.js

@@ -0,0 +1,148 @@
+describe('custom view duration', function() {
+	var options;
+
+	beforeEach(function() {
+		options = {
+			views: {}
+		};
+		affix('#cal');
+	});
+
+	it('renders a 4 day basic view', function() {
+		options.views.basicFourDay = {
+			type: 'basic',
+			duration: { days: 4 }
+		};
+		options.defaultView = 'basicFourDay';
+		options.defaultDate = '2014-12-25';
+		$('#cal').fullCalendar(options);
+		expect($('.fc-day-grid .fc-row').length).toBe(1);
+		expect($('.fc-day-grid .fc-row .fc-day').length).toBe(4);
+		expect($('.fc-day-grid .fc-row .fc-day:first'))
+			.toBeMatchedBy('[data-date="2014-12-25"]'); // starts on defaultDate
+	});
+
+	it('renders a 2 week basic view', function() {
+		options.views.basicTwoWeek = {
+			type: 'basic',
+			duration: { weeks: 2 }
+		};
+		options.defaultView = 'basicTwoWeek';
+		options.defaultDate = '2014-12-25';
+		options.firstDay = 2; // Tues
+		$('#cal').fullCalendar(options);
+		expect($('.fc-day-grid .fc-row').length).toBe(2);
+		expect($('.fc-day-grid .fc-day').length).toBe(14);
+		expect($('.fc-day-grid .fc-day:first')).toBeMatchedBy('.fc-tue'); // respects start-of-week
+		expect($('.fc-day-grid .fc-day:first')).toBeMatchedBy('[data-date="2014-12-23"]'); // week start. tues
+	});
+
+	it('will use the provided options', function() {
+		options.views.basicFourDay = {
+			type: 'basic',
+			duration: { days: 4 },
+			titleFormat: '[special]'
+		};
+		options.defaultView = 'basicFourDay';
+		$('#cal').fullCalendar(options);
+		expect($('h2')).toHaveText('special');
+	});
+
+	it('will inherit options from the parent view type', function() {
+		options.views.basic = {
+			titleFormat: '[basictitle]'
+		};
+		options.views.basicFourDay = {
+			type: 'basic',
+			duration: { days: 4 }
+		};
+		options.defaultView = 'basicFourDay';
+		$('#cal').fullCalendar(options);
+		expect($('h2')).toHaveText('basictitle');
+	});
+
+	it('will override an option from the parent view type', function() {
+		options.views.basic = {
+			titleFormat: '[basictitle]'
+		};
+		options.views.basicFourDay = {
+			type: 'basic',
+			duration: { days: 4 },
+			titleFormat: '[basicfourweekttitle]'
+		};
+		options.defaultView = 'basicFourDay';
+		$('#cal').fullCalendar(options);
+		expect($('h2')).toHaveText('basicfourweekttitle');
+	});
+
+	it('will inherit options from generic "week" type', function() {
+		options.views.week = {
+			titleFormat: '[weektitle]'
+		};
+		options.views.basicOneWeek = {
+			type: 'basic',
+			duration: { weeks: 1 }
+		};
+		options.defaultView = 'basicOneWeek';
+		$('#cal').fullCalendar(options);
+		expect($('h2')).toHaveText('weektitle');
+	});
+
+	it('generic type options for "basic" will override generic "week" options', function() {
+		options.views.week = {
+			titleFormat: '[weektitle]'
+		};
+		options.views.basic = {
+			titleFormat: '[basictitle]'
+		};
+		options.views.basicOneWeek = {
+			type: 'basic',
+			duration: { weeks: 1 }
+		};
+		options.defaultView = 'basicOneWeek';
+		$('#cal').fullCalendar(options);
+		expect($('h2')).toHaveText('basictitle');
+	});
+
+	it('will not inherit "week" options if more than a single week', function() {
+		options.titleFormat = '[defaultitle]';
+		options.views.week = {
+			titleFormat: '[weektitle]'
+		};
+		options.views.basicTwoWeek = {
+			type: 'basic',
+			duration: { weeks: 2 }
+		};
+		options.defaultView = 'basicTwoWeek';
+		$('#cal').fullCalendar(options);
+		expect($('h2')).toHaveText('defaultitle');
+	});
+
+	it('renders a 4 day agenda view', function() {
+		options.views.agendaFourDay = {
+			type: 'agenda',
+			duration: { days: 4 }
+		};
+		options.defaultView = 'agendaFourDay';
+		options.defaultDate = '2014-12-25';
+		$('#cal').fullCalendar(options);
+		expect($('.fc-day-grid .fc-row').length).toBe(1);
+		expect($('.fc-day-grid .fc-row .fc-day').length).toBe(4);
+		expect($('.fc-time-grid .fc-day').length).toBe(4);
+		expect($('.fc-time-grid .fc-day:first')).toBeMatchedBy('[data-date="2014-12-25"]'); // starts on defaultDate
+	});
+
+	it('renders a two week agenda view', function() {
+		options.views.agendaTwoWeek = {
+			type: 'agenda',
+			duration: { weeks: 2 }
+		};
+		options.defaultView = 'agendaTwoWeek';
+		options.defaultDate = '2014-12-25';
+		$('#cal').fullCalendar(options);
+		expect($('.fc-day-grid .fc-row').length).toBe(1);
+		expect($('.fc-day-grid .fc-row .fc-day').length).toBe(14); // one long row
+		expect($('.fc-time-grid .fc-day').length).toBe(14);
+		expect($('.fc-time-grid .fc-day:first')).toBeMatchedBy('[data-date="2014-12-21"]'); // week start
+	});
+});

+ 104 - 0
tests/automated/views-specific-options.js

@@ -0,0 +1,104 @@
+describe('view-specific options', function() {
+	var options;
+
+	beforeEach(function() {
+		options = {
+			header: {
+				left: 'prev,next',
+				center: 'title',
+				right: 'month,basicWeek,basicDay,agendaWeek,agendaDay'
+			},
+			defaultView: 'month',
+			titleFormat: '[default]',
+			views: { }
+		};
+		affix('#cal');
+	});
+
+	function testEachView(viewsAndVals) {
+		$('#cal').fullCalendar(options);
+		for (var view in viewsAndVals) {
+			var val = viewsAndVals[view];
+			$('#cal').fullCalendar('changeView', view);
+			expect($('h2')).toHaveText(val);
+		}
+	}
+
+	it('can target a specific view (month)', function() {
+		options.views.month = {
+			titleFormat: '[special!!!]'
+		};
+		testEachView({
+			month: 'special!!!',
+			basicWeek: 'default',
+			basicDay: 'default',
+			agendaWeek: 'default',
+			agendaDay: 'default'
+		});
+	});
+
+	it('can target a specific view (agendaWeek)', function() {
+		options.views.agendaWeek = {
+			titleFormat: '[special!!!]'
+		};
+		testEachView({
+			month: 'default',
+			basicWeek: 'default',
+			basicDay: 'default',
+			agendaWeek: 'special!!!',
+			agendaDay: 'default'
+		});
+	});
+
+	it('can target basic views', function() {
+		options.views.basic = {
+			titleFormat: '[special!!!]'
+		};
+		testEachView({
+			month: 'default', // will NOT target month view
+			basicWeek: 'special!!!',
+			basicDay: 'special!!!',
+			agendaWeek: 'default',
+			agendaDay: 'default'
+		});
+	});
+
+	it('can target agenda views', function() {
+		options.views.agenda = {
+			titleFormat: '[special!!!]'
+		};
+		testEachView({
+			month: 'default',
+			basicWeek: 'default',
+			basicDay: 'default',
+			agendaWeek: 'special!!!',
+			agendaDay: 'special!!!'
+		});
+	});
+
+	it('can target week views', function() {
+		options.views.week = {
+			titleFormat: '[special!!!]'
+		};
+		testEachView({
+			month: 'default',
+			basicWeek: 'special!!!',
+			basicDay: 'default',
+			agendaWeek: 'special!!!',
+			agendaDay: 'default'
+		});
+	});
+
+	it('can target day views', function() {
+		options.views.day = {
+			titleFormat: '[special!!!]'
+		};
+		testEachView({
+			month: 'default',
+			basicWeek: 'default',
+			basicDay: 'special!!!',
+			agendaWeek: 'default',
+			agendaDay: 'special!!!'
+		});
+	});
+});