Przeglądaj źródła

automated tests for viewRender and viewDestroy

Adam Shaw 11 lat temu
rodzic
commit
3051966f2d
2 zmienionych plików z 105 dodań i 0 usunięć
  1. 60 0
      tests/automated/viewDestroy.js
  2. 45 0
      tests/automated/viewRender.js

+ 60 - 0
tests/automated/viewDestroy.js

@@ -0,0 +1,60 @@
+
+describe('viewDestroy', function() {
+	var options;
+
+	beforeEach(function() {
+		options = {
+			defaultDate: '2015-02-20'
+		};
+		affix('#cal');
+	});
+
+	describe('when in month view', function() {
+		beforeEach(function() {
+			options = {
+				defaultView: 'month'
+			};
+		});
+		defineTests();
+	});
+
+	describe('when in agendaWeek view', function() {
+		beforeEach(function() {
+			options = {
+				defaultView: 'agendaWeek'
+			};
+		});
+		defineTests();
+	});
+
+	function defineTests() {
+
+		it('fires before the view is unrendered, with correct arguments', function(done) {
+			var viewRenderCalls = 0;
+			var viewDestroyCalls = 0;
+
+			options.viewRender = function() {
+				++viewRenderCalls;
+			};
+
+			options.viewDestroy = function(givenViewObj, givenViewEl) {
+				if (++viewDestroyCalls === 1) { // because done() calls destroy
+
+					// the viewDestroy should be called before the next viewRender
+					expect(viewRenderCalls).toBe(1);
+
+					var viewObj = $('#cal').fullCalendar('getView');
+					var viewEl = $('#cal .fc-view');
+
+					expect(viewObj).toBe(givenViewObj);
+					expect(viewEl[0]).toBe(givenViewEl[0]);
+					expect(viewEl.children().length >= 1).toBe(true); // is the content still rendered?
+					done();
+				}
+			};
+
+			$('#cal').fullCalendar(options);
+			$('#cal').fullCalendar('next'); // will trigger a viewDestroy/viewRender
+		});
+	}
+});

+ 45 - 0
tests/automated/viewRender.js

@@ -0,0 +1,45 @@
+
+describe('viewRender', function() {
+	var options;
+
+	beforeEach(function() {
+		options = {
+			defaultDate: '2015-02-20'
+		};
+		affix('#cal');
+	});
+
+	describe('when in month view', function() {
+		beforeEach(function() {
+			options = {
+				defaultView: 'month'
+			};
+		});
+		defineTests();
+	});
+
+	describe('when in agendaWeek view', function() {
+		beforeEach(function() {
+			options = {
+				defaultView: 'agendaWeek'
+			};
+		});
+		defineTests();
+	});
+
+	function defineTests() {
+
+		it('fires after the view is rendered, with correct arguments', function(done) {
+			options.viewRender = function(givenViewObj, givenViewEl) {
+				var viewObj = $('#cal').fullCalendar('getView');
+				var viewEl = $('#cal .fc-view');
+
+				expect(viewObj).toBe(givenViewObj);
+				expect(viewEl[0]).toBe(givenViewEl[0]);
+				expect(viewEl.children().length >= 1).toBe(true); // has it rendered content?
+				done();
+			};
+			$('#cal').fullCalendar(options);
+		});
+	}
+});