<commit_before>import XHRMock from 'xhr-mock'
import dayGridMonth from '@fullcalendar/daygrid'
import { EventSourceInput } from '@fullcalendar/core'
import iCalendarPlugin from '@fullcalendar/icalendar'
import { CalendarWrapper } from '../lib/wrappers/CalendarWrapper'

import alldayEvent from './data/alldayEvent'
import multidayEvent from './data/multidayEvent'
import multipleMultidayEvents from './data/multipleMultidayEvents'
import multipleEventsOneMunged from './data/multipleEventsOneMunged'
import oneHourMeeting from './data/oneHourMeeting'
import recurringWeeklyMeeting from './data/recurringWeeklyMeeting'
import mungedOneHourMeeting from './data/mungedOneHourMeeting'

describe('addICalEventSource with month view', () => {
  const ICAL_MIME_TYPE = 'text/calendar'

  pushOptions({
    plugins: [iCalendarPlugin, dayGridMonth],
    initialDate: '2019-04-10', // the start of the three-day event in the feed
    initialView: 'dayGridMonth',
  })

  beforeEach(() => { XHRMock.setup() })

  afterEach(() => { XHRMock.teardown() })

  it('correctly adds an all day event', (done) => {
    loadICalendarWith(alldayEvent, () => {
      setTimeout(() => {
        assertEventCount(1)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds a single multi-day event', (done) => {
    loadICalendarWith(multidayEvent, () => {
      setTimeout(() => {
        assertEventCount(1)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds multiple multi-day events', (done) => {
    loadICalendarWith(multipleMultidayEvents, () => {
      setTimeout(() => {
        assertEventCount(2)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds a one-hour long meeting', (done) => {
    loadICalendarWith(oneHourMeeting, () => {
      setTimeout(() => {
        assertEventCount(1)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).not.toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds a repeating weekly meeting', (done) => {
    loadICalendarWith(recurringWeeklyMeeting, () => {
      setTimeout(() => {
        assertEventCount(5)
        done()
      }, 100)
    })
  })

  it('ignores a munged event', (done) => {
	  loadICalendarWith(mungedOneHourMeeting, () => {
		  setTimeout(() => {
			  assertEventCount(0)
        done()
      }, 100)
    })
  })

  it('adds a valid event and ignores a munged event', (done) => {
	  loadICalendarWith(multipleEventsOneMunged, () => {
		  setTimeout(() => {
			  assertEventCount(1)
        done()
      }, 100)
    })
  })

  it('defaultAllDayEventDuration does not override ical default all day length of one day', (done) => {
    loadICalendarWith(alldayEvent,
      () => {
        setTimeout(() => {
          assertEventCount(1)
          // check that event has been given a two day length
          const event = currentCalendar.getEvents()[0]
          expect(event.end.getDate()).toEqual(event.start.getDate() + 1)
          done()
        }, 100)
      },
      (source) => {
        initCalendar({
          forceEventDuration: true,
          defaultAllDayEventDuration: { days: 2 },
        }).addEventSource(source)
      })
  })

  function loadICalendarWith(rawICal: string, assertions: () => void, calendarSetup?: (source: EventSourceInput) => void) {
    const feedUrl = '/mock.ics'

    XHRMock.get(feedUrl, (req, res) => {
      expect(req.url().query).toEqual({})

      return res.status(200)
        .header('content-type', ICAL_MIME_TYPE)
        .body(rawICal)<commit_msg>whitespace lint fixes<commit_after>import XHRMock from 'xhr-mock'
import dayGridMonth from '@fullcalendar/daygrid'
import { EventSourceInput } from '@fullcalendar/core'
import iCalendarPlugin from '@fullcalendar/icalendar'
import { CalendarWrapper } from '../lib/wrappers/CalendarWrapper'
import alldayEvent from './data/alldayEvent'
import multidayEvent from './data/multidayEvent'
import multipleMultidayEvents from './data/multipleMultidayEvents'
import multipleEventsOneMunged from './data/multipleEventsOneMunged'
import oneHourMeeting from './data/oneHourMeeting'
import recurringWeeklyMeeting from './data/recurringWeeklyMeeting'
import mungedOneHourMeeting from './data/mungedOneHourMeeting'

describe('addICalEventSource with month view', () => {
  const ICAL_MIME_TYPE = 'text/calendar'

  pushOptions({
    plugins: [iCalendarPlugin, dayGridMonth],
    initialDate: '2019-04-10', // the start of the three-day event in the feed
    initialView: 'dayGridMonth',
  })

  beforeEach(() => { XHRMock.setup() })
  afterEach(() => { XHRMock.teardown() })

  it('correctly adds an all day event', (done) => {
    loadICalendarWith(alldayEvent, () => {
      setTimeout(() => {
        assertEventCount(1)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds a single multi-day event', (done) => {
    loadICalendarWith(multidayEvent, () => {
      setTimeout(() => {
        assertEventCount(1)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds multiple multi-day events', (done) => {
    loadICalendarWith(multipleMultidayEvents, () => {
      setTimeout(() => {
        assertEventCount(2)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds a one-hour long meeting', (done) => {
    loadICalendarWith(oneHourMeeting, () => {
      setTimeout(() => {
        assertEventCount(1)
        currentCalendar.getEvents().forEach((event) => expect(event.allDay).not.toBeTruthy())
        done()
      }, 100)
    })
  })

  it('correctly adds a repeating weekly meeting', (done) => {
    loadICalendarWith(recurringWeeklyMeeting, () => {
      setTimeout(() => {
        assertEventCount(5)
        done()
      }, 100)
    })
  })

  it('ignores a munged event', (done) => {
    loadICalendarWith(mungedOneHourMeeting, () => {
      setTimeout(() => {
        assertEventCount(0)
        done()
      }, 100)
    })
  })

  it('adds a valid event and ignores a munged event', (done) => {
    loadICalendarWith(multipleEventsOneMunged, () => {
      setTimeout(() => {
        assertEventCount(1)
        done()
      }, 100)
    })
  })

  it('defaultAllDayEventDuration does not override ical default all day length of one day', (done) => {
    loadICalendarWith(
      alldayEvent,
      () => {
        setTimeout(() => {
          assertEventCount(1)
          // check that event has been given a two day length
          const event = currentCalendar.getEvents()[0]
          expect(event.end.getDate()).toEqual(event.start.getDate() + 1)
          done()
        }, 100)
      },
      (source) => {
        initCalendar({
          forceEventDuration: true,
          defaultAllDayEventDuration: { days: 2 },
        }).addEventSource(source)
      },
    )
  })

  function loadICalendarWith(rawICal: string, assertions: () => void, calendarSetup?: (source: EventSourceInput) => void) {
    const feedUrl = '/mock.ics'

    XHRMock.get(feedUrl, (req, res) => {
      expect(req.url().query).toEqual({})

      return res.status(200)
        .header('content-type', ICAL_MIME_TYPE)
        .body(rawICal)
{'fraction_non_alphanumeric': 0.1453756084725694, 'fraction_numerical': 0.012103670569661886, 'mean_word_length': 3.0286168521462637, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 73, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7651310', 'n_tokens_mistral': 2426, 'n_tokens_neox': 2324, 'n_words': 462}