2
0
Эх сурвалжийг харах

bunch of tests for mutation api

Adam Shaw 7 жил өмнө
parent
commit
cb60e0e2aa

+ 69 - 0
tests/automated/event-data/Event.moveDates.js

@@ -0,0 +1,69 @@
+
+describe('Event::moveDates', function() {
+  pushOptions({
+    timeZone: 'UTC'
+  })
+
+  describe('when event doesn\'t have an end', function() {
+    it('moves start and keeps end null', function() {
+      initCalendar({
+        events: [
+          { id: '1', start: '2018-09-03T00:00:00' }
+        ]
+      })
+      let event = currentCalendar.getEventById('1')
+      event.moveDates({ days: 1, hours: 1 })
+      expect(event.start).toEqualDate('2018-09-04T01:00:00Z')
+      expect(event.end).toBe(null)
+    })
+  })
+
+  describe('when event does have an end', function() {
+    it('moves start and end by same delta', function() {
+      initCalendar({
+        events: [
+          { id: '1', start: '2018-09-03T00:00:00', end: '2018-09-04T12:00:00' }
+        ]
+      })
+      let event = currentCalendar.getEventById('1')
+      event.moveDates({ days: 1, hours: 1 })
+      expect(event.start).toEqualDate('2018-09-04T01:00:00Z')
+      expect(event.end).toEqualDate('2018-09-05T13:00:00Z')
+    })
+  })
+
+  it('moves related events of different duration by same delta', function() {
+    initCalendar({
+      events: [
+        { id: '1', groupId: 'a', start: '2018-09-03T00:00:00', end: '2018-09-04T12:00:00' },
+        { id: '2', groupId: 'a', start: '2018-10-03T00:00:00', end: '2018-10-04T12:00:00' },
+      ]
+    })
+    let event1 = currentCalendar.getEventById('1')
+    event1.moveDates({ days: 1, hours: 1 })
+    expect(event1.start).toEqualDate('2018-09-04T01:00:00Z')
+    expect(event1.end).toEqualDate('2018-09-05T13:00:00Z')
+
+    let event2 = currentCalendar.getEventById('2')
+    expect(event2.start).toEqualDate('2018-10-04T01:00:00Z')
+    expect(event2.end).toEqualDate('2018-10-05T13:00:00Z')
+  })
+
+  it('does not move unrelated events', function() {
+    initCalendar({
+      events: [
+        { id: '1', groupId: 'a', start: '2018-09-03T00:00:00', end: '2018-09-04T12:00:00' },
+        { id: '2', groupId: 'bbb', start: '2018-10-03T00:00:00', end: '2018-10-04T12:00:00' },
+      ]
+    })
+    let event1 = currentCalendar.getEventById('1')
+    event1.moveDates({ days: 1, hours: 1 })
+    expect(event1.start).toEqualDate('2018-09-04T01:00:00Z')
+    expect(event1.end).toEqualDate('2018-09-05T13:00:00Z')
+
+    let event2 = currentCalendar.getEventById('2')
+    expect(event2.start).toEqualDate('2018-10-03T00:00:00Z') // same
+    expect(event2.end).toEqualDate('2018-10-04T12:00:00Z') // same
+  })
+
+})

+ 39 - 0
tests/automated/event-data/Event.moveEnd.js

@@ -0,0 +1,39 @@
+describe('Event::moveEnd', function() {
+  pushOptions({
+    timeZone: 'UTC',
+    defaultTimedEventDuration: '01:00'
+  })
+
+  describe('when event doesn\'t have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-03T12:00:00' }
+      ]
+    })
+
+    it('generates a new end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.moveEnd('01:00')
+      expect(event.start).toEqualDate('2018-09-03T12:00:00Z')
+      expect(event.end).toEqualDate('2018-09-03T14:00:00Z')
+    })
+  })
+
+  describe('when event does have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-03T12:00:00', end: '2018-09-03T15:00:00' }
+      ]
+    })
+
+    it('moves end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.moveEnd('01:00')
+      expect(event.start).toEqualDate('2018-09-03T12:00:00Z')
+      expect(event.end).toEqualDate('2018-09-03T16:00:00Z')
+    })
+  })
+
+})

+ 55 - 0
tests/automated/event-data/Event.moveStart.js

@@ -0,0 +1,55 @@
+describe('Event::moveStart', function() {
+  pushOptions({
+    timeZone: 'UTC',
+    defaultTimedEventDuration: '01:00'
+  })
+
+  describe('when event doesn\'t have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-03T12:00:00' }
+      ]
+    })
+
+    it('moves start and generates an end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.moveStart({ hours: -5 })
+      expect(event.start).toEqualDate('2018-09-03T07:00:00Z')
+      expect(event.end).toEqualDate('2018-09-03T13:00:00Z')
+    })
+  })
+
+  describe('when event does have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-03T12:00:00', end: '2018-09-03T15:00:00' }
+      ]
+    })
+
+    it('moves start and keeps end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.moveStart({ hours: -5 })
+      expect(event.start).toEqualDate('2018-09-03T07:00:00Z')
+      expect(event.end).toEqualDate('2018-09-03T15:00:00Z')
+    })
+  })
+
+  describe('when moving start past end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-03T12:00:00', end: '2018-09-03T15:00:00' }
+      ]
+    })
+
+    it('resets end to reflect default duration', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.moveStart({ days: 1 })
+      expect(event.start).toEqualDate('2018-09-04T12:00:00Z')
+      expect(event.end).toEqualDate('2018-09-04T13:00:00Z')
+    })
+  })
+
+})

+ 42 - 0
tests/automated/event-data/Event.mutation.js

@@ -0,0 +1,42 @@
+
+describe('event mutations on non-instances', function() {
+  pushOptions({
+    defaultView: 'basicWeek',
+    now: '2018-09-03',
+    events: [
+      { id: '1', start: '2018-09-04', rendering: 'inverse-background' }
+    ]
+  })
+
+  describe('with date mutating', function() {
+    it('doesn\'t do anything', function() {
+      let renderCnt = 0
+
+      initCalendar({
+        eventRender(arg) {
+          renderCnt++
+          if (renderCnt === 1) {
+            arg.event.moveStart('-01:00')
+            arg.event.moveEnd('01:00')
+            arg.event.moveDates({ days: 1 })
+            arg.event.setIsAllDay(false)
+          } else if (renderCnt == 2) {
+            arg.event.setStart('2018-08-04')
+            arg.event.setEnd('2018-10-04')
+            arg.event.setDates('2018-08-04', '2018-10-04')
+          }
+        }
+      })
+
+      expect(renderCnt).toBe(2)
+
+      let event = currentCalendar.getEventById('1')
+      expect(event.start).toEqualDate('2018-09-04')
+      expect(event.end).toBe(null)
+      expect(event.isAllDay).toBe(true)
+    })
+  })
+
+  // TODO: test for non-instances to have other props and extended props modified
+
+})

+ 110 - 0
tests/automated/event-data/Event.setDates.js

@@ -0,0 +1,110 @@
+describe('Event::setDates', function() {
+  pushOptions({
+    now: '2018-09-03',
+    timeZone: 'UTC',
+    defaultTimedEventDuration: '01:00',
+    events: [
+      { id: '1', start: '2018-09-05T12:00:00' }
+    ]
+  })
+
+  describe('when setting different start', function() {
+    it('changes start and gives it an end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.setDates('2018-09-05T14:00:00', '2018-09-05T16:00:00')
+      expect(event.start).toEqualDate('2018-09-05T14:00:00Z')
+      expect(event.end).toEqualDate('2018-09-05T16:00:00Z')
+    })
+  })
+
+  describe('when setting same start and end', function() {
+    it('changes nothing and end remains null', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.setDates('2018-09-05T12:00:00', '2018-09-05T13:00:00')
+      expect(event.start).toEqualDate('2018-09-05T12:00:00Z')
+      expect(event.end).toBe(null)
+    })
+  })
+
+  describe('when setting different end', function() {
+    it('changes end and gives it an end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.setDates('2018-09-05T12:00:00', '2018-09-05T18:00:00')
+      expect(event.start).toEqualDate('2018-09-05T12:00:00Z')
+      expect(event.end).toEqualDate('2018-09-05T18:00:00Z')
+    })
+  })
+
+  describe('when setting different start AND end', function() {
+    describe('if duration is effectively the same', function() {
+      it('changes start and leaves end null', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setDates('2018-09-06T01:00:00', '2018-09-06T02:00:00')
+        expect(event.start).toEqualDate('2018-09-06T01:00:00Z')
+        expect(event.end).toBe(null)
+      })
+    })
+  })
+
+  describe('when called with a null end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-05T12:00:00', end: '2018-09-05T14:00:00' }
+      ]
+    })
+
+    it('clears the end', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.setDates('2018-09-06T01:00:00', null)
+      expect(event.start).toEqualDate('2018-09-06T01:00:00Z')
+      expect(event.end).toBe(null)
+    })
+  })
+
+  it('can set isAllDay to true', function() {
+    initCalendar() // { id: '1', start: '2018-09-05T12:00:00' }
+    let event = currentCalendar.getEventById('1')
+    event.setDates('2018-09-06', '2018-09-10', { isAllDay: true })
+    expect(event.start).toEqualDate('2018-09-06')
+    expect(event.end).toEqualDate('2018-09-10')
+    expect(event.isAllDay).toBe(true)
+  })
+
+  it('can set isAllDay to false', function() {
+    initCalendar({
+      events: [
+        { id: '1', start: '2018-09-05', end: '2018-09-08' }
+      ]
+    })
+
+    let event = currentCalendar.getEventById('1')
+    event.setDates('2018-09-06T10:00:00', '2018-09-10T02:00:00', { isAllDay: false })
+    expect(event.start).toEqualDate('2018-09-06T10:00:00Z')
+    expect(event.end).toEqualDate('2018-09-10T02:00:00Z')
+    expect(event.isAllDay).toBe(false)
+  })
+
+  it('shortens related events of different duration by same delta', function() {
+    initCalendar({
+      events: [
+        { id: '1', groupId: 'a', start: '2018-09-03', end: '2018-09-05' },
+        { id: '2', groupId: 'a', start: '2018-09-13', end: '2018-09-15' }
+      ]
+    })
+
+    let event1 = currentCalendar.getEventById('1')
+    event1.setDates('2018-09-02', '2018-09-06') // start back by 1, end ahead by 1
+    expect(event1.start).toEqualDate('2018-09-02')
+    expect(event1.end).toEqualDate('2018-09-06')
+
+    let event2 = currentCalendar.getEventById('2')
+    expect(event2.start).toEqualDate('2018-09-12')
+    expect(event2.end).toEqualDate('2018-09-16')
+  })
+
+})

+ 58 - 0
tests/automated/event-data/Event.setEnd.js

@@ -0,0 +1,58 @@
+describe('Event::setEnd', function() {
+  pushOptions({
+    now: '2018-09-03',
+    timeZone: 'UTC',
+    defaultTimedEventDuration: '01:00'
+  })
+
+  describe('when event doesn\'t have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-10T00:00:00' }
+      ]
+    })
+
+    it('sets end and keeps start', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.setEnd('2018-09-12T02:00:00')
+      expect(event.start).toEqualDate('2018-09-10T00:00:00Z')
+      expect(event.end).toEqualDate('2018-09-12T02:00:00Z')
+    })
+  })
+
+  describe('when event does have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-10T00:00:00', end: '2018-09-11T00:00:00' }
+      ]
+    })
+
+    it('changes end and keeps start', function() {
+      initCalendar()
+      let event = currentCalendar.getEventById('1')
+      event.setEnd('2018-09-12T02:00:00')
+      expect(event.start).toEqualDate('2018-09-10T00:00:00Z')
+      expect(event.end).toEqualDate('2018-09-12T02:00:00Z')
+    })
+  })
+
+  it('shortens related events of different duration by same delta', function() {
+    initCalendar({
+      events: [
+        { id: '1', groupId: 'a', start: '2018-09-10T00:00:00', end: '2018-09-11T00:00:00' },
+        { id: '2', groupId: 'a', start: '2018-09-14T00:00:00', end: '2018-09-16T00:00:00' }
+      ]
+    })
+
+    let event1 = currentCalendar.getEventById('1')
+    event1.setEnd('2018-09-12T02:00:00') // move end forward by 1 day, 2 hours
+    expect(event1.start).toEqualDate('2018-09-10T00:00:00Z')
+    expect(event1.end).toEqualDate('2018-09-12T02:00:00Z')
+
+    let event2 = currentCalendar.getEventById('2')
+    expect(event2.start).toEqualDate('2018-09-14T00:00:00Z')
+    expect(event2.end).toEqualDate('2018-09-17T02:00:00Z')
+  })
+
+})

+ 117 - 0
tests/automated/event-data/Event.setIsAllDay.js

@@ -0,0 +1,117 @@
+describe('Event::setIsAllDay', function() {
+
+  describe('when setting from all-day to all-day', function() {
+    it('causes no change', function() {
+      initCalendar({
+        events: [
+          { id: '1', start: '2018-09-03', end: '2018-09-05', isAllDay: true }
+        ]
+      })
+      let event = currentCalendar.getEventById('1')
+      event.setIsAllDay(true)
+      expect(event.start).toEqualDate('2018-09-03')
+      expect(event.end).toEqualDate('2018-09-05')
+      expect(event.isAllDay).toBe(true)
+    })
+  })
+
+  describe('when setting from timed to timed', function() {
+    it('causes no change', function() {
+      initCalendar({
+        events: [
+          { id: '1', start: '2018-09-03T09:00:00', end: '2018-09-05T09:00:00', isAllDay: false }
+        ]
+      })
+      let event = currentCalendar.getEventById('1')
+      event.setIsAllDay(false)
+      expect(event.start).toEqualDate('2018-09-03T09:00:00Z')
+      expect(event.end).toEqualDate('2018-09-05T09:00:00Z')
+      expect(event.isAllDay).toBe(false)
+    })
+  })
+
+  describe('when setting from all-day to timed', function() {
+
+    describe('when not maintaining duration', function() {
+      it('removes the end', function() {
+        initCalendar({
+          events: [
+            { id: '1', start: '2018-09-03', end: '2018-09-05', isAllDay: true }
+          ]
+        })
+        let event = currentCalendar.getEventById('1')
+        event.setIsAllDay(false)
+        expect(event.start).toEqualDate('2018-09-03')
+        expect(event.end).toBe(null)
+        expect(event.isAllDay).toBe(false)
+      })
+    })
+
+    describe('when maintaining duration', function() {
+      it('keeps exact duration', function() {
+        initCalendar({
+          events: [
+            { id: '1', start: '2018-09-03', end: '2018-09-05', isAllDay: true }
+          ]
+        })
+        let event = currentCalendar.getEventById('1')
+        event.setIsAllDay(false, { maintainDuration: true })
+        expect(event.start).toEqualDate('2018-09-03')
+        expect(event.end).toEqualDate('2018-09-05')
+        expect(event.isAllDay).toBe(false)
+      })
+    })
+
+  })
+
+  describe('when setting from timed to all-day', function() {
+
+    describe('when not maintaining duration', function() {
+      it('removes the end', function() {
+        initCalendar({
+          events: [
+            { id: '1', start: '2018-09-03T09:00:00', end: '2018-09-05T09:00:00', isAllDay: false }
+          ]
+        })
+        let event = currentCalendar.getEventById('1')
+        event.setIsAllDay(true)
+        expect(event.start).toEqualDate('2018-09-03')
+        expect(event.end).toBe(null)
+        expect(event.isAllDay).toBe(true)
+      })
+    })
+
+    describe('when maintaining duration', function() {
+      it('rounds the end down to the prev whole day', function() {
+        initCalendar({
+          events: [
+            { id: '1', start: '2018-09-03T09:00:00', end: '2018-09-05T10:00:00', isAllDay: false }
+          ]
+        })
+        let event = currentCalendar.getEventById('1')
+        event.setIsAllDay(true, { maintainDuration: true })
+        expect(event.start).toEqualDate('2018-09-03')
+        expect(event.end).toEqualDate('2018-09-05')
+        expect(event.isAllDay).toBe(true)
+      })
+    })
+
+    describe('when maintaining duration (from calendar setting)', function() {
+      it('rounds the end to the next whole day', function() {
+        initCalendar({
+          isAllDayMaintainDuration: true,
+          events: [
+            { id: '1', start: '2018-09-03T09:00:00', end: '2018-09-05T10:00:00', isAllDay: false }
+          ]
+        })
+        let event = currentCalendar.getEventById('1')
+        event.setIsAllDay(true)
+        expect(event.start).toEqualDate('2018-09-03')
+        expect(event.end).toEqualDate('2018-09-05')
+        expect(event.isAllDay).toBe(true)
+      })
+    })
+
+  })
+
+})

+ 115 - 0
tests/automated/event-data/Event.setStart.js

@@ -0,0 +1,115 @@
+describe('Event::setStart', function() {
+  pushOptions({
+    now: '2018-09-03',
+    timeZone: 'UTC',
+    defaultTimedEventDuration: '01:00'
+  })
+
+  describe('when event doesn\'t have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-05T00:00:00' }
+      ]
+    })
+
+    describe('when not maintaining duration', function() {
+      it('moves start and gives event an end', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setStart('2018-09-01')
+        expect(event.start).toEqualDate('2018-09-01T00:00:00Z')
+        expect(event.end).toEqualDate('2018-09-05T01:00:00Z')
+      })
+    })
+
+    describe('when maintaining duration', function() {
+      it('moves start and keeps no end', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setStart('2018-09-01', { maintainDuration: true })
+        expect(event.start).toEqualDate('2018-09-01')
+        expect(event.end).toBe(null)
+      })
+    })
+
+  })
+
+  describe('when event does have an end', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-05T00:00:00', end: '2018-09-07T00:00:00' }
+      ]
+    })
+
+    describe('when not maintaining duration', function() {
+      it('moves start and keeps the same end', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setStart('2018-09-01')
+        expect(event.start).toEqualDate('2018-09-01')
+        expect(event.end).toEqualDate('2018-09-07')
+      })
+    })
+
+    describe('when maintaining duration', function() {
+      it('move start and keeps the end', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setStart('2018-09-01', { maintainDuration: true })
+        expect(event.start).toEqualDate('2018-09-01')
+        expect(event.end).toEqualDate('2018-09-03')
+      })
+    })
+
+  })
+
+  describe('when event is all-day', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-05', end: '2018-09-07', isAllDay: true }
+      ]
+    })
+
+    describe('when setting start to another all-day', function() {
+      it('moves start', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setStart('2018-09-01')
+        expect(event.start).toEqualDate('2018-09-01')
+        expect(event.end).toEqualDate('2018-09-07')
+        expect(event.isAllDay).toBe(true)
+      })
+    })
+
+    describe('when setting start to timed', function() {
+      it('moves start to rounded-down start-of-day', function() {
+        initCalendar()
+        let event = currentCalendar.getEventById('1')
+        event.setStart('2018-09-01T23:00:00')
+        expect(event.start).toEqualDate('2018-09-01')
+        expect(event.end).toEqualDate('2018-09-07')
+        expect(event.isAllDay).toBe(true)
+      })
+    })
+
+  })
+
+  it('shortens related events of different duration by same delta', function() {
+    initCalendar({
+      events: [
+        { id: '1', groupId: 'a', start: '2018-09-05T00:00:00', end: '2018-09-10T00:00:00' },
+        { id: '2', groupId: 'a', start: '2018-09-06T00:00:00', end: '2018-09-09T00:00:00' },
+      ]
+    })
+
+    let event1 = currentCalendar.getEventById('1')
+    event1.setStart('2018-09-01') // move start back by 4 days
+    expect(event1.start).toEqualDate('2018-09-01')
+    expect(event1.end).toEqualDate('2018-09-10')
+
+    let event2 = currentCalendar.getEventById('2')
+    expect(event2.start).toEqualDate('2018-09-02')
+    expect(event2.end).toEqualDate('2018-09-09')
+  })
+
+})

+ 56 - 0
tests/automated/event-drag/all-day-change.js

@@ -0,0 +1,56 @@
+import { drag } from './EventDragUtils'
+import { computeSpanRects } from '../event-render/TimeGridEventRenderUtils'
+import { getDayEl } from '../view-render/DayGridRenderUtils'
+
+describe('isAllDay change', function() {
+  pushOptions({
+    timeZone: 'UTC',
+    defaultView: 'agendaWeek',
+    now: '2018-09-03',
+    scrollTime: 0,
+    editable: true,
+    dragScroll: false
+  })
+
+  describe('when dragged from all-day to timed', function() {
+    pushOptions({
+      events: [
+        { id: '1', start: '2018-09-03', end: '2018-09-05' }
+      ]
+    })
+
+    function doDrag() {
+      let startRect = getDayEl('2018-09-03')[0].getBoundingClientRect()
+      let endDate = FullCalendar.parseMarker('2018-09-03T02:00:00').marker
+      var endRect = computeSpanRects(
+        endDate,
+        FullCalendar.addMs(endDate, 1000 * 60 * 30) // hardcoded 30 minute slot :(
+      )[0]
+      return drag(startRect, endRect, false)
+    }
+
+    it('discards duration when isAllDayMaintainDuration:false', function(done) {
+      initCalendar({
+        isAllDayMaintainDuration: false
+      })
+      doDrag().then(function() {
+        let event = currentCalendar.getEventById('1')
+        expect(event.start).toEqualDate('2018-09-03T02:00:00Z')
+        expect(event.end).toBe(null)
+      }).then(done)
+    })
+
+    it('keeps duration when isAllDayMaintainDuration:true', function(done) {
+      initCalendar({
+        isAllDayMaintainDuration: true
+      })
+      doDrag().then(function() {
+        let event = currentCalendar.getEventById('1')
+        expect(event.start).toEqualDate('2018-09-03T02:00:00Z')
+        expect(event.end).toEqualDate('2018-09-05T02:00:00Z')
+      }).then(done)
+    })
+
+  })
+
+})