From 723a13e488463331d19dbab835ce1b9c614a4d9f Mon Sep 17 00:00:00 2001 From: Adam Shaw Date: Sun, 25 May 2014 09:59:43 -0700 Subject: [PATCH] tests for forceEventDuration, defaultAllDayEventDuration, defaultTimedEventDuration --- tests/automated/defaultAllDayEventDuration.js | 87 +++++++++++++ tests/automated/defaultTimedEventDuration.js | 117 ++++++++++++++++++ tests/automated/forceEventDuration.js | 64 ++++++++++ 3 files changed, 268 insertions(+) create mode 100644 tests/automated/defaultAllDayEventDuration.js create mode 100644 tests/automated/defaultTimedEventDuration.js create mode 100644 tests/automated/forceEventDuration.js diff --git a/tests/automated/defaultAllDayEventDuration.js b/tests/automated/defaultAllDayEventDuration.js new file mode 100644 index 0000000..c2914e9 --- /dev/null +++ b/tests/automated/defaultAllDayEventDuration.js @@ -0,0 +1,87 @@ +describe('defaultAllDayEventDuration', function() { + + var options; + + beforeEach(function() { + affix('#cal'); + + options = { + defaultDate: '2014-05-01', + defaultView: 'month' + }; + }); + + describe('when forceEventDuration is on', function() { + + beforeEach(function() { + options.forceEventDuration = true; + }); + + it('correctly calculates an unspecified end when using a Duration object input', function() { + options.defaultAllDayEventDuration = { days: 2 }; + options.events = [ + { + allDay: true, + start: '2014-05-05' + } + ]; + $('#cal').fullCalendar(options); + var event = $('#cal').fullCalendar('clientEvents')[0]; + expect(event.end).toEqualMoment('2014-05-07'); + }); + + it('correctly calculates an unspecified end when using a string Duration input', function() { + options.defaultAllDayEventDuration = '3.00:00:00'; + options.events = [ + { + allDay: true, + start: '2014-05-05' + } + ]; + $('#cal').fullCalendar(options); + var event = $('#cal').fullCalendar('clientEvents')[0]; + expect(event.end).toEqualMoment('2014-05-08'); + }); + }); + + describe('when forceEventDuration is off', function() { + + beforeEach(function() { + options.forceEventDuration = false; + }); + + [ 'basicWeek', 'agendaWeek' ].forEach(function(viewName) { // because they render all-day events in similar ways + describe('with ' + viewName + ' view', function() { + beforeEach(function() { + options.defaultView = viewName; + }); + it('renders an all-day event with no `end` to appear to have the default duration', function(done) { + options.defaultAllDayEventDuration = { days: 2 }; + options.events = [ + { + // a control. so we know how wide it should be + title: 'control event', + allDay: true, + start: '2014-04-28', + end: '2014-04-30' + }, + { + // one day after the control. no specified end + title: 'test event', + allDay: true, + start: '2014-04-28' + } + ]; + options.eventAfterAllRender = function() { + var eventElms = $('#cal .fc-event'); + var width0 = eventElms.eq(0).outerWidth(); + var width1 = eventElms.eq(1).outerWidth(); + expect(width0).toEqual(width1); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + }); + }); +}); \ No newline at end of file diff --git a/tests/automated/defaultTimedEventDuration.js b/tests/automated/defaultTimedEventDuration.js new file mode 100644 index 0000000..5c2484c --- /dev/null +++ b/tests/automated/defaultTimedEventDuration.js @@ -0,0 +1,117 @@ +describe('defaultTimedEventDuration', function() { + + var options; + + beforeEach(function() { + affix('#cal'); + + options = { + defaultDate: '2014-05-01', + defaultView: 'month' + }; + }); + + describe('when forceEventDuration is on', function() { + + beforeEach(function() { + options.forceEventDuration = true; + }); + + it('correctly calculates an unspecified end when using a Duration object input', function() { + options.defaultTimedEventDuration = { hours: 2, minutes: 30 }; + options.events = [ + { + allDay: false, + start: '2014-05-05T04:00:00' + } + ]; + $('#cal').fullCalendar(options); + var event = $('#cal').fullCalendar('clientEvents')[0]; + expect(event.end).toEqualMoment('2014-05-05T06:30:00'); + }); + + it('correctly calculates an unspecified end when using a string Duration input', function() { + options.defaultTimedEventDuration = '03:15:00'; + options.events = [ + { + allDay: false, + start: '2014-05-05T04:00:00' + } + ]; + $('#cal').fullCalendar(options); + var event = $('#cal').fullCalendar('clientEvents')[0]; + expect(event.end).toEqualMoment('2014-05-05T07:15:00'); + }); + }); + + describe('when forceEventDuration is off', function() { + + beforeEach(function() { + options.forceEventDuration = false; + }); + + describe('with agendaWeek view', function() { + beforeEach(function() { + options.defaultView = 'agendaWeek'; + }); + it('renders a timed event with no `end` to appear to have the default duration', function(done) { + options.defaultTimedEventDuration = '01:15:00'; + options.events = [ + { + // a control. so we know how tall it should be + title: 'control event', + allDay: false, + start: '2014-05-01T04:00:00', + end: '2014-05-01T05:15:00' + }, + { + // one day after the control. no specified end + title: 'test event', + allDay: false, + start: '2014-05-02T04:00:00' + } + ]; + options.eventAfterAllRender = function() { + var eventElms = $('#cal .fc-event'); + var height0 = eventElms.eq(0).outerHeight(); + var height1 = eventElms.eq(1).outerHeight(); + expect(height0).toEqual(height1); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + + describe('with basicWeek view', function() { + beforeEach(function() { + options.defaultView = 'basicWeek'; + }); + it('renders a timed event with no `end` to appear to have the default duration', function(done) { + options.defaultTimedEventDuration = { days: 2 }; + options.events = [ + { + // a control. so we know how wide it should be + title: 'control event', + allDay: false, + start: '2014-04-28T04:00:00', + end: '2014-04-30T00:00:00' + }, + { + // one day after the control. no specified end + title: 'test event', + allDay: false, + start: '2014-04-28T04:00:00' + } + ]; + options.eventAfterAllRender = function() { + var eventElms = $('#cal .fc-event'); + var width0 = eventElms.eq(0).outerWidth(); + var width1 = eventElms.eq(1).outerWidth(); + expect(width0).toEqual(width1); + done(); + }; + $('#cal').fullCalendar(options); + }); + }); + }); +}); \ No newline at end of file diff --git a/tests/automated/forceEventDuration.js b/tests/automated/forceEventDuration.js new file mode 100644 index 0000000..2ab6386 --- /dev/null +++ b/tests/automated/forceEventDuration.js @@ -0,0 +1,64 @@ +ddescribe('forceEventDuration', function() { + + var options; + + beforeEach(function() { + affix('#cal'); + + options = { + defaultDate: '2014-05-01', + defaultView: 'month' + }; + }); + + describe('when turned off', function() { + beforeEach(function() { + options.forceEventDuration = false; + }); + it('allows a null end date for all-day and timed events', function() { + options.events = [ + { + id: '1', + start: '2014-05-10' + }, + { + id: '2', + start: '2014-05-10T14:00:00' + } + ]; + $('#cal').fullCalendar(options); + var events = $('#cal').fullCalendar('clientEvents'); + expect(events[0].end).toBeNull(); + expect(events[1].end).toBeNull(); + }); + }); + + describe('when turned on', function() { + beforeEach(function() { + options.forceEventDuration = true; + }); + it('allows a null end date for all-day and timed events', function() { + options.events = [ + { + id: '1', + start: '2014-05-10' + }, + { + id: '2', + start: '2014-05-10T14:00:00' + } + ]; + $('#cal').fullCalendar(options); + var events = $('#cal').fullCalendar('clientEvents'); + expect(events[0].id).toEqual('1'); + expect(moment.isMoment(events[0].end)).toEqual(true); + expect(events[1].id).toEqual('2'); + expect(moment.isMoment(events[1].end)).toEqual(true); + }); + }); + + // NOTE: the actual verification of the correct calculation of the end + // (using defaultTimedEventDuration and defaultAllDayEventDuration) + // is done in those test files. + +}); \ No newline at end of file