{"size": 2089, "ext": "js", "max_stars_repo_path": "packages/__tests__/src/legacy/scroll-state.js", "max_stars_repo_name": "fariaseduv/fullcalendar", "max_stars_repo_stars_event_min_datetime": "2021-04-10T20:49:25.000Z", "max_stars_repo_stars_event_max_datetime": "2021-04-10T20:49:25.000Z", "max_issues_repo_path": "packages/__tests__/src/legacy/scroll-state.js", "max_issues_repo_name": "fariaseduv/fullcalendar", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "packages/__tests__/src/legacy/scroll-state.js", "max_forks_repo_name": "fariaseduv/fullcalendar", "max_forks_repo_forks_event_min_datetime": "2021-06-17T23:41:21.000Z", "max_forks_repo_forks_event_max_datetime": "2021-06-18T02:23:17.000Z"}
{"max_stars_count": 1, "max_issues_count": null, "max_forks_count": 2, "avg_line_length": 30.7205882353, "max_line_length": 91, "alphanum_fraction": 0.6443274294}
import { DayGridViewWrapper } from '../lib/wrappers/DayGridViewWrapper'
import { TimeGridViewWrapper } from '../lib/wrappers/TimeGridViewWrapper'
import { CalendarWrapper } from '../lib/wrappers/CalendarWrapper'

describe('scroll state', function() {
  let calendarEl

  beforeEach(function() {
    calendarEl = $('<div id="calendar">').width(800).appendTo('body')
  })
  afterEach(function() {
    calendarEl.remove()
    calendarEl = null
  })

  pushOptions({
    initialDate: '2015-02-20',
    contentHeight: 200,
    scrollTime: '00:00' // for timeGrid
  })

  describeOptions('initialView', {
    'when in month view': 'dayGridMonth',
    'when in week view': 'timeGridWeek'
  }, function(viewName) {
    let ViewWrapper = viewName.match(/^dayGrid/) ? DayGridViewWrapper : TimeGridViewWrapper

    it('should be maintained when resizing window', function(done) {
      let calendar = initCalendar({
        windowResize: function() {
          setTimeout(function() { // wait until all other tasks are finished
            expect(scrollEl.scrollTop).toBe(scroll0)
            done()
          }, 0)
        }
      }, calendarEl)
      let scrollEl = new ViewWrapper(calendar).getScrollerEl()
      let scroll0

      setTimeout(function() { // wait until after browser's scroll state is applied
        scrollEl.scrollTop = 9999 // all the way
        scroll0 = scrollEl.scrollTop
        $(window).simulate('resize')
      }, 0)
    })

    it('should be maintained when after rerendering events', function() {
      let calendar = initCalendar({
        events: [ {
          start: '2015-02-20'
        } ]
      }, calendarEl)

      let scrollEl = new ViewWrapper(calendar).getScrollerEl()
      let eventEl0 = new CalendarWrapper(calendar).getEventEls()
      expect(eventEl0.length).toBe(1)

      scrollEl.scrollTop = 9999 // all the way
      let scroll0 = scrollEl.scrollTop
      currentCalendar.render()

      let eventEl1 = new CalendarWrapper(calendar).getEventEls()
      expect(eventEl1.length).toBe(1)
      expect(scrollEl.scrollTop).toBe(scroll0)
    })
  })
})
