From c9d577c278cc1b0714be85cd4ba1d98bf2ac9c2d Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Sat, 24 May 2014 23:04:42 -0700 Subject: [PATCH] tests for event object creation --- tests/automated/event-obj.js | 109 +++++++++++++++++++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 tests/automated/event-obj.js diff --git a/tests/automated/event-obj.js b/tests/automated/event-obj.js new file mode 100644 index 0000000..67c2eb5 --- /dev/null +++ b/tests/automated/event-obj.js @@ -0,0 +1,109 @@ +describe('event object creation', function() { + + /* + + NOTE: Where possible, if there is a specific option that affects event object creation + behavior, write your tests in the individual file for that option, instead of here. + Examples of this: + allDayDefault (tests allDay guessing behavior too) + eventDataTransform + forceEventDuration + + */ + + var event; + + beforeEach(function() { + affix('#cal'); + event = null; + }); + + function init(singleEventData) { + $('#cal').fullCalendar({ + events: [ singleEventData ] + }); + event = $('#cal').fullCalendar('clientEvents')[0]; + } + + it('accepts `date` property as alias for `start`', function() { + init({ + date: '2014-05-05' + }); + expect(moment.isMoment(event.start)).toEqual(true); + expect(event.start).toEqualMoment('2014-05-05'); + }); + + it('doesn\'t produce an event when an invalid start', function() { + init({ + start: 'asdf' + }); + expect(event).toBeUndefined(); + }); + + it('doesn\'t produce an event when an invalid end', function() { + init({ + end: 'asdf' + }); + expect(event).toBeUndefined(); + }); + + it('strips times of dates when event is all-day', function() { + init({ + start: '2014-05-01T01:00:00-12:00', + end: '2014-05-02T01:00:00+12:00', + allDay: true + }); + expect(event.start.hasTime()).toEqual(false); + expect(event.start).toEqualMoment('2014-05-01'); + expect(event.end.hasTime()).toEqual(false); + expect(event.end).toEqualMoment('2014-05-02'); + }); + + it('gives 00:00 times to ambiguously-timed dates when event is timed', function() { + init({ + start: '2014-05-01', + end: '2014-05-03', + allDay: false + }); + expect(event.start.hasTime()).toEqual(true); + expect(event.start).toEqualMoment('2014-05-01T00:00:00'); + expect(event.end.hasTime()).toEqual(true); + expect(event.end).toEqualMoment('2014-05-03T00:00:00'); + }); + + it('sets the source', function() { + init({ + start: '2014-05-01' + }); + expect(typeof event.source).toEqual('object'); + }); + + it('accepts an array `className`', function() { + init({ + start: '2014-05-01', + className: [ 'class1', 'class2' ] + }); + expect($.isArray(event.className)).toEqual(true); + expect(event.className).toEqual([ 'class1', 'class2' ]); + }); + + it('accepts a string `className`', function() { + init({ + start: '2014-05-01', + className: 'class1 class2' + }); + expect($.isArray(event.className)).toEqual(true); + expect(event.className).toEqual([ 'class1', 'class2' ]); + }); + + it('copies over custom properties', function() { + init({ + start: '2014-05-01', + prop1: 'prop1val', + prop2: [ 'a', 'b' ] + }); + expect(event.prop1).toEqual('prop1val'); + expect(event.prop2).toEqual([ 'a', 'b' ]); + }); + +}); \ No newline at end of file