Jelajahi Sumber

Merge branch 'master' of https://github.com/acerix/fullcalendar

Adam Shaw 8 tahun lalu
induk
melakukan
52b5c31443

+ 44 - 44
tests/legacy/defaultAllDayEventDuration.js

@@ -1,63 +1,63 @@
 describe('defaultAllDayEventDuration', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-
-    options = {
-      defaultDate: '2014-05-01',
-      defaultView: 'month'
-    }
+  pushOptions({
+    defaultDate: '2014-05-01',
+    defaultView: 'month'
   })
 
   describe('when forceEventDuration is on', function() {
 
-    beforeEach(function() {
-      options.forceEventDuration = true
+    pushOptions({
+      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]
+
+      initCalendar({
+        defaultAllDayEventDuration: { days: 2 },
+        events: [
+          {
+            allDay: true,
+            start: '2014-05-05'
+          }
+        ]
+      })
+
+      var event = currentCalendar.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]
+
+      initCalendar({
+        defaultAllDayEventDuration: '3.00:00:00',
+        events: [
+          {
+            allDay: true,
+            start: '2014-05-05'
+          }
+        ]
+      })
+
+      var event = currentCalendar.clientEvents()[0]
       expect(event.end).toEqualMoment('2014-05-08')
     })
   })
 
   describe('when forceEventDuration is off', function() {
 
-    beforeEach(function() {
-      options.forceEventDuration = false
-    });
+    pushOptions({
+      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 = [
+    describeOptions('defaultView', {
+      'with basicWeek view': 'basicWeek',
+      'with agendaWeek view': 'agendaWeek'
+    }, function() {
+      it('renders an all-day event with no `end` to appear to have the default duration', function(done) {
+        initCalendar({
+          defaultAllDayEventDuration: { days: 2 },
+          events: [
             {
               // a control. so we know how wide it should be
               title: 'control event',
@@ -71,15 +71,15 @@ describe('defaultAllDayEventDuration', function() {
               allDay: true,
               start: '2014-04-28'
             }
-          ]
-          options.eventAfterAllRender = function() {
-            var eventElms = $('#cal .fc-event')
+          ],
+          eventAfterAllRender: function() {
+            var eventElms = $('.fc-event', currentCalendar.el)
             var width0 = eventElms.eq(0).outerWidth()
             var width1 = eventElms.eq(1).outerWidth()
+            expect(width0).toBeGreaterThan(0)
             expect(width0).toEqual(width1)
             done()
           }
-          $('#cal').fullCalendar(options)
         })
       })
     })

+ 86 - 81
tests/legacy/defaultTimedEventDuration.js

@@ -1,116 +1,121 @@
 describe('defaultTimedEventDuration', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-
-    options = {
-      defaultDate: '2014-05-01',
-      defaultView: 'month'
-    }
+  pushOptions({
+    defaultDate: '2014-05-01',
+    defaultView: 'month'
   })
 
   describe('when forceEventDuration is on', function() {
 
-    beforeEach(function() {
-      options.forceEventDuration = true
+    pushOptions({
+      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]
+      initCalendar({
+        defaultTimedEventDuration: { hours: 2, minutes: 30 },
+        events: [
+          {
+            allDay: false,
+            start: '2014-05-05T04:00:00'
+          }
+        ]
+      })
+      var event = currentCalendar.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]
+      initCalendar({
+        defaultTimedEventDuration: '03:15:00',
+        events: [
+          {
+            allDay: false,
+            start: '2014-05-05T04:00:00'
+          }
+        ]
+      })
+      var event = currentCalendar.clientEvents()[0]
       expect(event.end).toEqualMoment('2014-05-05T07:15:00')
     })
   })
 
   describe('when forceEventDuration is off', function() {
 
-    beforeEach(function() {
-      options.forceEventDuration = false
+    pushOptions({
+      forceEventDuration: false
     })
 
     describe('with agendaWeek view', function() {
-      beforeEach(function() {
-        options.defaultView = 'agendaWeek'
+
+      pushOptions({
+        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'
+        initCalendar({
+          defaultTimedEventDuration: '01:15:00',
+          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'
+            }
+          ],
+          eventAfterAllRender: function() {
+            var eventElms = $('.fc-event', currentCalendar.el)
+            var height0 = eventElms.eq(0).outerHeight()
+            var height1 = eventElms.eq(1).outerHeight()
+            expect(height0).toBeGreaterThan(0)
+            expect(height0).toEqual(height1)
+            done()
           }
-        ]
-        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'
+
+      pushOptions({
+        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'
+
+        initCalendar({
+          defaultTimedEventDuration: { days: 2 },
+          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'
+            }
+          ],
+          eventAfterAllRender: function() {
+            var eventElms = $('.fc-event', currentCalendar.el)
+            var width0 = eventElms.eq(0).outerWidth()
+            var width1 = eventElms.eq(1).outerWidth()
+            expect(width0).toBeGreaterThan(0)
+            expect(width0).toEqual(width1)
+            done()
           }
-        ]
-        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)
+        })
       })
     })
   })

+ 54 - 62
tests/legacy/destroy.js

@@ -2,27 +2,23 @@ import { countHandlers } from '../lib/dom-misc'
 
 describe('destroy', function() {
 
-  beforeEach(function() {
-    affix('#cal')
-  })
-
   describe('when calendar is LTR', function() {
     it('cleans up all classNames on the root element', function() {
-      $('#cal').fullCalendar({
+      initCalendar({
         isRTL: false
       })
-      $('#cal').fullCalendar('destroy')
-      expect($('#cal')[0].className).toBe('')
+      currentCalendar.destroy()
+      expect($('#calendar')[0].className).toBe('')
     })
   })
 
   describe('when calendar is RTL', function() {
     it('cleans up all classNames on the root element', function() {
-      $('#cal').fullCalendar({
+      initCalendar({
         isRTL: true
       })
-      $('#cal').fullCalendar('destroy')
-      expect($('#cal')[0].className).toBe('')
+      currentCalendar.destroy()
+      expect($('#calendar')[0].className).toBe('')
     })
   })
 
@@ -32,71 +28,67 @@ describe('destroy', function() {
   }, function() {
     it('cleans up all classNames on the root element', function() {
       initCalendar()
-      $('#cal').fullCalendar('destroy')
-      expect($('#cal')[0].className).toBe('')
+      currentCalendar.destroy()
+      expect($('#calendar')[0].className).toBe('')
     })
-  });
-
-  [ 'month', 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
-
-    describe('when in ' + viewName + ' view', function() {
-      var options
-
-      beforeEach(function() {
-        options = {
-          defaultView: viewName,
-          defaultDate: '2014-12-01',
-          droppable: true, // likely to attach document handler
-          editable: true, // same
-          events: [
-            { title: 'event1', start: '2014-12-01' }
-          ]
-        }
-      })
-
-      it('leaves no handlers attached to DOM', function(done) {
-        setTimeout(function() { // in case there are delayed attached handlers
+  })
 
-          var origDocCnt = countHandlers(document)
-          var origElCnt = countHandlers('#cal')
+  pushOptions({
+    defaultDate: '2014-12-01',
+    droppable: true, // likely to attach document handler
+    editable: true, // same
+    events: [
+      { title: 'event1', start: '2014-12-01' }
+    ]
+  })
 
-          $('#cal').fullCalendar(options)
+  describeOptions('defaultView', {
+    'when in month view': 'month',
+    'when in basicWeek view': 'basicWeek',
+    'when in agendaWeek view': 'agendaWeek'
+  }, function() {
+    it('leaves no handlers attached to DOM', function(done) {
+      setTimeout(function() { // in case there are delayed attached handlers
+        var $el = $('<div id="calendar">').appendTo('body')
+        var origDocCnt = countHandlers(document)
+        var origElCnt = countHandlers('#calendar')
 
-          $('#cal').fullCalendar('destroy')
-          setTimeout(function() { // might not have detached handlers synchronously
+        initCalendar({}, $el)
 
-            expect(countHandlers(document)).toBe(origDocCnt)
-            expect(countHandlers('#cal')).toBe(origElCnt)
+        currentCalendar.destroy()
 
-            done()
-          }, 100)
+        setTimeout(function() { // might not have detached handlers synchronously
+          expect(countHandlers(document)).toBe(origDocCnt)
+          expect(countHandlers('#calendar')).toBe(origElCnt)
+          done()
         }, 100)
-      })
 
-      // Issue 2432
-      it('preserves existing window handlers when handleWindowResize is off', function(done) {
-        var resizeHandler = function() { }
-        var handlerCnt0 = countHandlers(window)
-        var handlerCnt1
-        var handlerCnt2
+      }, 100)
+    })
 
-        $(window).on('resize', resizeHandler)
-        handlerCnt1 = countHandlers(window)
-        expect(handlerCnt1).toBe(handlerCnt0 + 1)
+    // Issue 2432
+    it('preserves existing window handlers when handleWindowResize is off', function(done) {
+      var resizeHandler = function() {}
+      var handlerCnt0 = countHandlers(window)
+      var handlerCnt1
+      var handlerCnt2
 
-        $('#cal').fullCalendar({
-          handleWindowResize: false
-        })
+      $(window).on('resize', resizeHandler)
+      handlerCnt1 = countHandlers(window)
+      expect(handlerCnt1).toBe(handlerCnt0 + 1)
 
-        $('#cal').fullCalendar('destroy')
-        setTimeout(function() { // might not have detached handlers synchronously
+      initCalendar({
+        handleWindowResize: false
+      })
 
-          handlerCnt2 = countHandlers(window)
-          expect(handlerCnt2).toBe(handlerCnt1)
+      currentCalendar.destroy()
+
+      setTimeout(function() { // might not have detached handlers synchronously
+        handlerCnt2 = countHandlers(window)
+        expect(handlerCnt2).toBe(handlerCnt1)
+        done()
+      }, 100)
 
-          done()
-        }, 100)
-      })
     })
   })
 

+ 64 - 80
tests/legacy/displayEventEnd.js

@@ -1,157 +1,141 @@
 describe('displayEventEnd', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultDate: '2014-06-13',
-      timeFormat: 'H:mm'
-    }
+  pushOptions({
+    defaultDate: '2014-06-13',
+    timeFormat: 'H:mm'
   })
 
-  afterEach(function() {
-    $('#cal').fullCalendar('destroy')
-  });
+  describeOptions('defaultView', {
+    'when in month view': 'month',
+    'when in agendaWeek view': 'agendaWeek'
+  }, function() {
 
-  [ 'month', 'agendaWeek' ].forEach(function(viewName) {
-    describe('when in ' + viewName + ' view', function() {
-      beforeEach(function() {
-        options.defaultView = viewName
-      })
+    describe('when off', function() {
 
-      describe('when off', function() {
-        beforeEach(function() {
-          options.displayEventEnd = false
-        })
+      pushOptions({
+        displayEventEnd: false
+      })
 
-        describe('with an all-day event', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with an all-day event', function() {
+        it('displays no time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13',
               end: '2014-06-13',
               allDay: true
-            } ]
-          })
-          it('displays no time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time').length).toBe(0)
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
+      })
 
-        describe('with a timed event with no end time', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with a timed event with no end time', function() {
+        it('displays only the start time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13T01:00:00',
               allDay: false
-            } ]
-          })
-          it('displays only the start time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time')).toHaveText('1:00')
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
+      })
 
-        describe('with a timed event with an end time', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with a timed event with an end time', function() {
+        it('displays only the start time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13T01:00:00',
               end: '2014-06-13T02:00:00',
               allDay: false
-            } ]
-          })
-          it('displays only the start time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time')).toHaveText('1:00')
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
       })
+    })
 
-      describe('when on', function() {
-        beforeEach(function() {
-          options.displayEventEnd = true
-        })
+    describe('when on', function() {
+
+      pushOptions({
+        displayEventEnd: true
+      })
 
-        describe('with an all-day event', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with an all-day event', function() {
+        it('displays no time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13',
               end: '2014-06-13',
               allDay: true
-            } ]
-          })
-          it('displays no time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time').length).toBe(0)
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
+      })
 
-        describe('with a timed event with no end time', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with a timed event with no end time', function() {
+        it('displays only the start time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13T01:00:00',
               allDay: false
-            } ]
-          })
-          it('displays only the start time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time')).toHaveText('1:00')
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
+      })
 
-        describe('with a timed event given an invalid end time', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with a timed event given an invalid end time', function() {
+        it('displays only the start time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13T01:00:00',
               end: '2014-06-13T01:00:00',
               allDay: false
-            } ]
-          })
-          it('displays only the start time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time')).toHaveText('1:00')
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
+      })
 
-        describe('with a timed event with an end time', function() {
-          beforeEach(function() {
-            options.events = [ {
+      describe('with a timed event with an end time', function() {
+        it('displays both the start and end time text', function(done) {
+          initCalendar({
+            events: [ {
               title: 'timed event',
               start: '2014-06-13T01:00:00',
               end: '2014-06-13T02:00:00',
               allDay: false
-            } ]
-          })
-          it('displays both the start and end time text', function(done) {
-            options.eventAfterAllRender = function() {
+            } ],
+            eventAfterAllRender: function() {
               expect($('.fc-event .fc-time')).toHaveText('1:00 - 2:00')
               done()
             }
-            $('#cal').fullCalendar(options)
           })
         })
       })

+ 25 - 27
tests/legacy/event-feed-param.js

@@ -1,15 +1,11 @@
 describe('event feed params', function() {
 
-  var options
+  pushOptions({
+    defaultDate: '2014-05-01',
+    defaultView: 'month'
+  })
 
   beforeEach(function() {
-    affix('#cal')
-
-    options = {
-      defaultDate: '2014-05-01',
-      defaultView: 'month'
-    }
-
     $.mockjax({
       url: '*',
       contentType: 'text/json',
@@ -28,12 +24,13 @@ describe('event feed params', function() {
   })
 
   it('utilizes custom startParam, endParam, and timezoneParam names', function() {
-    options.events = 'my-feed.php'
-    options.timezone = 'America/Los_Angeles'
-    options.startParam = 'mystart'
-    options.endParam = 'myend'
-    options.timezoneParam = 'currtz'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      events: 'my-feed.php',
+      timezone: 'America/Los_Angeles',
+      startParam: 'mystart',
+      endParam: 'myend',
+      timezoneParam: 'currtz'
+    })
     var request = $.mockjax.mockedAjaxCalls()[0]
     expect(request.data.start).toBeUndefined()
     expect(request.data.end).toBeUndefined()
@@ -44,19 +41,20 @@ describe('event feed params', function() {
   })
 
   it('utilizes event-source-specific startParam, endParam, and timezoneParam names', function() {
-    options.timezone = 'America/Los_Angeles'
-    options.startParam = 'mystart'
-    options.endParam = 'myend'
-    options.timezoneParam = 'currtz'
-    options.eventSources = [
-      {
-        url: 'my-feed.php',
-        startParam: 'feedstart',
-        endParam: 'feedend',
-        timezoneParam: 'feedctz'
-      }
-    ]
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      timezone: 'America/Los_Angeles',
+      startParam: 'mystart',
+      endParam: 'myend',
+      timezoneParam: 'currtz',
+      eventSources: [
+        {
+          url: 'my-feed.php',
+          startParam: 'feedstart',
+          endParam: 'feedend',
+          timezoneParam: 'feedctz'
+        }
+      ]
+    })
     var request = $.mockjax.mockedAjaxCalls()[0]
     expect(request.data.start).toBeUndefined()
     expect(request.data.end).toBeUndefined()

+ 17 - 24
tests/legacy/event-obj.js

@@ -11,22 +11,15 @@ describe('event object creation', function() {
 
   */
 
-  var event
-
-  beforeEach(function() {
-    affix('#cal')
-    event = null
-  })
-
   function init(singleEventData) {
-    $('#cal').fullCalendar({
+    initCalendar({
       events: [ singleEventData ]
     })
-    event = $('#cal').fullCalendar('clientEvents')[0]
+    return currentCalendar.clientEvents()[0]
   }
 
   it('accepts `date` property as alias for `start`', function() {
-    init({
+    var event = init({
       date: '2014-05-05'
     })
     expect(moment.isMoment(event.start)).toEqual(true)
@@ -34,14 +27,14 @@ describe('event object creation', function() {
   })
 
   it('doesn\'t produce an event when an invalid start', function() {
-    init({
+    var event = init({
       start: new Date('asdf') // we use Date constructor to avoid annoying momentjs warning
     })
     expect(event).toBeUndefined()
   })
 
   it('produces null end when given an invalid date', function() {
-    init({
+    var event = init({
       start: '2014-05-01',
       end: new Date('asdf') // we use Date constructor to avoid annoying momentjs warning
     })
@@ -50,7 +43,7 @@ describe('event object creation', function() {
   })
 
   it('produces null end when given a timed end before the start', function() {
-    init({
+    var event = init({
       start: '2014-05-02T00:00:00',
       end: '2014-05-01T23:00:00'
     })
@@ -59,7 +52,7 @@ describe('event object creation', function() {
   })
 
   it('produces null end when given a timed end equal to the start', function() {
-    init({
+    var event = init({
       start: '2014-05-02T00:00:00',
       end: '2014-05-01T00:00:00'
     })
@@ -68,7 +61,7 @@ describe('event object creation', function() {
   })
 
   it('produces null end when given an all-day end before the start', function() {
-    init({
+    var event = init({
       start: '2014-05-02',
       end: '2014-05-02'
     })
@@ -77,7 +70,7 @@ describe('event object creation', function() {
   })
 
   it('produces null end when given an all-day end equal to the start', function() {
-    init({
+    var event = init({
       start: '2014-05-02T00:00:00',
       end: '2014-05-02T00:00:00'
     })
@@ -86,7 +79,7 @@ describe('event object creation', function() {
   })
 
   it('allows ASP dates for start', function() {
-    init({
+    var event = init({
       start: '/Date(1239018869048)/',
       end: '/Date(1239105269048)/'
     })
@@ -97,7 +90,7 @@ describe('event object creation', function() {
   })
 
   it('produces null end when given an invalid ASP date end', function() {
-    init({
+    var event = init({
       start: '/Date(1239018869048)/',
       end: '/Date(1239018869048)/' // same as start
     })
@@ -107,7 +100,7 @@ describe('event object creation', function() {
   })
 
   it('strips times of dates when event is all-day', function() {
-    init({
+    var event = init({
       start: '2014-05-01T01:00:00-12:00',
       end: '2014-05-02T01:00:00-12:00',
       allDay: true
@@ -119,7 +112,7 @@ describe('event object creation', function() {
   })
 
   it('gives 00:00 times to ambiguously-timed dates when event is timed', function() {
-    init({
+    var event = init({
       start: '2014-05-01',
       end: '2014-05-03',
       allDay: false
@@ -131,14 +124,14 @@ describe('event object creation', function() {
   })
 
   it('sets the source', function() {
-    init({
+    var event = init({
       start: '2014-05-01'
     })
     expect(typeof event.source).toEqual('object')
   })
 
   it('accepts an array `className`', function() {
-    init({
+    var event = init({
       start: '2014-05-01',
       className: [ 'class1', 'class2' ]
     })
@@ -147,7 +140,7 @@ describe('event object creation', function() {
   })
 
   it('accepts a string `className`', function() {
-    init({
+    var event = init({
       start: '2014-05-01',
       className: 'class1 class2'
     })
@@ -156,7 +149,7 @@ describe('event object creation', function() {
   })
 
   it('copies over custom properties', function() {
-    init({
+    var event = init({
       start: '2014-05-01',
       prop1: 'prop1val',
       prop2: [ 'a', 'b' ]

+ 27 - 27
tests/legacy/eventAllow.js

@@ -1,36 +1,34 @@
 import { dragTimeGridEvent } from '../lib/time-grid'
 
 describe('eventAllow', function() {
-  var options
-
-  beforeEach(function() {
-    options = {
-      now: '2016-09-04',
-      defaultView: 'agendaWeek',
-      scrollTime: '00:00',
-      editable: true,
-      events: [
-        {
-          title: 'event 1',
-          start: '2016-09-04T01:00'
-        }
-      ]
-    }
-    affix('#cal')
+
+  pushOptions({
+    now: '2016-09-04',
+    defaultView: 'agendaWeek',
+    scrollTime: '00:00',
+    editable: true,
+    events: [
+      {
+        title: 'event 1',
+        start: '2016-09-04T01:00'
+      }
+    ]
   })
 
   it('disallows dragging when returning false', function(done) { // and given correct params
-    options.eventAllow = function(dropInfo, event) {
-      expect(typeof dropInfo).toBe('object')
-      expect(moment.isMoment(dropInfo.start)).toBe(true)
-      expect(moment.isMoment(dropInfo.end)).toBe(true)
-      expect(typeof event).toBe('object')
-      expect(event.title).toBe('event 1')
-      return false
+    var options = {
+      eventAllow: function(dropInfo, event) {
+        expect(typeof dropInfo).toBe('object')
+        expect(moment.isMoment(dropInfo.start)).toBe(true)
+        expect(moment.isMoment(dropInfo.end)).toBe(true)
+        expect(typeof event).toBe('object')
+        expect(event.title).toBe('event 1')
+        return false
+      }
     }
     spyOn(options, 'eventAllow').and.callThrough()
 
-    $('#cal').fullCalendar(options)
+    initCalendar(options)
 
     dragTimeGridEvent($('.fc-event'), '2016-09-04T03:00:00')
       .then(function(modifiedEvent) {
@@ -41,12 +39,14 @@ describe('eventAllow', function() {
   })
 
   it('allows dragging when returning true', function(done) {
-    options.eventAllow = function(dropInfo, event) {
-      return true
+    var options = {
+      eventAllow: function(dropInfo, event) {
+        return true
+      }
     }
     spyOn(options, 'eventAllow').and.callThrough()
 
-    $('#cal').fullCalendar(options)
+    initCalendar(options)
 
     dragTimeGridEvent($('.fc-event'), '2016-09-04T03:00:00')
       .then(function(modifiedEvent) {

+ 207 - 183
tests/legacy/eventLimit-popover.js

@@ -1,68 +1,65 @@
-
 describe('eventLimit popover', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultView: 'month',
-      defaultDate: '2014-08-01',
-      eventLimit: 3,
-      events: [
-        { title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
-        { title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
-        { title: 'event3', start: '2014-07-29', className: 'event3' },
-        { title: 'event4', start: '2014-07-29', className: 'event4' }
-      ],
-      dragScroll: false, // don't do autoscrolling while dragging. close quarters in PhantomJS
-      popoverViewportConstrain: false, // because PhantomJS window is small, don't do smart repositioning
-      handleWindowResize: false // because showing the popover causes scrollbars and fires resize
-    }
+  var testEvents = [
+    { title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
+    { title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
+    { title: 'event3', start: '2014-07-29', className: 'event3' },
+    { title: 'event4', start: '2014-07-29', className: 'event4' }
+  ]
+
+  pushOptions({
+    defaultView: 'month',
+    defaultDate: '2014-08-01',
+    eventLimit: 3,
+    events: testEvents,
+    dragScroll: false, // don't do autoscrolling while dragging. close quarters in PhantomJS
+    popoverViewportConstrain: false, // because PhantomJS window is small, don't do smart repositioning
+    handleWindowResize: false // because showing the popover causes scrollbars and fires resize
   })
 
   function init() {
-    $('#cal').fullCalendar(options)
     $('.fc-more').simulate('click')
   }
 
-  [ 'month', 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
-
-    describe('when in ' + viewName + ' view', function() {
+  describeOptions('defaultView', {
+    'when in month view': 'month',
+    'when in basicWeek view': 'basicWeek',
+    'when in agendaWeek view': 'agendaWeek'
+  }, function() {
 
-      beforeEach(function() {
-        options.defaultView = viewName
-      })
-
-      it('aligns horizontally with left edge of cell if LTR', function() {
-        options.isRTL = false
-        init()
-        var cellLeft = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(2)').offset().left
-        var popoverLeft = $('.fc-more-popover').offset().left
-        var diff = Math.abs(cellLeft - popoverLeft)
-        expect(diff).toBeLessThan(2)
+    it('aligns horizontally with left edge of cell if LTR', function() {
+      initCalendar({
+        isRTL: false
       })
+      init()
+      var cellLeft = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(2)').offset().left
+      var popoverLeft = $('.fc-more-popover').offset().left
+      var diff = Math.abs(cellLeft - popoverLeft)
+      expect(diff).toBeLessThan(2)
+    })
 
-      it('aligns horizontally with left edge of cell if RTL', function() {
-        options.isRTL = true
-        init()
-        var cell = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(4)')
-        var cellRight = cell.offset().left + cell.outerWidth()
-        var popover = $('.fc-more-popover')
-        var popoverRight = popover.offset().left + popover.outerWidth()
-        var diff = Math.abs(cellRight - popoverRight)
-        expect(diff).toBeLessThan(2)
+    it('aligns horizontally with left edge of cell if RTL', function() {
+      initCalendar({
+        isRTL: true
       })
+      init()
+      var cell = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis):eq(4)')
+      var cellRight = cell.offset().left + cell.outerWidth()
+      var popover = $('.fc-more-popover')
+      var popoverRight = popover.offset().left + popover.outerWidth()
+      var diff = Math.abs(cellRight - popoverRight)
+      expect(diff).toBeLessThan(2)
     })
   })
 
   describe('when in month view', function() {
 
-    beforeEach(function() {
-      options.defaultView = 'month'
+    pushOptions({
+      defaultView: 'month'
     })
 
     it('aligns with top of cell', function() {
+      initCalendar()
       init()
       var popoverTop = $('.fc-more-popover').offset().top
       var rowTop = $('.fc-day-grid .fc-row:eq(0)').offset().top
@@ -71,81 +68,88 @@ describe('eventLimit popover', function() {
     })
 
     it('works with background events', function() {
-      options.events.push({
+      testEvents.push({
         start: '2014-07-29',
         rendering: 'background'
       })
+      initCalendar({
+        events: testEvents
+      })
       init()
       expect($('.fc-more-popover .fc-event').length).toBeGreaterThan(1)
       expect($('.fc-more-popover .fc-bgevent').length).toBe(0)
     })
 
     it('works with events that have invalid end times', function() {
-      options.events = [
-        { title: 'event1', start: '2014-07-29', end: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29', end: '2014-07-28' },
-        { title: 'event3', start: '2014-07-29T00:00:00', end: '2014-07-29T00:00:00' },
-        { title: 'event4', start: '2014-07-29T00:00:00', end: '2014-07-28T23:00:00' }
-      ]
+      initCalendar({
+        events: [
+          { title: 'event1', start: '2014-07-29', end: '2014-07-29' },
+          { title: 'event2', start: '2014-07-29', end: '2014-07-28' },
+          { title: 'event3', start: '2014-07-29T00:00:00', end: '2014-07-29T00:00:00' },
+          { title: 'event4', start: '2014-07-29T00:00:00', end: '2014-07-28T23:00:00' }
+        ]
+      })
       init()
       expect($('.fc-more-popover .fc-event').length).toBe(4)
     })
 
     // issue 2385
     it('orders events correctly regardless of ID', function() {
-      options.defaultDate = '2012-03-22'
-      options.eventLimit = 3
-      options.events = [
-        {
-          id: '39957',
-          title: 'event01',
-          start: '2012-03-22T11:00:00',
-          end: '2012-03-22T11:30:00',
-          allDay: false
-        },
-        {
-          id: '40607',
-          title: 'event02',
-          start: '2012-03-22T16:15:00',
-          end: '2012-03-22T16:30:00',
-          allDay: false
-        },
-        {
-          id: '40760',
-          title: 'event03',
-          start: '2012-03-22T16:00:00',
-          end: '2012-03-22T16:15:00',
-          allDay: false
-        },
-        {
-          id: '41284',
-          title: 'event04',
-          start: '2012-03-22T19:00:00',
-          end: '2012-03-22T19:15:00',
-          allDay: false
-        },
-        {
-          id: '41645',
-          title: 'event05',
-          start: '2012-03-22T11:30:00',
-          end: '2012-03-22T12:00:00',
-          allDay: false
-        },
-        {
-          id: '41679',
-          title: 'event07',
-          start: '2012-03-22T12:00:00',
-          end: '2012-03-22T12:15:00',
-          allDay: false
-        },
-        {
-          id: '42246',
-          title: 'event08',
-          start: '2012-03-22T16:45:00',
-          end: '2012-03-22T17:00:00',
-          allDay: false
-        }
-      ]
+      initCalendar({
+        defaultDate: '2012-03-22',
+        eventLimit: 3,
+        events: [
+          {
+            id: '39957',
+            title: 'event01',
+            start: '2012-03-22T11:00:00',
+            end: '2012-03-22T11:30:00',
+            allDay: false
+          },
+          {
+            id: '40607',
+            title: 'event02',
+            start: '2012-03-22T16:15:00',
+            end: '2012-03-22T16:30:00',
+            allDay: false
+          },
+          {
+            id: '40760',
+            title: 'event03',
+            start: '2012-03-22T16:00:00',
+            end: '2012-03-22T16:15:00',
+            allDay: false
+          },
+          {
+            id: '41284',
+            title: 'event04',
+            start: '2012-03-22T19:00:00',
+            end: '2012-03-22T19:15:00',
+            allDay: false
+          },
+          {
+            id: '41645',
+            title: 'event05',
+            start: '2012-03-22T11:30:00',
+            end: '2012-03-22T12:00:00',
+            allDay: false
+          },
+          {
+            id: '41679',
+            title: 'event07',
+            start: '2012-03-22T12:00:00',
+            end: '2012-03-22T12:15:00',
+            allDay: false
+          },
+          {
+            id: '42246',
+            title: 'event08',
+            start: '2012-03-22T16:45:00',
+            end: '2012-03-22T17:00:00',
+            allDay: false
+          }
+        ]
+      })
       init()
 
       var titles = $('.fc-more-popover .fc-event .fc-title').map(function() {
@@ -159,32 +163,33 @@ describe('eventLimit popover', function() {
 
     // https://github.com/fullcalendar/fullcalendar/issues/3856
     it('displays multi-day events only once', function() {
-      options.defaultDate = '2017-10-04'
-      options.events = [
-        {
-          title: 'Long event',
-          className: 'long-event',
-          start: '2017-10-03',
-          end: '2017-10-20'
-        },
-        {
-          title: 'Meeting',
-          className: 'meeting-event',
-          start: '2017-10-04T10:00:00',
-          end: '2017-10-04T12:00:00'
-        },
-        {
-          title: 'Lunch 1',
-          className: 'lunch1-event',
-          start: '2017-10-04T12:00:00'
-        },
-        {
-          title: 'Lunch 2',
-          className: 'lunch2-event',
-          start: '2017-10-04T14:00:00'
-        }
-      ]
-
+      initCalendar({
+        defaultDate: '2017-10-04',
+        events: [
+          {
+            title: 'Long event',
+            className: 'long-event',
+            start: '2017-10-03',
+            end: '2017-10-20'
+          },
+          {
+            title: 'Meeting',
+            className: 'meeting-event',
+            start: '2017-10-04T10:00:00',
+            end: '2017-10-04T12:00:00'
+          },
+          {
+            title: 'Lunch 1',
+            className: 'lunch1-event',
+            start: '2017-10-04T12:00:00'
+          },
+          {
+            title: 'Lunch 2',
+            className: 'lunch2-event',
+            start: '2017-10-04T14:00:00'
+          }
+        ]
+      })
       init()
 
       expect($('.fc-popover .fc-event').length).toBe(4)
@@ -208,37 +213,34 @@ describe('eventLimit popover', function() {
         expect(el).not.toHaveClass('fc-not-end')
       })
     })
-  });
-
-  [ 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
-
-    describe('when in ' + viewName + ' view', function() {
-
-      beforeEach(function() {
-        options.defaultView = viewName
-      })
+  })
 
-      it('aligns with top of header', function() {
-        init()
-        var popoverTop = $('.fc-more-popover').offset().top
-        var headTop = $('.fc-view > table > thead .fc-row').offset().top
-        var diff = Math.abs(popoverTop - headTop)
-        expect(diff).toBeLessThan(2)
-      })
+  describeOptions('defaultView', {
+    'when in basicWeek view': 'basicWeek',
+    'when in agendaWeek view': 'agendaWeek'
+  }, function() {
+    it('aligns with top of header', function() {
+      initCalendar()
+      init()
+      var popoverTop = $('.fc-more-popover').offset().top
+      var headTop = $('.fc-view > table > thead .fc-row').offset().top
+      var diff = Math.abs(popoverTop - headTop)
+      expect(diff).toBeLessThan(2)
     })
   })
 
   // TODO: somehow test how the popover does to the edge of any scroll container
 
   it('closes when user clicks the X', function() {
+    initCalendar()
     init()
     expect($('.fc-more-popover')).toBeVisible()
-    $('.fc-more-popover .fc-close')
-      .simulate('click')
+    $('.fc-more-popover .fc-close').simulate('click')
     expect($('.fc-more-popover')).not.toBeVisible()
   })
 
   it('doesn\'t close when user clicks somewhere inside of the popover', function() {
+    initCalendar()
     init()
     expect($('.fc-more-popover')).toBeVisible()
     expect($('.fc-more-popover .fc-header')).toBeInDOM()
@@ -247,6 +249,7 @@ describe('eventLimit popover', function() {
   })
 
   it('closes when user clicks outside of the popover', function() {
+    initCalendar()
     init()
     expect($('.fc-more-popover')).toBeVisible()
     $('body').simulate('mousedown').simulate('click')
@@ -254,6 +257,7 @@ describe('eventLimit popover', function() {
   })
 
   it('has the correct event contents', function() {
+    initCalendar()
     init()
     expect($('.fc-more-popover .event1')).toBeMatchedBy('.fc-not-start.fc-end')
     expect($('.fc-more-popover .event2')).toBeMatchedBy('.fc-start.fc-not-end')
@@ -261,22 +265,24 @@ describe('eventLimit popover', function() {
     expect($('.fc-more-popover .event4')).toBeMatchedBy('.fc-start.fc-end')
   })
 
+  pushOptions({
+    editable: true
+  })
 
   describe('when dragging events out', function() {
 
-    beforeEach(function() {
-      options.editable = true
-    })
-
     describe('when dragging an all-day event to a different day', function() {
 
       it('should have the new day and remain all-day', function(done) {
 
-        options.eventDrop = function(event) {
-          expect(event.start).toEqualMoment('2014-07-28')
-          expect(event.allDay).toBe(true)
-          done()
-        }
+        initCalendar({
+          eventDrop: function(event) {
+            expect(event.start).toEqualMoment('2014-07-28')
+            expect(event.allDay).toBe(true)
+            done()
+          }
+        })
+
         init()
 
         setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
@@ -291,16 +297,21 @@ describe('eventLimit popover', function() {
 
       it('should move to new day but maintain its time', function(done) {
 
-        options.events.push({ // add timed event
+        testEvents.push({ // add timed event
           title: 'event5',
           start: '2014-07-29T13:00:00',
           className: 'event5'
         })
-        options.eventDrop = function(event) {
-          expect(event.start).toEqualMoment('2014-07-28T13:00:00')
-          expect(event.allDay).toBe(false)
-          done()
-        }
+
+        initCalendar({
+          events: testEvents,
+          eventDrop: function(event) {
+            expect(event.start).toEqualMoment('2014-07-28T13:00:00')
+            expect(event.allDay).toBe(false)
+            done()
+          }
+        })
+
         init()
 
         setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
@@ -315,13 +326,16 @@ describe('eventLimit popover', function() {
 
       it('should assume the new time, with a cleared end', function(done) {
 
-        options.defaultView = 'agendaWeek'
-        options.scrollTime = '00:00:00'
-        options.eventDrop = function(event) {
-          expect(event.start).toEqualMoment('2014-07-30T03:00:00')
-          expect(event.allDay).toBe(false)
-          done()
-        }
+        initCalendar({
+          defaultView: 'agendaWeek',
+          scrollTime: '00:00:00',
+          eventDrop: function(event) {
+            expect(event.start).toEqualMoment('2014-07-30T03:00:00')
+            expect(event.allDay).toBe(false)
+            done()
+          }
+        })
+
         init()
 
         setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
@@ -340,12 +354,15 @@ describe('eventLimit popover', function() {
 
       it('shouldn\'t do anything', function(done) {
 
-        options.eventDragStop = function() {
-          setTimeout(function() { // try to wait until drag is over. eventDrop won't fire BTW
-            expect($('.fc-more-popover')).toBeInDOM()
-            done()
-          }, 0)
-        }
+        initCalendar({
+          eventDragStop: function() {
+            setTimeout(function() { // try to wait until drag is over. eventDrop won't fire BTW
+              expect($('.fc-more-popover')).toBeInDOM()
+              done()
+            }, 0)
+          }
+        })
+
         init()
 
         setTimeout(function() { // simulate was getting confused about which thing was being clicked :(
@@ -358,19 +375,26 @@ describe('eventLimit popover', function() {
 
   })
 
-
   it('calls event render handlers', function() {
-    options.eventRender = function() {}
-    options.eventAfterRender = function() {}
-    options.eventAfterAllRender = function() {}
-    options.eventDestroy = function() {}
+    var options = {
+      events: [
+        { title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
+        { title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
+        { title: 'event3', start: '2014-07-29', className: 'event3' },
+        { title: 'event4', start: '2014-07-29', className: 'event4' }
+      ],
+      eventRender: function() {},
+      eventAfterRender: function() {},
+      eventAfterAllRender: function() {},
+      eventDestroy: function() {}
+    }
 
     spyOn(options, 'eventRender')
     spyOn(options, 'eventAfterRender')
     spyOn(options, 'eventAfterAllRender')
     spyOn(options, 'eventDestroy')
 
-    $('#cal').fullCalendar(options)
+    initCalendar(options)
 
     expect(options.eventRender.calls.count()).toBe(4)
     expect(options.eventAfterRender.calls.count()).toBe(4)

+ 34 - 40
tests/legacy/eventLimit-popoverDestroy.js

@@ -1,41 +1,35 @@
-
 describe('eventLimit popover', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultView: 'month',
-      defaultDate: '2014-08-01',
-      eventLimit: 3,
-      events: [
-        { title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
-        { title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
-        { title: 'event3', start: '2014-07-29', className: 'event3' },
-        { title: 'event4', start: '2014-07-29', className: 'event4' }
-      ],
-      popoverViewportConstrain: false, // because PhantomJS window is small, don't do smart repositioning
-      handleWindowResize: false // because showing the popover causes scrollbars and fires resize
-    }
+  pushOptions({
+    defaultView: 'month',
+    defaultDate: '2014-08-01',
+    eventLimit: 3,
+    events: [
+      { title: 'event1', start: '2014-07-28', end: '2014-07-30', className: 'event1' },
+      { title: 'event2', start: '2014-07-29', end: '2014-07-31', className: 'event2' },
+      { title: 'event3', start: '2014-07-29', className: 'event3' },
+      { title: 'event4', start: '2014-07-29', className: 'event4' }
+    ],
+    popoverViewportConstrain: false, // because PhantomJS window is small, don't do smart repositioning
+    handleWindowResize: false // because showing the popover causes scrollbars and fires resize
   })
 
   it('closes when user clicks the X and trigger eventDestroy for every render', function() {
     var eventsRendered = {}
     var renderCount = 0
     var activated = false
-    options.eventRender = function(eventObject, element, view) {
-      if (activated) {
-        eventsRendered[eventObject.title] = eventObject
-        ++renderCount
+    initCalendar({
+      eventRender: function(eventObject, element, view) {
+        if (activated) {
+          eventsRendered[eventObject.title] = eventObject
+          ++renderCount
+        }
+      },
+      eventDestroy: function(eventObject, element, view) {
+        delete eventsRendered[eventObject.title]
+        --renderCount
       }
-    }
-    options.eventDestroy = function(eventObject, element, view) {
-      delete eventsRendered[eventObject.title]
-      --renderCount
-    }
-    // Create calendar
-    $('#cal').fullCalendar(options)
+    })
     // Activate flags and pop event limit popover
     activated = true
     $('.fc-more').simulate('click')
@@ -52,18 +46,18 @@ describe('eventLimit popover', function() {
     var eventsRendered = {}
     var renderCount = 0
     var activated = false
-    options.eventRender = function(eventObject, element, view) {
-      if (activated) {
-        eventsRendered[eventObject.title] = eventObject
-        ++renderCount
+    initCalendar({
+      eventRender: function(eventObject, element, view) {
+        if (activated) {
+          eventsRendered[eventObject.title] = eventObject
+          ++renderCount
+        }
+      },
+      eventDestroy: function(eventObject, element, view) {
+        delete eventsRendered[eventObject.title]
+        --renderCount
       }
-    }
-    options.eventDestroy = function(eventObject, element, view) {
-      delete eventsRendered[eventObject.title]
-      --renderCount
-    }
-    // Create calendar
-    $('#cal').fullCalendar(options)
+    })
     // Activate flags and pop event limit popover
     activated = true
     $('.fc-more').simulate('click')

+ 107 - 113
tests/legacy/eventLimit.js

@@ -1,157 +1,153 @@
-
 describe('eventLimit', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultDate: '2014-08-01' // important that it is the first week, so works w/ month + week views
-    }
+  pushOptions({
+    defaultDate: '2014-08-01', // important that it is the first week, so works w/ month + week views
+    eventLimit: 3
   })
 
   describe('as a number', function() {
 
-    beforeEach(function() {
-      options.eventLimit = 3
-    });
-
-    [ 'month', 'basicWeek', 'agendaWeek' ].forEach(function(viewName) {
+    describeOptions('defaultView', {
+      'when in month view': 'month',
+      'when in basicWeek view': 'basicWeek',
+      'when in agendaWeek view': 'agendaWeek'
+    }, function() {
 
-      describe('when in ' + viewName + ' view', function() {
-
-        beforeEach(function() {
-          options.defaultView = viewName
-        })
-
-        it('doesn\'t display a more link when limit is more than the # of events', function() {
-          options.events = [
+      it('doesn\'t display a more link when limit is more than the # of events', function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' }
           ]
-          $('#cal').fullCalendar(options)
-          expect($('.fc-more').length).toBe(0)
         })
+        expect($('.fc-more').length).toBe(0)
+      })
 
-        it('doesn\'t display a more link when limit equal to the # of events', function() {
-          options.events = [
+      it('doesn\'t display a more link when limit equal to the # of events', function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' }
           ]
-          $('#cal').fullCalendar(options)
-          expect($('.fc-more').length).toBe(0)
         })
+        expect($('.fc-more').length).toBe(0)
+      })
 
-        it('displays a more link when limit is less than the # of events', function() {
-          options.events = [
+      it('displays a more link when limit is less than the # of events', function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' }
           ]
-          $('#cal').fullCalendar(options)
-          expect($('.fc-more').length).toBe(1)
-          expect($('.fc-more')).toHaveText('+2 more')
         })
+        expect($('.fc-more').length).toBe(1)
+        expect($('.fc-more')).toHaveText('+2 more')
+      })
 
-        it('displays one more per day, when a multi-day event is above', function() {
-          options.events = [
+      it('displays one more per day, when a multi-day event is above', function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-29', end: '2014-07-31' },
             { title: 'event2', start: '2014-07-29', end: '2014-07-31' },
             { title: 'event2', start: '2014-07-29', end: '2014-07-31' },
             { title: 'event2', start: '2014-07-29', end: '2014-07-31' }
           ]
-          $('#cal').fullCalendar(options)
-          var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
-          expect($('.fc-more').length).toBe(2)
-          expect($('.fc-more').eq(0)).toHaveText('+2 more')
-          expect($('.fc-more').eq(0)).toBeBoundedBy(cells.eq(2))
-          expect($('.fc-more').eq(1)).toHaveText('+2 more')
-          expect($('.fc-more').eq(1)).toBeBoundedBy(cells.eq(3))
         })
+        var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
+        expect($('.fc-more').length).toBe(2)
+        expect($('.fc-more').eq(0)).toHaveText('+2 more')
+        expect($('.fc-more').eq(0)).toBeBoundedBy(cells.eq(2))
+        expect($('.fc-more').eq(1)).toHaveText('+2 more')
+        expect($('.fc-more').eq(1)).toBeBoundedBy(cells.eq(3))
+      })
 
-        it('will render a link in a multi-day event\'s second column ' +
-          'if it has already been hidden in the first',
-        function() {
-          options.events = [
+      it('will render a link in a multi-day event\'s second column ' +
+        'if it has already been hidden in the first',
+      function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-29', end: '2014-07-31' },
             { title: 'event2', start: '2014-07-29', end: '2014-07-31' },
             { title: 'event2', start: '2014-07-29', end: '2014-07-31' },
             { title: 'event2', start: '2014-07-29' }
           ]
-          $('#cal').fullCalendar(options)
-          var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
-          expect($('.fc-more').length).toBe(2)
-          expect($('.fc-more').eq(0)).toHaveText('+2 more')
-          expect($('.fc-more').eq(0)).toBeBoundedBy(cells.eq(2))
-          expect($('.fc-more').eq(1)).toHaveText('+1 more')
-          expect($('.fc-more').eq(1)).toBeBoundedBy(cells.eq(3))
         })
+        var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
+        expect($('.fc-more').length).toBe(2)
+        expect($('.fc-more').eq(0)).toHaveText('+2 more')
+        expect($('.fc-more').eq(0)).toBeBoundedBy(cells.eq(2))
+        expect($('.fc-more').eq(1)).toHaveText('+1 more')
+        expect($('.fc-more').eq(1)).toBeBoundedBy(cells.eq(3))
+      })
 
-        it('will render a link in a multi-day event\'s second column ' +
-          'if it has already been hidden in the first even if he second column hardly has any events',
-        function() {
-          options.events = [
+      it('will render a link in a multi-day event\'s second column ' +
+        'if it has already been hidden in the first even if he second column hardly has any events',
+      function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-29', end: '2014-07-31' }
           ]
-          $('#cal').fullCalendar(options)
-          var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
-          var link = $('.fc-more').eq(0) // will appear to be the third link, but will be in first row, so 0dom
-          expect(link.length).toBe(1)
-          expect(link).toHaveText('+1 more')
-          expect(link).toBeBoundedBy(cells.eq(3))
         })
+        var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
+        var link = $('.fc-more').eq(0) // will appear to be the third link, but will be in first row, so 0dom
+        expect(link.length).toBe(1)
+        expect(link).toHaveText('+1 more')
+        expect(link).toBeBoundedBy(cells.eq(3))
+      })
 
-        it('will render a link in place of a hidden single day event, if covered by a multi-day', function() {
-          options.events = [
+      it('will render a link in place of a hidden single day event, if covered by a multi-day', function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-28' },
             { title: 'event2', start: '2014-07-28' }
           ]
-          $('#cal').fullCalendar(options)
-          var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
-          var link = $('.fc-more').eq(0)
-          expect(link.length).toBe(1)
-          expect(link).toHaveText('+2 more')
-          expect(link).toBeBoundedBy(cells.eq(1))
         })
+        var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
+        var link = $('.fc-more').eq(0)
+        expect(link.length).toBe(1)
+        expect(link).toHaveText('+2 more')
+        expect(link).toBeBoundedBy(cells.eq(1))
+      })
 
-        it('will render a link in place of a hidden single day event, if covered by a multi-day ' +
-          'and in its second column',
-        function() {
-          options.events = [
+      it('will render a link in place of a hidden single day event, if covered by a multi-day ' +
+        'and in its second column',
+      function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-28', end: '2014-07-30' },
             { title: 'event2', start: '2014-07-29' },
             { title: 'event2', start: '2014-07-29' }
           ]
-          $('#cal').fullCalendar(options)
-          var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
-          var link = $('.fc-more').eq(0)
-          expect(link.length).toBe(1)
-          expect(link).toHaveText('+2 more')
-          expect(link).toBeBoundedBy(cells.eq(2))
         })
+        var cells = $('.fc-day-grid .fc-row:eq(0) .fc-bg td:not(.fc-axis)')
+        var link = $('.fc-more').eq(0)
+        expect(link.length).toBe(1)
+        expect(link).toHaveText('+2 more')
+        expect(link).toBeBoundedBy(cells.eq(2))
       })
     })
   })
 
   describe('when auto', function() {
 
-    beforeEach(function() {
-      options.eventLimit = true
+    pushOptions({
+      eventLimit: true
     })
 
     describe('in month view', function() {
 
-      beforeEach(function() {
-        options.defaultView = 'month'
-        options.events = [
+      pushOptions({
+        defaultView: 'month',
+        events: [
           { title: 'event1', start: '2014-07-28', end: '2014-07-30' },
           { title: 'event2', start: '2014-07-28', end: '2014-07-30' },
           { title: 'event2', start: '2014-07-29' },
@@ -169,7 +165,7 @@ describe('eventLimit', function() {
       })
 
       it('renders the heights of all the rows the same, regardless of # of events', function() {
-        $('#cal').fullCalendar(options)
+        initCalendar()
         var rowEls = $('.fc-day-grid .fc-row').slice(0, -1) // remove last b/c it will be a different height
         expect(rowEls.length).toBeGreaterThan(0)
         var height = rowEls.height()
@@ -179,47 +175,45 @@ describe('eventLimit', function() {
       })
 
       it('renders a more link when there are obviously too many events', function() {
-        $('#cal').width(800)
-        $('#cal').fullCalendar(options)
-        expect($('#cal .fc-more').length).toBe(1)
+        var $el = $('<div id="calendar">').appendTo('body').width(800)
+        initCalendar({}, $el)
+        expect($('.fc-more', currentCalendar.el).length).toBe(1)
       })
-    });
-
-    [ 'month', 'basicWeek' ].forEach(function(viewName) {
-
-      describe('in ' + viewName + ' view', function() {
+    })
 
-        beforeEach(function() {
-          options.defaultView = viewName
-        })
+    describeOptions('defaultView', {
+      'when in month view': 'month',
+      'when in basicWeek view': 'basicWeek'
+    }, function() {
 
-        it('doesn\'t render a more link where there should obviously not be a limit', function() {
-          options.events = [
+      it('doesn\'t render a more link where there should obviously not be a limit', function() {
+        initCalendar({
+          events: [
             { title: 'event1', start: '2014-07-28', end: '2014-07-30' }
           ]
-          $('#cal').fullCalendar(options)
-          expect($('.fc-more').length).toBe(0)
         })
+        expect($('.fc-more').length).toBe(0)
       })
     })
 
     describe('in agendaWeek view', function() {
 
-      beforeEach(function() {
-        options.defaultView = 'agendaWeek'
+      pushOptions({
+        defaultView: 'agendaWeek'
       })
 
       it('behaves as if limit is 5', function() {
-        options.events = [
-          { title: 'event1', start: '2014-07-29' },
-          { title: 'event2', start: '2014-07-29' },
-          { title: 'event2', start: '2014-07-29' },
-          { title: 'event2', start: '2014-07-29' },
-          { title: 'event2', start: '2014-07-29' },
-          { title: 'event2', start: '2014-07-29' },
-          { title: 'event2', start: '2014-07-29' }
-        ]
-        $('#cal').fullCalendar(options)
+        initCalendar({
+          events: [
+            { title: 'event1', start: '2014-07-29' },
+            { title: 'event2', start: '2014-07-29' },
+            { title: 'event2', start: '2014-07-29' },
+            { title: 'event2', start: '2014-07-29' },
+            { title: 'event2', start: '2014-07-29' },
+            { title: 'event2', start: '2014-07-29' },
+            { title: 'event2', start: '2014-07-29' }
+          ]
+        })
         expect($('.fc-event:visible').length).toBe(4)
         expect($('.fc-more').length).toBe(1)
         expect($('.fc-more')).toHaveText('+3 more')

+ 75 - 74
tests/legacy/eventLimitClick.js

@@ -1,31 +1,25 @@
-
 describe('eventLimitClick', function() { // simulate a click
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultDate: '2014-08-01', // important that it is the first week, so works w/ month + week views
-      defaultView: 'month',
-      eventLimit: 3,
-      events: [
-        { title: 'event1', start: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29' }
-      ]
-    }
+  pushOptions({
+    defaultDate: '2014-08-01', // important that it is the first week, so works w/ month + week views
+    defaultView: 'month',
+    eventLimit: 3,
+    events: [
+      { title: 'event1', start: '2014-07-29' },
+      { title: 'event2', start: '2014-07-29' },
+      { title: 'event2', start: '2014-07-29' },
+      { title: 'event2', start: '2014-07-29' }
+    ]
   })
 
   describe('when set to "popover"', function() {
 
-    beforeEach(function() {
-      options.eventLimitClick = 'popover'
+    pushOptions({
+      eventLimitClick: 'popover'
     })
 
     it('renders a popover upon click', function() {
-      $('#cal').fullCalendar(options)
+      initCalendar()
       $('.fc-more').simulate('click')
       expect($('.fc-more-popover')).toBeVisible()
     })
@@ -35,32 +29,34 @@ describe('eventLimitClick', function() { // simulate a click
 
   describe('when set to "week"', function() {
 
-    beforeEach(function() {
-      options.eventLimitClick = 'week'
+    pushOptions({
+      eventLimitClick: 'week'
     })
 
     it('should go to basicWeek if it is one of the available views', function() {
-      options.header = {
-        left: 'prev,next today',
-        center: 'title',
-        right: 'month,basicWeek,basicDay'
-      }
-      $('#cal').fullCalendar(options)
+      initCalendar({
+        header: {
+          left: 'prev,next today',
+          center: 'title',
+          right: 'month,basicWeek,basicDay'
+        }
+      })
       $('.fc-more').simulate('click')
-      var view = $('#cal').fullCalendar('getView')
+      var view = currentCalendar.getView()
       expect(view.name).toBe('basicWeek') // .name should be deprecated
       expect(view.type).toBe('basicWeek')
     })
 
     it('should go to agendaWeek if it is one of the available views', function() {
-      options.header = {
-        left: 'prev,next today',
-        center: 'title',
-        right: 'month,agendaWeek,agendaDay'
-      }
-      $('#cal').fullCalendar(options)
+      initCalendar({
+        header: {
+          left: 'prev,next today',
+          center: 'title',
+          right: 'month,agendaWeek,agendaDay'
+        }
+      })
       $('.fc-more').simulate('click')
-      var view = $('#cal').fullCalendar('getView')
+      var view = currentCalendar.getView()
       expect(view.name).toBe('agendaWeek') // .name should be deprecated
       expect(view.type).toBe('agendaWeek')
     })
@@ -68,69 +64,74 @@ describe('eventLimitClick', function() { // simulate a click
 
   describe('when set to "day"', function() {
 
-    beforeEach(function() {
-      options.eventLimitClick = 'day'
+    pushOptions({
+      eventLimitClick: 'day'
     })
 
     it('should go to basicDay if it is one of the available views', function() {
-      options.header = {
-        left: 'prev,next today',
-        center: 'title',
-        right: 'month,basicWeek,basicDay'
-      }
-      $('#cal').fullCalendar(options)
+      initCalendar({
+        header: {
+          left: 'prev,next today',
+          center: 'title',
+          right: 'month,basicWeek,basicDay'
+        }
+      })
       $('.fc-more').simulate('click')
-      var view = $('#cal').fullCalendar('getView')
+      var view = currentCalendar.getView()
       expect(view.name).toBe('basicDay')
     })
 
     it('should go to agendaDay if it is one of the available views', function() {
-      options.header = {
-        left: 'prev,next today',
-        center: 'title',
-        right: 'month,agendaWeek,agendaDay'
-      }
-      $('#cal').fullCalendar(options)
+      initCalendar({
+        header: {
+          left: 'prev,next today',
+          center: 'title',
+          right: 'month,agendaWeek,agendaDay'
+        }
+      })
       $('.fc-more').simulate('click')
-      var view = $('#cal').fullCalendar('getView')
+      var view = currentCalendar.getView()
       expect(view.name).toBe('agendaDay')
     })
   })
 
   it('works with an explicit view name', function() {
-    options.eventLimitClick = 'agendaWeek'
-    options.header = {
-      left: 'prev,next today',
-      center: 'title',
-      right: 'month,basicWeek,basicDay'
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      eventLimitClick: 'agendaWeek',
+      header: {
+        left: 'prev,next today',
+        center: 'title',
+        right: 'month,basicWeek,basicDay'
+      }
+    })
     $('.fc-more').simulate('click')
-    var view = $('#cal').fullCalendar('getView')
+    var view = currentCalendar.getView()
     expect(view.name).toBe('agendaWeek')
   })
 
   it('works with custom function and all the arguments are correct', function() {
-    options.eventLimitClick = function(cellInfo, jsEvent) {
-      expect(typeof cellInfo).toBe('object')
-      expect(typeof jsEvent).toBe('object')
-      expect(cellInfo.date).toEqualMoment('2014-07-29')
-      expect(cellInfo.dayEl.data('date')).toBe('2014-07-29')
-      expect(cellInfo.hiddenSegs.length).toBe(2)
-      expect(cellInfo.segs.length).toBe(4)
-      expect(cellInfo.moreEl).toHaveClass('fc-more')
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      eventLimitClick: function(cellInfo, jsEvent) {
+        expect(typeof cellInfo).toBe('object')
+        expect(typeof jsEvent).toBe('object')
+        expect(cellInfo.date).toEqualMoment('2014-07-29')
+        expect(cellInfo.dayEl.data('date')).toBe('2014-07-29')
+        expect(cellInfo.hiddenSegs.length).toBe(2)
+        expect(cellInfo.segs.length).toBe(4)
+        expect(cellInfo.moreEl).toHaveClass('fc-more')
+      }
+    })
     $('.fc-more').simulate('click')
   })
 
   it('works with custom function, and can return a view name', function() {
-    options.eventLimitClick = function(cellInfo, jsEvent) {
-      return 'agendaDay'
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      eventLimitClick: function(cellInfo, jsEvent) {
+        return 'agendaDay'
+      }
+    })
     $('.fc-more').simulate('click')
-    var view = $('#cal').fullCalendar('getView')
+    var view = currentCalendar.getView()
     expect(view.name).toBe('agendaDay')
   })
 

+ 26 - 28
tests/legacy/eventLimitText.js

@@ -1,48 +1,46 @@
-
 describe('eventLimitText', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultDate: '2014-08-01', // important that it is the first week, so works w/ month + week views
-      defaultView: 'month',
-      eventLimit: 3,
-      events: [
-        { title: 'event1', start: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29' },
-        { title: 'event2', start: '2014-07-29' }
-      ]
-    }
+  pushOptions({
+    defaultDate: '2014-08-01', // important that it is the first week, so works w/ month + week views
+    defaultView: 'month',
+    eventLimit: 3,
+    events: [
+      { title: 'event1', start: '2014-07-29' },
+      { title: 'event2', start: '2014-07-29' },
+      { title: 'event2', start: '2014-07-29' },
+      { title: 'event2', start: '2014-07-29' }
+    ]
   })
 
   it('allows a string', function() {
-    options.eventLimitText = 'extra'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      eventLimitText: 'extra'
+    })
     expect($('.fc-more')).toHaveText('+2 extra')
   })
 
   it('allows a function', function() {
-    options.eventLimitText = function(n) {
-      expect(typeof n).toBe('number')
-      return 'there are ' + n + ' more events!'
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      eventLimitText: function(n) {
+        expect(typeof n).toBe('number')
+        return 'there are ' + n + ' more events!'
+      }
+    })
     expect($('.fc-more')).toHaveText('there are 2 more events!')
   })
 
   it('has a default value that is affected by the custom locale', function() {
-    options.locale = 'fr'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      locale: 'fr'
+    })
     expect($('.fc-more')).toHaveText('+2 en plus')
   })
 
   it('is not affected by a custom locale when the value is explicitly specified', function() {
-    options.locale = 'fr'
-    options.eventLimitText = 'extra'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      locale: 'fr',
+      eventLimitText: 'extra'
+    })
     expect($('.fc-more')).toHaveText('+2 extra')
   })
 })

+ 207 - 168
tests/legacy/eventRender.js

@@ -1,12 +1,12 @@
 describe('eventRender', function() {
-  var options
 
-  beforeEach(function() {
-    options = {
-      defaultDate: '2014-11-12',
-      scrollTime: '00:00:00'
-    }
-    affix('#cal')
+  pushOptions({
+    defaultDate: '2014-11-12',
+    scrollTime: '00:00:00',
+    events: [ {
+      title: 'my event',
+      start: '2014-11-12T09:00:00'
+    } ]
   })
 
   $.each({
@@ -14,279 +14,318 @@ describe('eventRender', function() {
     agendaWeek: '.fc-time-grid'
   }, function(viewName, gridSelector) {
     describe('when in ' + viewName + ' view', function() {
-      beforeEach(function() {
-        options.defaultView = viewName
+
+      pushOptions({
+        defaultView: viewName
       })
+
       describe('with foreground event', function() {
         it('receives correct args AND can modify the element', function(done) {
-          options.events = [ {
-            title: 'my event',
-            start: '2014-11-12T09:00:00'
-          } ]
-          options.eventRender = function(event, element, view) {
-            expect(typeof event).toBe('object')
-            expect(event.rendering).toBeUndefined()
-            expect(event.start).toBeDefined()
-            expect(typeof element).toBe('object')
-            expect(element.length).toBe(1)
-            expect(typeof view).toBe('object')
-            element.css('font-size', '20px')
-          }
-          options.eventAfterAllRender = function() {
-            expect($(gridSelector).find('.fc-event').css('font-size')).toBe('20px')
-            expect(options.eventRender).toHaveBeenCalled()
-            done()
+          var options = {
+            eventRender: function(event, element, view) {
+              expect(typeof event).toBe('object')
+              expect(event.rendering).toBeUndefined()
+              expect(event.start).toBeDefined()
+              expect(typeof element).toBe('object')
+              expect(element.length).toBe(1)
+              expect(typeof view).toBe('object')
+              element.css('font-size', '20px')
+            },
+            eventAfterAllRender: function() {
+              expect($(gridSelector).find('.fc-event').css('font-size')).toBe('20px')
+              expect(options.eventRender).toHaveBeenCalled()
+              done()
+            }
           }
           spyOn(options, 'eventRender').and.callThrough()
-          $('#cal').fullCalendar(options)
+          initCalendar(options)
         })
       })
     })
   })
 
   describe('when in month view', function() {
-    beforeEach(function() {
-      options.defaultView = 'month'
+
+    pushOptions({
+      defaultView: 'month',
+      events: [ {
+        title: 'my event',
+        start: '2014-11-12'
+      } ]
     })
 
     describe('with a foreground event', function() {
-      beforeEach(function() {
-        options.events = [ {
-          title: 'my event',
-          start: '2014-11-12'
-        } ]
-      })
       it('can return a new element', function(done) {
-        options.eventRender = function(event, element, view) {
-          return $('<div class="fc-event sup" style="background-color:green">sup g</div>')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .sup').length).toBe(1)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return $('<div class="fc-event sup" style="background-color:green">sup g</div>')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .sup').length).toBe(1)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('can return false and cancel rendering', function(done) {
-        options.eventRender = function(event, element, view) {
-          return false
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .fc-event').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return false
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .fc-event').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
     })
 
     describe('with an all-day background event', function() {
-      beforeEach(function() {
-        options.events = [ {
+
+      pushOptions({
+        events: [ {
           title: 'my event',
           start: '2014-11-12',
           rendering: 'background'
         } ]
       })
+
       it('receives correct args AND can modify the element', function(done) {
-        options.eventRender = function(event, element, view) {
-          expect(typeof event).toBe('object')
-          expect(event.rendering).toBe('background')
-          expect(event.start).toBeDefined()
-          expect(typeof element).toBe('object')
-          expect(element.length).toBe(1)
-          expect(typeof view).toBe('object')
-          element.css('font-size', '20px')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .fc-bgevent').css('font-size')).toBe('20px')
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            expect(typeof event).toBe('object')
+            expect(event.rendering).toBe('background')
+            expect(event.start).toBeDefined()
+            expect(typeof element).toBe('object')
+            expect(element.length).toBe(1)
+            expect(typeof view).toBe('object')
+            element.css('font-size', '20px')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .fc-bgevent').css('font-size')).toBe('20px')
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
+
       it('can return a new element', function(done) {
-        options.eventRender = function(event, element, view) {
-          return $('<td class="sup" style="background-color:green">sup g</td>')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .sup').length).toBe(1)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return $('<td class="sup" style="background-color:green">sup g</td>')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .sup').length).toBe(1)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('won\'t rendering when returning a new element of the wrong type', function(done) {
-        options.eventRender = function(event, element, view) {
-          return $('<div class="sup" style="background-color:green">sup g</div>')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .sup').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return $('<div class="sup" style="background-color:green">sup g</div>')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .sup').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('can return false and cancel rendering', function(done) {
-        options.eventRender = function(event, element, view) {
-          return false
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .fc-bgevent').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return false
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .fc-bgevent').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
     })
 
     describe('with a timed background event', function() { // not exactly related to eventRender!
-      beforeEach(function() {
-        options.events = [ {
+
+      pushOptions({
+        events: [ {
           title: 'my event',
           start: '2014-11-12T01:00:00',
           rendering: 'background'
         } ]
       })
+
       it('won\'t render or call eventRender', function(done) {
-        options.eventRender = function(event, element, view) { }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .fc-bgevent').length).toBe(0)
-          expect(options.eventRender).not.toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {},
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .fc-bgevent').length).toBe(0)
+            expect(options.eventRender).not.toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
     })
   })
 
   describe('when in agendaWeek view', function() {
-    beforeEach(function() {
-      options.defaultView = 'agendaWeek'
+
+    pushOptions({
+      defaultView: 'agendaWeek'
     })
 
     describe('with a foreground event', function() {
-      beforeEach(function() {
-        options.events = [ {
+
+      pushOptions({
+        events: [ {
           title: 'my event',
           start: '2014-11-12T01:00:00'
         } ]
       })
+
       it('can return a new element', function(done) {
-        options.eventRender = function(event, element, view) {
-          return $('<div class="fc-event sup" style="background-color:green">sup g</div>')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-time-grid .sup').length).toBe(1)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return $('<div class="fc-event sup" style="background-color:green">sup g</div>')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-time-grid .sup').length).toBe(1)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('can return false and cancel rendering', function(done) {
-        options.eventRender = function(event, element, view) {
-          return false
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-time-grid .fc-event').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return false
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-time-grid .fc-event').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
     })
 
     describe('with a timed background event', function() {
-      beforeEach(function() {
-        options.events = [ {
+
+      pushOptions({
+        events: [ {
           title: 'my event',
           start: '2014-11-12T01:00:00',
           rendering: 'background'
         } ]
       })
+
       it('receives correct args AND can modify the element', function(done) {
-        options.eventRender = function(event, element, view) {
-          expect(typeof event).toBe('object')
-          expect(event.rendering).toBe('background')
-          expect(event.start).toBeDefined()
-          expect(typeof element).toBe('object')
-          expect(element.length).toBe(1)
-          expect(typeof view).toBe('object')
-          element.css('font-size', '20px')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-time-grid .fc-bgevent').css('font-size')).toBe('20px')
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            expect(typeof event).toBe('object')
+            expect(event.rendering).toBe('background')
+            expect(event.start).toBeDefined()
+            expect(typeof element).toBe('object')
+            expect(element.length).toBe(1)
+            expect(typeof view).toBe('object')
+            element.css('font-size', '20px')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-time-grid .fc-bgevent').css('font-size')).toBe('20px')
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('can return a new element', function(done) {
-        options.eventRender = function(event, element, view) {
-          return $('<div class="fc-bgevent sup" style="background-color:green">sup g</div>')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-time-grid .sup').length).toBe(1)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return $('<div class="fc-bgevent sup" style="background-color:green">sup g</div>')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-time-grid .sup').length).toBe(1)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('won\'t rendering when returning a new element of the wrong type', function(done) {
-        options.eventRender = function(event, element, view) {
-          return $('<p class="fc-bgevent sup" style="background-color:green">sup g</p>')
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-time-grid .sup').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return $('<p class="fc-bgevent sup" style="background-color:green">sup g</p>')
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-time-grid .sup').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
       it('can return false and cancel rendering', function(done) {
-        options.eventRender = function(event, element, view) {
-          return false
-        }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-time-grid .fc-bgevent').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {
+            return false
+          },
+          eventAfterAllRender: function() {
+            expect($('.fc-time-grid .fc-bgevent').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
     })
 
     describe('with an all-day background event', function() { // not exactly related to eventRender!
-      beforeEach(function() {
-        options.events = [ {
+
+      pushOptions({
+        events: [ {
           title: 'my event',
           start: '2014-11-12',
           rendering: 'background'
         } ]
       })
+
       it('will render in the all-day slot', function(done) {
-        options.eventRender = function(event, element, view) { }
-        options.eventAfterAllRender = function() {
-          expect($('.fc-day-grid .fc-bgevent').length).toBe(1)
-          expect($('.fc-time-grid .fc-bgevent').length).toBe(0)
-          expect(options.eventRender).toHaveBeenCalled()
-          done()
+        var options = {
+          eventRender: function(event, element, view) {},
+          eventAfterAllRender: function() {
+            expect($('.fc-day-grid .fc-bgevent').length).toBe(1)
+            expect($('.fc-time-grid .fc-bgevent').length).toBe(0)
+            expect(options.eventRender).toHaveBeenCalled()
+            done()
+          }
         }
         spyOn(options, 'eventRender').and.callThrough()
-        $('#cal').fullCalendar(options)
+        initCalendar(options)
       })
     })
   })

+ 5 - 7
tests/legacy/eventRenderWait.js

@@ -13,8 +13,7 @@ describe('eventRenderWait', function() {
     var extraEvent2 = { title: 'event6', start: '2016-12-04T06:00:00', className: 'event6', id: '6' }
     var eventRenderCnt = 0
 
-    affix('#cal')
-    $('#cal').fullCalendar({
+    initCalendar({
       defaultDate: '2016-12-04',
       defaultView: 'agendaDay',
       events: eventSource1,
@@ -39,19 +38,18 @@ describe('eventRenderWait', function() {
       }
     })
 
-    var calendar = $('#cal').fullCalendar('getCalendar')
     expect($('.fc-event').length).toBe(0)
 
-    calendar.addEventSource(eventSource2)
+    currentCalendar.addEventSource(eventSource2)
     expect($('.fc-event').length).toBe(0)
 
-    calendar.renderEvent(extraEvent1)
+    currentCalendar.renderEvent(extraEvent1)
     expect($('.fc-event').length).toBe(0)
 
-    calendar.renderEvent(extraEvent2)
+    currentCalendar.renderEvent(extraEvent2)
     expect($('.fc-event').length).toBe(0)
 
-    calendar.removeEvents(extraEvent2.id) // only works with id!?
+    currentCalendar.removeEvents(extraEvent2.id) // only works with id!?
     expect($('.fc-event').length).toBe(0)
   })
 })

+ 75 - 101
tests/legacy/events-function.js

@@ -1,125 +1,97 @@
-
 describe('events as a function', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultView: 'month',
-      defaultDate: '2014-05-01'
-    }
+  pushOptions({
+    defaultView: 'month',
+    defaultDate: '2014-05-01'
   })
 
+  function testEventFunctionParams(start, end, timezone, callback) {
+    expect(moment.isMoment(start)).toEqual(true)
+    expect(start.hasTime()).toEqual(false)
+    expect(start.hasZone()).toEqual(false)
+    expect(start.format()).toEqual('2014-04-27')
+    expect(moment.isMoment(end)).toEqual(true)
+    expect(end.hasTime()).toEqual(false)
+    expect(end.hasZone()).toEqual(false)
+    expect(end.format()).toEqual('2014-06-08')
+    expect(typeof callback).toEqual('function')
+  }
+
   it('requests correctly when no timezone', function(done) {
-    options.events = function(start, end, timezone, callback) {
-      expect(moment.isMoment(start)).toEqual(true)
-      expect(start.hasTime()).toEqual(false)
-      expect(start.hasZone()).toEqual(false)
-      expect(start.format()).toEqual('2014-04-27')
-      expect(moment.isMoment(end)).toEqual(true)
-      expect(end.hasTime()).toEqual(false)
-      expect(end.hasZone()).toEqual(false)
-      expect(end.format()).toEqual('2014-06-08')
-      expect(timezone).toEqual(false)
-      expect(typeof callback).toEqual('function')
-      callback([])
-      done()
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      events: function(start, end, timezone, callback) {
+        testEventFunctionParams(start, end, timezone, callback)
+        expect(timezone).toEqual(false)
+        callback([])
+        done()
+      }
+    })
   })
 
   it('requests correctly when local timezone', function(done) {
-    options.timezone = 'local'
-    options.events = function(start, end, timezone, callback) {
-      expect(moment.isMoment(start)).toEqual(true)
-      expect(start.hasTime()).toEqual(false)
-      expect(start.hasZone()).toEqual(false)
-      expect(start.format()).toEqual('2014-04-27')
-      expect(moment.isMoment(end)).toEqual(true)
-      expect(end.hasTime()).toEqual(false)
-      expect(end.hasZone()).toEqual(false)
-      expect(end.format()).toEqual('2014-06-08')
-      expect(timezone).toEqual('local')
-      expect(typeof callback).toEqual('function')
-      callback([])
-      done()
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      timezone: 'local',
+      events: function(start, end, timezone, callback) {
+        testEventFunctionParams(start, end, timezone, callback)
+        expect(timezone).toEqual('local')
+        callback([])
+        done()
+      }
+    })
   })
 
   it('requests correctly when UTC timezone', function(done) {
-    options.timezone = 'UTC'
-    options.events = function(start, end, timezone, callback) {
-      expect(moment.isMoment(start)).toEqual(true)
-      expect(start.hasTime()).toEqual(false)
-      expect(start.hasZone()).toEqual(false)
-      expect(start.format()).toEqual('2014-04-27')
-      expect(moment.isMoment(end)).toEqual(true)
-      expect(end.hasTime()).toEqual(false)
-      expect(end.hasZone()).toEqual(false)
-      expect(end.format()).toEqual('2014-06-08')
-      expect(timezone).toEqual('UTC')
-      expect(typeof callback).toEqual('function')
-      callback([])
-      done()
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      timezone: 'UTC',
+      events: function(start, end, timezone, callback) {
+        testEventFunctionParams(start, end, timezone, callback)
+        expect(timezone).toEqual('UTC')
+        callback([])
+        done()
+      }
+    })
   })
 
   it('requests correctly when custom timezone', function(done) {
-    options.timezone = 'America/Chicago'
-    options.events = function(start, end, timezone, callback) {
-      expect(moment.isMoment(start)).toEqual(true)
-      expect(start.hasTime()).toEqual(false)
-      expect(start.hasZone()).toEqual(false)
-      expect(start.format()).toEqual('2014-04-27')
-      expect(moment.isMoment(end)).toEqual(true)
-      expect(end.hasTime()).toEqual(false)
-      expect(end.hasZone()).toEqual(false)
-      expect(end.format()).toEqual('2014-06-08')
-      expect(timezone).toEqual('America/Chicago')
-      expect(typeof callback).toEqual('function')
-      callback([])
-      done()
-    }
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      timezone: 'America/Chicago',
+      events: function(start, end, timezone, callback) {
+        testEventFunctionParams(start, end, timezone, callback)
+        expect(timezone).toEqual('America/Chicago')
+        callback([])
+        done()
+      }
+    })
   })
 
   it('requests correctly when timezone changed dynamically', function(done) {
     var callCnt = 0
-
-    options.timezone = 'America/Chicago'
-    options.events = function(start, end, timezone, callback) {
-      callCnt++
-      if (callCnt === 1) {
-        expect(timezone).toEqual('America/Chicago')
-        setTimeout(function() {
-          $('#cal').fullCalendar('option', 'timezone', 'UTC')
-        }, 0)
-      } else if (callCnt === 2) {
-        expect(timezone).toEqual('UTC')
-        done()
+    var options = {
+      timezone: 'America/Chicago',
+      events: function(start, end, timezone, callback) {
+        testEventFunctionParams(start, end, timezone, callback)
+        callCnt++
+        if (callCnt === 1) {
+          expect(timezone).toEqual('America/Chicago')
+          setTimeout(function() {
+            currentCalendar.option('timezone', 'UTC')
+          }, 0)
+        } else if (callCnt === 2) {
+          expect(timezone).toEqual('UTC')
+          done()
+        }
       }
     }
 
-    $('#cal').fullCalendar(options)
+    initCalendar(options)
   })
 
   it('requests correctly with event source extended form', function(done) {
     var eventSource = {
       className: 'customeventclass',
       events: function(start, end, timezone, callback) {
-        expect(moment.isMoment(start)).toEqual(true)
-        expect(start.hasTime()).toEqual(false)
-        expect(start.hasZone()).toEqual(false)
-        expect(start.format()).toEqual('2014-04-27')
-        expect(moment.isMoment(end)).toEqual(true)
-        expect(end.hasTime()).toEqual(false)
-        expect(end.hasZone()).toEqual(false)
-        expect(end.format()).toEqual('2014-06-08')
+        testEventFunctionParams(start, end, timezone, callback)
         expect(timezone).toEqual(false)
-        expect(typeof callback).toEqual('function')
         callback([
           {
             title: 'event1',
@@ -129,13 +101,15 @@ describe('events as a function', function() {
       }
     }
     spyOn(eventSource, 'events').and.callThrough()
-    options.eventSources = [ eventSource ]
-    options.eventRender = function(eventObj, eventElm) {
-      expect(eventSource.events.calls.count()).toEqual(1)
-      expect(eventElm).toHaveClass('customeventclass')
-      done()
-    }
-    $('#cal').fullCalendar(options)
+
+    initCalendar({
+      eventSources: [ eventSource ],
+      eventRender: function(eventObj, eventElm) {
+        expect(eventSource.events.calls.count()).toEqual(1)
+        expect(eventElm).toHaveClass('customeventclass')
+        done()
+      }
+    })
   })
 
 })

+ 61 - 67
tests/legacy/events-json-feed.js

@@ -1,16 +1,11 @@
-
 describe('events as a json feed', function() {
 
-  var options
+  pushOptions({
+    defaultDate: '2014-05-01',
+    defaultView: 'month'
+  })
 
   beforeEach(function() {
-    affix('#cal')
-
-    options = {
-      defaultDate: '2014-05-01',
-      defaultView: 'month'
-    }
-
     $.mockjax({
       url: '/my-feed.php',
       contentType: 'text/json',
@@ -29,8 +24,9 @@ describe('events as a json feed', function() {
   })
 
   it('requests correctly when no timezone', function() {
-    options.events = '/my-feed.php'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      events: '/my-feed.php'
+    })
     var request = $.mockjax.mockedAjaxCalls()[0]
     expect(request.data.start).toEqual('2014-04-27')
     expect(request.data.end).toEqual('2014-06-08')
@@ -38,9 +34,10 @@ describe('events as a json feed', function() {
   })
 
   it('requests correctly when local timezone', function() {
-    options.events = '/my-feed.php'
-    options.timezone = 'local'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      events: '/my-feed.php',
+      timezone: 'local'
+    })
     var request = $.mockjax.mockedAjaxCalls()[0]
     expect(request.data.start).toEqual('2014-04-27')
     expect(request.data.end).toEqual('2014-06-08')
@@ -48,9 +45,10 @@ describe('events as a json feed', function() {
   })
 
   it('requests correctly when UTC timezone', function() {
-    options.events = '/my-feed.php'
-    options.timezone = 'UTC'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      events: '/my-feed.php',
+      timezone: 'UTC'
+    })
     var request = $.mockjax.mockedAjaxCalls()[0]
     expect(request.data.start).toEqual('2014-04-27')
     expect(request.data.end).toEqual('2014-06-08')
@@ -58,9 +56,10 @@ describe('events as a json feed', function() {
   })
 
   it('requests correctly when custom timezone', function() {
-    options.events = '/my-feed.php'
-    options.timezone = 'America/Chicago'
-    $('#cal').fullCalendar(options)
+    initCalendar({
+      events: '/my-feed.php',
+      timezone: 'America/Chicago'
+    })
     var request = $.mockjax.mockedAjaxCalls()[0]
     expect(request.data.start).toEqual('2014-04-27')
     expect(request.data.end).toEqual('2014-06-08')
@@ -68,60 +67,59 @@ describe('events as a json feed', function() {
   })
 
   it('requests correctly with event source extended form', function(done) {
-    var eventSource = {
-      url: '/my-feed.php',
-      className: 'customeventclass'
-    }
-    options.eventSources = [ eventSource ]
-    options.timezone = 'America/Chicago'
-    options.eventRender = function(eventObj, eventElm) {
-      var request = $.mockjax.mockedAjaxCalls()[0]
-      expect(request.data.start).toEqual('2014-04-27')
-      expect(request.data.end).toEqual('2014-06-08')
-      expect(request.data.timezone).toEqual('America/Chicago')
-      expect(eventElm).toHaveClass('customeventclass')
-      done()
-    }
-    $('#cal').fullCalendar(options)
-  })
-
-  it('accepts jQuery.ajax params', function(done) {
-    var eventSource = {
-      url: '/my-feed.php',
-      data: {
-        customParam: 'yes'
-      },
-      success: function() {
+    initCalendar({
+      eventSources: [ {
+        url: '/my-feed.php',
+        className: 'customeventclass'
+      } ],
+      timezone: 'America/Chicago',
+      eventRender: function(eventObj, eventElm) {
         var request = $.mockjax.mockedAjaxCalls()[0]
-        expect(request.data.customParam).toMatch('yes')
+        expect(request.data.start).toEqual('2014-04-27')
+        expect(request.data.end).toEqual('2014-06-08')
+        expect(request.data.timezone).toEqual('America/Chicago')
+        expect(eventElm).toHaveClass('customeventclass')
         done()
       }
-    }
-    options.eventSources = [ eventSource ]
-    $('#cal').fullCalendar(options)
+    })
+  })
+
+  it('accepts jQuery.ajax params', function(done) {
+    initCalendar({
+      eventSources: [ {
+        url: '/my-feed.php',
+        data: {
+          customParam: 'yes'
+        },
+        success: function() {
+          var request = $.mockjax.mockedAjaxCalls()[0]
+          expect(request.data.customParam).toMatch('yes')
+          done()
+        }
+      } ]
+    })
   })
 
   it('accepts a dynamic data function', function(done) {
-    var eventSource = {
-      url: '/my-feed.php',
-      data: function() {
-        return {
-          customParam: 'heckyeah'
+    initCalendar({
+      eventSources: [ {
+        url: '/my-feed.php',
+        data: function() {
+          return {
+            customParam: 'heckyeah'
+          }
         }
+      } ],
+      eventAfterAllRender: function() {
+        var request = $.mockjax.mockedAjaxCalls()[0]
+        expect(request.data.customParam).toMatch('heckyeah')
+        done()
       }
-    }
-    options.eventSources = [ eventSource ]
-    options.eventAfterAllRender = function() {
-      var request = $.mockjax.mockedAjaxCalls()[0]
-      expect(request.data.customParam).toMatch('heckyeah')
-      done()
-    }
-    $('#cal').fullCalendar(options)
+    })
   })
 
   it('calls loading callback', function(done) {
     var loadingCallArgs = []
-
     initCalendar({
       events: { url: '/my-feed.php' },
       loading: function(bool) {
@@ -136,14 +134,10 @@ describe('events as a json feed', function() {
 
   it('has and Event Source object with certain props', function() {
     var url = '/my-feed.php'
-    var source
-
     initCalendar({
       events: { url: url }
     })
-
-    source = currentCalendar.getEventSources()[0]
-    expect(source.url).toBe(url)
+    expect(currentCalendar.getEventSources()[0].url).toBe(url)
   })
 
 })

+ 2 - 5
tests/legacy/formatRange.js

@@ -1,4 +1,3 @@
-
 describe('formatRange', function() {
 
   it('doesn\'t do any splitting when dates have different years', function() {
@@ -135,8 +134,7 @@ describe('formatRange', function() {
   describe('when calendar has isRTL', function() {
 
     it('splits correctly on day when dates have same month', function() {
-      affix('#cal')
-      $('#cal').fullCalendar({
+      initCalendar({
         defaultView: 'basicWeek',
         defaultDate: '2014-05-20',
         isRTL: true,
@@ -151,8 +149,7 @@ describe('formatRange', function() {
   describe('when calendar has a customized locale', function() {
 
     it('uses locale and splits correctly on day when dates have same month', function() {
-      affix('#cal')
-      $('#cal').fullCalendar({
+      initCalendar({
         defaultView: 'basicWeek',
         defaultDate: '2014-05-20',
         locale: 'fr',

+ 3 - 10
tests/legacy/moment-construct.js

@@ -37,18 +37,11 @@ describe('moment constructor', function() {
     ]
       .forEach(function(scenario) {
         describe(scenario.description, function() {
-          var calendarObj
-
-          beforeEach(function() {
-            affix('#cal')
-            $('#cal').fullCalendar({
+          scenario.testMethod(function() {
+            initCalendar({
               timezone: scenario.timezone
             })
-            calendarObj = $('#cal').fullCalendar('getCalendar')
-          })
-
-          scenario.testMethod(function() {
-            return calendarObj.moment.apply(calendarObj, arguments)
+            return currentCalendar.moment.apply(currentCalendar, arguments)
           })
         })
       })

+ 6 - 13
tests/legacy/moment-misc.js

@@ -68,37 +68,30 @@ describe('FCMoment::time', function() {
 
 describe('FCMoment::week', function() {
 
-  beforeEach(function() {
-    affix('#cal')
-  })
-
   it('computes based on a weekNumberCalculation function', function() {
-    $('#cal').fullCalendar({
+    initCalendar({
       weekNumberCalculation: function(date) {
         expect(moment.isMoment(date)).toBe(true)
         return 999
       }
     })
-    var calendar = $('#cal').fullCalendar('getCalendar')
-    var mom = calendar.moment()
+    var mom = currentCalendar.moment()
     expect(mom.week()).toBe(999)
   })
 
   it('computes based on a weekNumberCalculation "ISO" value', function() {
-    $('#cal').fullCalendar({
+    initCalendar({
       weekNumberCalculation: 'ISO'
     })
-    var calendar = $('#cal').fullCalendar('getCalendar')
-    var mom = calendar.moment('2015-02-22') // is 9 local week, 8 ISO week
+    var mom = currentCalendar.moment('2015-02-22') // is 9 local week, 8 ISO week
     expect(mom.week()).toBe(8)
   })
 
   it('computes based on a weekNumberCalculation "local" value', function() {
-    $('#cal').fullCalendar({
+    initCalendar({
       weekNumberCalculation: 'local'
     })
-    var calendar = $('#cal').fullCalendar('getCalendar')
-    var mom = calendar.moment('2015-02-22') // is 9 local week, 8 ISO week
+    var mom = currentCalendar.moment('2015-02-22') // is 9 local week, 8 ISO week
     expect(mom.week()).toBe(9)
   })
 })

+ 28 - 29
tests/legacy/now.js

@@ -1,57 +1,56 @@
 describe('now', function() {
 
-  var options
-
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultDate: '2014-05-01'
-    }
+  pushOptions({
+    defaultDate: '2014-05-01'
   })
 
   describe('when month view', function() {
-    beforeEach(function() {
-      options.defaultView = 'month'
+    pushOptions({
+      defaultView: 'month'
     })
     it('changes the highlighted day when customized', function() {
-      options.now = '2014-05-06'
-      $('#cal').fullCalendar(options)
-      var todayCell = $('#cal td.fc-today')
+      initCalendar({
+        now: '2014-05-06'
+      })
+      var todayCell = $('td.fc-today', currentCalendar.el)
       var todayDate = todayCell.data('date')
       expect(todayDate).toEqual('2014-05-06')
     })
   })
 
   describe('when agendaWeek view', function() {
-    beforeEach(function() {
-      options.defaultView = 'agendaWeek'
+    pushOptions({
+      defaultView: 'agendaWeek'
     })
     it('changes the highlighted day when customized', function() {
-      options.now = '2014-04-29T12:00:00'
-      $('#cal').fullCalendar(options)
-      var todayCell = $('#cal td.fc-today')
+      initCalendar({
+        now: '2014-04-29T12:00:00'
+      })
+      var todayCell = $('td.fc-today', currentCalendar.el)
       expect(todayCell.data('date')).toBe('2014-04-29')
     })
   })
 
   it('accepts a function that returns a moment', function() {
-    options.defaultView = 'month'
-    options.now = function() {
-      return moment.utc('2014-05-01')
-    }
-    $('#cal').fullCalendar(options)
-    var todayCell = $('#cal td.fc-today')
+    initCalendar({
+      defaultView: 'month',
+      now: function() {
+        return moment.utc('2014-05-01')
+      }
+    })
+    var todayCell = $('td.fc-today', currentCalendar.el)
     var todayDate = todayCell.data('date')
     expect(todayDate).toEqual('2014-05-01')
   })
 
   it('accepts a function that returns a moment-ish string', function() {
-    options.defaultView = 'month'
-    options.now = function() {
-      return '2014-05-01'
-    }
-    $('#cal').fullCalendar(options)
-    var todayCell = $('#cal td.fc-today')
+    initCalendar({
+      defaultView: 'month',
+      now: function() {
+        return '2014-05-01'
+      }
+    })
+    var todayCell = $('td.fc-today', currentCalendar.el)
     var todayDate = todayCell.data('date')
     expect(todayDate).toEqual('2014-05-01')
   })

+ 19 - 19
tests/legacy/selectAllow.js

@@ -1,28 +1,26 @@
 import { selectTimeGrid } from '../lib/time-grid'
 
 describe('selectAllow', function() {
-  var options
-
-  beforeEach(function() {
-    options = {
-      now: '2016-09-04',
-      defaultView: 'agendaWeek',
-      scrollTime: '00:00',
-      selectable: true
-    }
-    affix('#cal')
+
+  pushOptions({
+    now: '2016-09-04',
+    defaultView: 'agendaWeek',
+    scrollTime: '00:00',
+    selectable: true
   })
 
   it('disallows selecting when returning false', function(done) { // and given correct params
-    options.selectAllow = function(selectInfo) {
-      expect(typeof selectInfo).toBe('object')
-      expect(moment.isMoment(selectInfo.start)).toBe(true)
-      expect(moment.isMoment(selectInfo.end)).toBe(true)
-      return false
+    var options = {
+      selectAllow: function(selectInfo) {
+        expect(typeof selectInfo).toBe('object')
+        expect(moment.isMoment(selectInfo.start)).toBe(true)
+        expect(moment.isMoment(selectInfo.end)).toBe(true)
+        return false
+      }
     }
     spyOn(options, 'selectAllow').and.callThrough()
 
-    $('#cal').fullCalendar(options)
+    initCalendar(options)
 
     selectTimeGrid('2016-09-04T01:00:00', '2016-09-04T05:00:00')
       .then(function(selectInfo) {
@@ -33,12 +31,14 @@ describe('selectAllow', function() {
   })
 
   it('allows selecting when returning true', function(done) {
-    options.selectAllow = function(selectInfo) {
-      return true
+    var options = {
+      selectAllow: function(selectInfo) {
+        return true
+      }
     }
     spyOn(options, 'selectAllow').and.callThrough()
 
-    $('#cal').fullCalendar(options)
+    initCalendar(options)
 
     selectTimeGrid('2016-09-04T01:00:00', '2016-09-04T05:00:00')
       .then(function(selectInfo) {

+ 11 - 14
tests/legacy/selectHelper.js

@@ -1,22 +1,19 @@
 describe('selectHelper', function() {
-  var options
 
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      defaultDate: '2014-08-03',
-      defaultView: 'agendaWeek',
-      scrollTime: '00:00:00',
-      selectHelper: true
-    }
+  pushOptions({
+    defaultDate: '2014-08-03',
+    defaultView: 'agendaWeek',
+    scrollTime: '00:00:00',
+    selectHelper: true
   })
 
   it('goes through eventRender', function() {
-    options.eventRender = function(event, element, view) {
-      element.addClass('didEventRender')
-    }
-    $('#cal').fullCalendar(options)
-    $('#cal').fullCalendar('select', '2014-08-04T01:00:00', '2014-08-04T04:00:00')
+    initCalendar({
+      eventRender: function(event, element, view) {
+        element.addClass('didEventRender')
+      }
+    })
+    currentCalendar.select('2014-08-04T01:00:00', '2014-08-04T04:00:00')
     expect($('.fc-helper')).toHaveClass('didEventRender')
   })
 })

+ 22 - 23
tests/legacy/themeButtonIcons.js

@@ -1,6 +1,13 @@
 describe('themeButtonIcons', function() {
 
-  var options
+  pushOptions({
+    header: {
+      left: 'prevYear,prev,next,nextYear today',
+      center: 'title',
+      right: 'month,agendaWeek,agendaDay'
+    }
+  })
+
   var defaultSelectors = [
     '.ui-icon-circle-triangle-w',
     '.ui-icon-circle-triangle-e',
@@ -8,23 +15,14 @@ describe('themeButtonIcons', function() {
     '.ui-icon-seek-next'
   ]
 
-  beforeEach(function() {
-    affix('#cal')
-    options = {
-      header: {
-        left: 'prevYear,prev,next,nextYear today',
-        center: 'title',
-        right: 'month,agendaWeek,agendaDay'
-      }
-    }
-  })
-
   describe('when theme is off', function() {
-    beforeEach(function() {
-      options.theme = false
+
+    pushOptions({
+      theme: false
     })
+
     it('should not have any of the default theme icon classes', function() {
-      $('#cal').fullCalendar(options)
+      initCalendar()
       defaultSelectors.forEach(function(selector) {
         expect($(selector)).not.toBeInDOM()
       })
@@ -33,23 +31,24 @@ describe('themeButtonIcons', function() {
 
   describe('when theme is on', function() {
 
-    beforeEach(function() {
-      options.theme = true
+    pushOptions({
+      theme: true
     })
 
     it('should have all of the deafult theme icon classes', function() {
-      $('#cal').fullCalendar(options)
+      initCalendar()
       defaultSelectors.forEach(function(selector) {
         expect($(selector)).toBeInDOM()
       })
     })
 
     it('should accept values that override the individual defaults', function() {
-      options.themeButtonIcons = {
-        prev: 'arrowthickstop-1-w',
-        next: 'arrowthickstop-1-e'
-      }
-      $('#cal').fullCalendar(options);
+      initCalendar({
+        themeButtonIcons: {
+          prev: 'arrowthickstop-1-w',
+          next: 'arrowthickstop-1-e'
+        }
+      });
       [
         '.ui-icon-arrowthickstop-1-w',
         '.ui-icon-arrowthickstop-1-e',

+ 3 - 5
tests/lib/time-grid.js

@@ -3,15 +3,14 @@ import { getBoundingRect } from '../lib/dom-geom'
 
 export function dragTimeGridEvent(eventEl, dropDate) {
   return new Promise(function(resolve) {
-    var calendar = $('#cal').fullCalendar('getCalendar')
     var modifiedEvent = null
 
-    calendar.on('eventDragStop', function() {
+    currentCalendar.on('eventDragStop', function() {
       setTimeout(function() { // wait for eventDrop to be called
         resolve(modifiedEvent)
       })
     })
-    calendar.on('eventDrop', function(event) {
+    currentCalendar.on('eventDrop', function(event) {
       modifiedEvent = event
     })
 
@@ -25,10 +24,9 @@ export function dragTimeGridEvent(eventEl, dropDate) {
 
 export function selectTimeGrid(start, inclusiveEnd) {
   return new Promise(function(resolve) {
-    var calendar = $('#cal').fullCalendar('getCalendar')
     var selectInfo = null
 
-    calendar.on('select', function(start, end) {
+    currentCalendar.on('select', function(start, end) {
       selectInfo = { start: start, end: end }
     })