Просмотр исходного кода

unselect callback should receive ev arg. closes #3832

Adam Shaw 8 лет назад
Родитель
Сommit
b0732586c6
2 измененных файлов с 41 добавлено и 11 удалено
  1. 2 2
      src/component/interactions/DateSelecting.js
  2. 39 9
      tests/legacy/unselectAuto.js

+ 2 - 2
src/component/interactions/DateSelecting.js

@@ -70,8 +70,8 @@ var DateSelecting = FC.DateSelecting = Interaction.extend({
 			interactionStart: function() {
 				selectionFootprint = null;
 			},
-			dragStart: function() {
-				_this.view.unselect(); // since we could be rendering a new selection, we want to clear any old one
+			dragStart: function(ev) {
+				_this.view.unselect(ev); // since we could be rendering a new selection, we want to clear any old one
 			},
 			hitOver: function(hit, isOrig, origHit) {
 				var origHitFootprint;

+ 39 - 9
tests/legacy/unselectAuto.js

@@ -1,5 +1,6 @@
 
 describe('unselectAuto', function() {
+	var View = $.fullCalendar.View;
 	var options;
 
 	beforeEach(function() {
@@ -18,18 +19,47 @@ describe('unselectAuto', function() {
 			options.unselectAuto = true;
 		});
 
-		it('unselects the current selection when clicking elsewhere in DOM', function() {
-			$('#cal').fullCalendar(options);
-			$('#cal').fullCalendar('select', '2014-12-01', '2014-12-03');
+		describe('when clicking away', function() {
+			it('unselects the current selection when clicking elsewhere in DOM', function(done) {
+				options.unselect = function(ev, view) {
+					expect($('.fc-highlight').length).toBe(0);
 
-			expect($('.fc-highlight').length).toBeGreaterThan(0);
+					expect('currentTarget' in ev).toBe(true); // a JS event
+					expect(view instanceof View).toBe(true);
 
-			$('#otherthing')
-				.simulate('mousedown')
-				.simulate('mouseup')
-				.simulate('click');
+					done();
+				};
+
+				$('#cal').fullCalendar(options);
+				$('#cal').fullCalendar('select', '2014-12-01', '2014-12-03');
+
+				expect($('.fc-highlight').length).toBeGreaterThan(0);
+
+				$('#otherthing')
+					.simulate('mousedown')
+					.simulate('mouseup')
+					.simulate('click');
+			});
+		});
+
+		describe('when clicking another date', function() {
+			it('unselects the current selection when clicking elsewhere in DOM', function(done) {
+				options.unselect = function(ev, view) {
+					expect($('.fc-highlight').length).toBe(0);
+
+					expect('currentTarget' in ev).toBe(true); // a JS event
+					expect(view instanceof View).toBe(true);
+
+					done();
+				};
+
+				$('#cal').fullCalendar(options);
+				$('#cal').fullCalendar('select', '2014-12-01', '2014-12-03');
+
+				expect($('.fc-highlight').length).toBeGreaterThan(0);
 
-			expect($('.fc-highlight').length).toBe(0);
+				$('.fc-day[data-date="2014-12-04"]').simulate('drag');
+			});
 		});
 	});