<commit_before>import { DayGridViewWrapper } from '../lib/wrappers/DayGridViewWrapper'
import { anyElsIntersect } from '../lib/dom-geom'
import { filterVisibleEls } from '../lib/dom-misc'

describe('dayGrid advanced event rendering', () => {
  pushOptions({
    initialDate: '2020-05-01',
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5408
  it('renders without intersecting', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-05-01',
      events: [
        { start: '2020-05-02', end: '2020-05-04', title: 'event a' },
        { start: '2020-05-02', end: '2020-05-04', title: 'event b' },
        { start: '2020-05-03', end: '2020-05-05', title: 'event c' },
        { start: '2020-05-04', title: 'event d' },
        { start: '2020-05-04', title: 'event e' },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()

    expect(anyElsIntersect(eventEls)).toBe(false)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5771
  it('renders more-links correctly when first obscured event is longer than event before it', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-08-01',
      dayMaxEventRows: 3,
      events: [
        { title: 'big1', start: '2020-07-23', end: '2020-07-28' },
        { title: 'small1', start: '2020-07-24', end: '2020-07-27' },
        { title: 'small2', start: '2020-07-24', end: '2020-07-27' },
        { title: 'big2', start: '2020-07-25', end: '2020-07-28' },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(2)
    expect(moreLinkEls.length).toBe(2)
    expect(anyElsIntersect(visibleEventEls.concat(moreLinkEls))).toBe(false)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5790
  it('positions more-links correctly in columns that have empty space', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-09-01',
      dayMaxEventRows: 4,
      events: [
        { start: '2020-08-30', end: '2020-09-04' },
        { start: '2020-08-31', end: '2020-09-03' },
        { start: '2020-09-01', end: '2020-09-04' },
        { start: '2020-09-02', end: '2020-09-04' },
        { start: '2020-09-02', end: '2020-09-04' },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(3)
    expect(moreLinkEls.length).toBe(2)
    expect(anyElsIntersect(visibleEventEls.concat(moreLinkEls))).toBe(false)

    expect(Math.abs(
      moreLinkEls[0].getBoundingClientRect().top -
      moreLinkEls[1].getBoundingClientRect().top,
    )).toBeLessThan(1)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5883
  it('it renders without gaps when ordered by title', () => {
    let calendar = initCalendar({
      initialDate: '2020-10-01',
      eventOrder: 'title',
      dayMaxEventRows: 3,
      events: [
        {
          title: 'b1',
          start: '2020-10-20',
          end: '2020-10-22',
        },
        {
          title: 'b2',
          start: '2020-10-21',
          end: '2020-10-22',
        },
        {
          title: 'b3',
          start: '2020-10-20',
          end: '2020-10-23',
        },
        {
          title: 'b4',
          start: '2020-10-20',
          end: '2020-10-23',
        },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(2)
    expect(moreLinkEls.length).toBe(3)
    expect(anyElsIntersect(visibleEventEls.concat(moreLinkEls))).toBe(false)
  })

  it('won\'t intersect when doing custom rendering', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-06-01',
      events: [
        { start: '2020-06-04', end: '2020-06-08', title: 'event a' },
        { start: '2020-06-05', end: '2020-06-09', title: 'event b' },
        { start: '2020-06-08T12:00:00', title: 'event c' },
      ],
      eventContent(arg) { // creates varying-height events, which revealed the bug
        return {
          html: `
            <b>${arg.timeText}</b>
            <i>${arg.event.title}</i>
          `,
        }
      },
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()

    expect(anyElsIntersect(eventEls)).toBe(false)
  })

  it('renders single-day timed event as list-item', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-05-01',<commit_msg>new tests for better daygrid event placement<commit_after>import { DayGridViewWrapper } from '../lib/wrappers/DayGridViewWrapper'
import { anyElsIntersect } from '../lib/dom-geom'
import { filterVisibleEls } from '../lib/dom-misc'

describe('dayGrid advanced event rendering', () => {
  pushOptions({
    initialDate: '2020-05-01',
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5408
  it('renders without intersecting', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-05-01',
      events: [
        { start: '2020-05-02', end: '2020-05-04', title: 'event a' },
        { start: '2020-05-02', end: '2020-05-04', title: 'event b' },
        { start: '2020-05-03', end: '2020-05-05', title: 'event c' },
        { start: '2020-05-04', title: 'event d' },
        { start: '2020-05-04', title: 'event e' },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()

    expect(anyElsIntersect(eventEls)).toBe(false)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5771
  it('renders more-links correctly when first obscured event is longer than event before it', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-08-01',
      dayMaxEventRows: 3,
      events: [
        { title: 'big1', start: '2020-07-23', end: '2020-07-28' },
        { title: 'small1', start: '2020-07-24', end: '2020-07-27' },
        { title: 'small2', start: '2020-07-24', end: '2020-07-27' },
        { title: 'big2', start: '2020-07-25', end: '2020-07-28' },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(3)
    expect(moreLinkEls.length).toBe(1)
    expect(anyElsIntersect(visibleEventEls.concat(moreLinkEls))).toBe(false)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5790
  it('positions more-links correctly in columns that have empty space', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-09-01',
      dayMaxEventRows: 4,
      events: [
        { start: '2020-08-30', end: '2020-09-04' },
        { start: '2020-08-31', end: '2020-09-03' },
        { start: '2020-09-01', end: '2020-09-04' },
        { start: '2020-09-02', end: '2020-09-04' },
        { start: '2020-09-02', end: '2020-09-04' },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(3)
    expect(moreLinkEls.length).toBe(2)
    expect(anyElsIntersect(visibleEventEls.concat(moreLinkEls))).toBe(false)

    expect(Math.abs(
      moreLinkEls[0].getBoundingClientRect().top -
      moreLinkEls[1].getBoundingClientRect().top,
    )).toBeLessThan(1)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/5883
  it('it renders without gaps when ordered by title', () => {
    let calendar = initCalendar({
      initialDate: '2020-10-01',
      eventOrder: 'title',
      dayMaxEventRows: 3,
      events: [
        {
          title: 'b1',
          start: '2020-10-20',
          end: '2020-10-22',
        },
        {
          title: 'b2',
          start: '2020-10-21',
          end: '2020-10-22',
        },
        {
          title: 'b3',
          start: '2020-10-20',
          end: '2020-10-23',
        },
        {
          title: 'b4',
          start: '2020-10-20',
          end: '2020-10-23',
        },
      ],
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(2)
    expect(moreLinkEls.length).toBe(3)
    expect(anyElsIntersect(visibleEventEls.concat(moreLinkEls))).toBe(false)
  })

  // https://github.com/fullcalendar/fullcalendar/issues/6187
  it('will partially slice long events that are beyond dayMaxEvents', () => {
    let calendar = initCalendar({
      initialDate: '2020-03-21',
      initialView: 'dayGridMonth',
      dayMaxEvents: 3,
      eventOrder: 'start,title',
      events: [
        {
          title: 'A',
          start: '2020-03-19',
        },
        {
          title: 'B',
          start: '2020-03-19',
        },
        {
          title: 'C',
          start: '2020-03-19',
        },
        {
          title: 'D',
          start: '2020-03-19',
          end: '2020-03-21',
        }
      ]
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()
    let visibleEventEls = filterVisibleEls(eventEls)
    let moreLinkEls = dayGridWrapper.getMoreEls()

    expect(visibleEventEls.length).toBe(4)
    expect(moreLinkEls.length).toBe(1)
  })

  it('won\'t intersect when doing custom rendering', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-06-01',
      events: [
        { start: '2020-06-04', end: '2020-06-08', title: 'event a' },
        { start: '2020-06-05', end: '2020-06-09', title: 'event b' },
        { start: '2020-06-08T12:00:00', title: 'event c' },
      ],
      eventContent(arg) { // creates varying-height events, which revealed the bug
        return {
          html: `
            <b>${arg.timeText}</b>
            <i>${arg.event.title}</i>
          `,
        }
      },
    })

    let dayGridWrapper = new DayGridViewWrapper(calendar).dayGrid
    let eventEls = dayGridWrapper.getEventEls()

    expect(anyElsIntersect(eventEls)).toBe(false)
  })

  it('renders single-day timed event as list-item', () => {
    let calendar = initCalendar({
      initialView: 'dayGridMonth',
      initialDate: '2020-05-01',
{'fraction_non_alphanumeric': 0.1565804674309073, 'fraction_numerical': 0.07775704256642674, 'mean_word_length': 2.563647878404053, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 26, 'https://': 9, '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': '4818990', 'n_tokens_mistral': 4310, 'n_tokens_neox': 3712, 'n_words': 698}