Browse Source

test for new event mutation code, className transfer behavior

Adam Shaw 8 years ago
parent
commit
27aa278e6d
2 changed files with 120 additions and 3 deletions
  1. 116 0
      tests/event-data/updateEvent.js
  2. 4 3
      tests/legacy/updateEvent.js

+ 116 - 0
tests/event-data/updateEvent.js

@@ -113,4 +113,120 @@ describe('updateEvent', function() {
 			});
 		});
 	});
+
+	describe('when adding a new misc object property', function() {
+
+		it('accepts the new property', function() {
+			var event;
+
+			initCalendar({
+				now: '2017-10-05',
+				events: [
+					{ title: 'event 0', start: '2017-10-05' }
+				]
+			});
+
+			event = currentCalendar.clientEvents()[0];
+			event.user = { fname: 'Adam' };
+			currentCalendar.updateEvent(event);
+
+			event = currentCalendar.clientEvents()[0];
+			expect(typeof event.user).toBe('object');
+			expect(event.user.fname).toBe('Adam');
+		})
+	});
+
+	describe('when modifying an existing misc object property', function() {
+
+		it('accepts the new property', function() {
+			var event;
+
+			initCalendar({
+				now: '2017-10-05',
+				events: [
+					{ title: 'event 0', start: '2017-10-05', user: { fname: 'Adam' } }
+				]
+			});
+
+			event = currentCalendar.clientEvents()[0];
+			expect(typeof event.user).toBe('object');
+			expect(event.user.fname).toBe('Adam');
+
+			event.user = { fname: 'John' };
+			currentCalendar.updateEvent(event);
+
+			event = currentCalendar.clientEvents()[0];
+			expect(typeof event.user).toBe('object');
+			expect(event.user.fname).toBe('John');
+		})
+	});
+
+	describe('with className', function() {
+
+		describe('when not modified', function() {
+			it('maintains classNames for individual event defs', function() {
+				var eventA, eventB;
+
+				initCalendar({
+					now: '2017-10-05',
+					events: [
+						{ id: '1', title: 'event1', start: '2017-10-05', otherId: 'a', customProp: 'asdf', className: 'myclassA' },
+						{ id: '1', title: 'event1', start: '2017-10-12', otherId: 'b', customProp: 'asdf', className: 'myclassB' }
+					]
+				});
+
+				eventA = currentCalendar.clientEvents(function(eventDef) {
+					return eventDef.otherId === 'a';
+				})[0];
+
+				eventA.customProp = 'qwer';
+				currentCalendar.updateEvent(eventA);
+
+				eventA = currentCalendar.clientEvents(function(eventDef) {
+					return eventDef.otherId === 'a';
+				})[0];
+
+				eventB = currentCalendar.clientEvents(function(eventDef) {
+					return eventDef.otherId === 'b';
+				})[0];
+
+				expect(eventA.customProp).toBe('qwer');
+				expect(eventA.className).toEqual([ 'myclassA' ]);
+				expect(eventB.customProp).toBe('qwer');
+				expect(eventB.className).toEqual([ 'myclassB' ]);
+			});
+		});
+
+		describe('when modified', function() {
+			it('changes classNames for all similar event defs', function() {
+				var eventA, eventB;
+
+				initCalendar({
+					now: '2017-10-05',
+					events: [
+						{ id: '1', title: 'event1', start: '2017-10-05', otherId: 'a', className: 'myclassA' },
+						{ id: '1', title: 'event1', start: '2017-10-12', otherId: 'b', className: 'myclassB' }
+					]
+				});
+
+				eventA = currentCalendar.clientEvents(function(eventDef) {
+					return eventDef.otherId === 'a';
+				})[0];
+
+				eventA.className = [ 'otherClass' ];
+				currentCalendar.updateEvent(eventA);
+
+				eventA = currentCalendar.clientEvents(function(eventDef) {
+					return eventDef.otherId === 'a';
+				})[0];
+
+				eventB = currentCalendar.clientEvents(function(eventDef) {
+					return eventDef.otherId === 'b';
+				})[0];
+
+				expect(eventA.className).toEqual([ 'otherClass' ]);
+				expect(eventB.className).toEqual([ 'otherClass' ]);
+			});
+		});
+	});
 });

+ 4 - 3
tests/legacy/updateEvent.js

@@ -556,8 +556,9 @@ describe('updateEvent', function() {
 		expect(relatedEvent.color).toBe('red');
 	});
 
-	it('should non-standard properties to related events', function() {
+	it('should copy non-standard properties to related events', function() {
 		var event, relatedEvent;
+		var specialObj = {};
 
 		options.events = [
 			{ id: '1', start: '2014-05-01', end: '2014-05-03', allDay: true, className: 'mainEvent' },
@@ -567,12 +568,12 @@ describe('updateEvent', function() {
 
 		event = getMainEvent();
 		event.someForeignKey = '123';
-		event.myObj = {};
+		event.myObj = specialObj;
 		$('#cal').fullCalendar('updateEvent', event);
 
 		relatedEvent = getRelatedEvent();
 		expect(relatedEvent.someForeignKey).toBe('123');
-		expect(relatedEvent.myObj).toBeUndefined();
+		expect(relatedEvent.myObj).toBe(specialObj);
 	});
 
 	function whenMovingStart(should) {