/**
 * Verifies CalendarView forwards the `popup` prop to react-big-calendar so the
 * month grid's "+N more" overflow link opens a popover instead of being inert
 * (raise-simpli-3er). RBC's overflow rendering depends on real cell layout
 * heights, which jsdom does not compute, so we mock RBC's Calendar with a
 * passthrough that surfaces props into the DOM.
 */
import { render } from '@testing-library/react'

const calendarPropSpy = jest.fn()

jest.mock('react-big-calendar', () => {
  const actual = jest.requireActual('react-big-calendar')
  return {
    ...actual,
    Calendar: (props: Record<string, unknown>) => {
      calendarPropSpy(props)
      return <div data-testid="rbc-calendar-stub" data-popup={String(props.popup)} />
    },
  }
})

import { CalendarView } from '../calendar/calendar-view'

const FIXED_DATE = new Date('2026-04-15T12:00:00Z')

describe('CalendarView popup prop', () => {
  beforeEach(() => calendarPropSpy.mockClear())

  it('defaults popup to true so the "+N more" overflow link opens a popover', () => {
    render(<CalendarView events={[]} defaultDate={FIXED_DATE} defaultView="month" />)
    expect(calendarPropSpy).toHaveBeenCalledTimes(1)
    expect(calendarPropSpy.mock.calls[0][0].popup).toBe(true)
  })

  it('forwards popup={false} when callers opt out', () => {
    render(
      <CalendarView events={[]} defaultDate={FIXED_DATE} defaultView="month" popup={false} />,
    )
    expect(calendarPropSpy.mock.calls[0][0].popup).toBe(false)
  })
})
