Kaynağa Gözat

begining of new event source tests

Adam Shaw 7 yıl önce
ebeveyn
işleme
6363ba36df

+ 12 - 0
tests/automated/event-source/getEventSourceById.js

@@ -0,0 +1,12 @@
+describe('getEventSourceById', function() {
+
+  xit('correctly retrieves an event source provided via `events` at initialization', function() {
+  })
+
+  xit('correctly retrieves an event source provided via `eventSources` at initialization', function() {
+  })
+
+  xit('correctly retrieves an event source provided via `addEventSource` method', function() {
+  })
+
+})

+ 12 - 0
tests/automated/event-source/getEventSources.js

@@ -0,0 +1,12 @@
+describe('getEventSources', function() {
+
+  xit('correctly retrieves event sources provided via `events` at initialization', function() {
+  })
+
+  xit('correctly retrieves event sources provided via `eventSources` at initialization', function() {
+  })
+
+  xit('correctly retrieves event sources provided via `addEventSource` method', function() {
+  })
+
+})

+ 7 - 43
tests/automated/legacy/refetchEventSources.js → tests/automated/event-source/refetch.js

@@ -1,4 +1,4 @@
-describe('refetchEventSources', function() {
+describe('event source refetch', function() {
 
   // used by createEventGenerator
   var eventCount
@@ -16,57 +16,25 @@ describe('refetchEventSources', function() {
     scrollTime: '00:00',
     eventSources: [
       {
-        id: 1,
+        id: 'green0',
         events: createEventGenerator('source1-'),
         color: 'green'
       },
       {
-        id: 2,
+        id: 'blue',
         events: createEventGenerator('source2-'),
         color: 'blue'
       },
       {
-        id: 3,
+        id: 'green1',
         events: createEventGenerator('source3-'),
         color: 'green'
       }
     ]
   })
 
-  describe('with a single event source passed in', function() {
-    it('only refetches events for the specified event source', function(done) {
-      initCalendar()
-
-      expect($('.source1-7').length).toEqual(1)
-      expect($('.source2-7').length).toEqual(1)
-      expect($('.source3-7').length).toEqual(1)
-
-      var allEventSources = currentCalendar.getEventSources()
-      var blueEventSource = $.grep(allEventSources, function(eventSource) {
-        return eventSource.color === 'blue'
-      })[0]
-
-      // increase the number of events for the refetched source
-      eventCount = 2
-      fetchId = 8
-
-      currentCalendar.refetchEventSources(blueEventSource)
-
-      // events from unaffected sources remain
-      expect($('.source1-7').length).toEqual(1)
-      expect($('.source3-7').length).toEqual(1)
-
-      // events from old fetch were cleared
-      expect($('.source2-7').length).toEqual(0)
-
-      // events from new fetch were rendered
-      expect($('.source2-8').length).toEqual(2)
-
-      done()
-    })
-  })
-  describe('with a single event source ID passed in', function() {
-    it('only refetches events for the specified event source', function(done) {
+  describe('with a single event source', function() { // reword this stuff
+    it('will be refetched', function() {
       initCalendar()
 
       expect($('.source1-7').length).toEqual(1)
@@ -88,13 +56,11 @@ describe('refetchEventSources', function() {
 
       // events from new fetch were rendered
       expect($('.source2-8').length).toEqual(2)
-
-      done()
     })
   })
 
   describe('multiple event sources', function() {
-    it('will be refetched', function(done) {
+    it('will be refetched', function() {
       initCalendar()
 
       expect($('.source1-7').length).toEqual(1)
@@ -118,8 +84,6 @@ describe('refetchEventSources', function() {
       // events from new fetch were rendered
       expect($('.source1-8').length).toEqual(2)
       expect($('.source3-8').length).toEqual(2)
-
-      done()
     })
   })
 

+ 80 - 0
tests/automated/event-source/remove.js

@@ -0,0 +1,80 @@
+describe('event source remove', function() {
+  pushOptions({
+    defaultDate: '2014-08-01'
+  })
+
+  it('correctly removes events provided via `eventSources` at initialization', function(done) {
+    var callCnt = 0
+
+    initCalendar({
+      eventSources: [ {
+        id: '5',
+        events: [
+          { title: 'event1', start: '2014-08-01' },
+          { title: 'event2', start: '2014-08-02' }
+        ]
+      } ],
+      eventAfterAllRender() {
+        callCnt++
+        if (callCnt === 1) {
+          expectEventCnt(2)
+          currentCalendar.getEventSourceById('5').remove()
+        } else if (callCnt === 2) {
+          expectEventCnt(0)
+          done()
+        }
+      }
+    })
+  })
+
+  it('won\'t render removed events when subsequent addEventSource', function(done) {
+
+    var source1 = {
+      id: '1',
+      events: function(arg, callback) {
+        setTimeout(function() {
+          callback([ {
+            title: 'event1',
+            className: 'event1',
+            start: '2014-08-01T02:00:00'
+          } ])
+        }, 100)
+      }
+    }
+
+    var source2 = {
+      id: '2',
+      events: function(arg, callback) {
+        setTimeout(function() {
+          callback([ {
+            title: 'event2',
+            className: 'event2',
+            start: '2014-08-01T02:00:00'
+          } ])
+        }, 100)
+      }
+    }
+
+    initCalendar({
+      eventSources: [ source1 ],
+      eventAfterAllRender() {
+        if (!$('.fc-event').length) {
+          ; // might have rendered no events after removeEventSource call
+        } else {
+          expect($('.event1').length).toBe(0)
+          expect($('.event2').length).toBe(1)
+          done()
+        }
+      }
+    })
+
+    currentCalendar.getEventSourceById('1').remove()
+    currentCalendar.addEventSource(source2)
+  })
+
+  function expectEventCnt(cnt) {
+    expect($('.fc-event').length).toBe(cnt)
+    expect(currentCalendar.getEvents().length).toBe(cnt)
+  }
+
+})

+ 0 - 161
tests/automated/legacy/removeEventSource.js

@@ -1,161 +0,0 @@
-describe('removeEventSource', function() {
-  pushOptions({
-    defaultDate: '2014-08-01'
-  })
-
-  beforeEach(function() {
-    XHRMock.setup()
-    XHRMock.get(/.*/, {
-      status: 200,
-      headers: { 'content-type': 'application/json' },
-      body: JSON.stringify(buildEventArray())
-    })
-  })
-
-  afterEach(function() {
-    XHRMock.teardown()
-  })
-
-  describe('with a URL', function() {
-    testInput('/myscript.php') // will go to mockjax
-  })
-
-  describe('with an array', function() {
-    testInput(buildEventArray())
-  })
-
-  describe('with a function', function() {
-    testInput(function(arg, callback) {
-      callback(buildEventArray())
-    })
-  })
-
-  describe('with an object+url', function() {
-    testInput({
-      url: '/myscript.php' // will go to mockjax
-    })
-  })
-
-  describe('with an object+array', function() {
-    testInput({
-      events: buildEventArray()
-    })
-  })
-
-  describe('with an object+function', function() {
-    testInput({
-      events: function(arg, callback) {
-        callback(buildEventArray())
-      }
-    })
-  })
-
-  it('won\'t render removed events when subsequent addEventSource', function(done) {
-
-    var source1 = function(arg, callback) {
-      setTimeout(function() {
-        callback([ {
-          title: 'event1',
-          className: 'event1',
-          start: '2014-08-01T02:00:00'
-        } ])
-      }, 100)
-    }
-
-    var source2 = function(arg, callback) {
-      setTimeout(function() {
-        callback([ {
-          title: 'event2',
-          className: 'event2',
-          start: '2014-08-01T02:00:00'
-        } ])
-      }, 100)
-    }
-
-    initCalendar({
-      eventSources: [ source1 ],
-      eventAfterAllRender() {
-        if (!$('.fc-event').length) {
-          ; // might have rendered no events after removeEventSource call
-        } else {
-          expect($('.event1').length).toBe(0)
-          expect($('.event2').length).toBe(1)
-          done()
-        }
-      }
-    })
-
-    currentCalendar.getEventSources()[0].remove()
-    currentCalendar.addEventSource(source2)
-  })
-
-  function testInput(eventInput) {
-
-    it('correctly removes events provided via `events` at initialization', function(done) {
-      var callCnt = 0
-
-      initCalendar({
-        events: eventInput,
-        eventAfterAllRender() {
-          callCnt++
-          if (callCnt === 1) {
-            expectEventCnt(2)
-            currentCalendar.removeEventSource(eventInput)
-          } else if (callCnt === 2) {
-            expectEventCnt(0)
-            done()
-          }
-        }
-      })
-    })
-
-    it('correctly removes events provided via `eventSources` at initialization', function(done) {
-      var callCnt = 0
-
-      initCalendar({
-        eventSources: [ eventInput ],
-        eventAfterAllRender() {
-          callCnt++
-          if (callCnt === 1) {
-            expectEventCnt(2)
-            currentCalendar.removeEventSource(eventInput)
-          } else if (callCnt === 2) {
-            expectEventCnt(0)
-            done()
-          }
-        }
-      })
-    })
-
-    it('correctly removes events provided via `addEventSource` method', function(done) {
-      var callCnt = 0
-
-      initCalendar({
-        eventAfterAllRender() {
-          callCnt++
-          if (callCnt === 1) {
-            currentCalendar.addEventSource(eventInput)
-          } else if (callCnt === 2) {
-            expectEventCnt(2)
-            currentCalendar.removeEventSource(eventInput)
-          } else if (callCnt === 3) {
-            expectEventCnt(0)
-            done()
-          }
-        }
-      })
-    })
-  }
-
-  function buildEventArray() {
-    return [
-      { title: 'event1', start: '2014-08-01' },
-      { title: 'event2', start: '2014-08-02' }
-    ]
-  }
-
-  function expectEventCnt(cnt) {
-    expect($('.fc-event').length).toBe(cnt)
-    expect(currentCalendar.getEvents().length).toBe(cnt)
-  }
-})