Fix selection in calendar

This commit is contained in:
2026-06-14 22:42:28 +02:00
parent cb5517a387
commit 3ca1418d94
3 changed files with 41 additions and 1 deletions
+31
View File
@@ -10,6 +10,9 @@ vi.mock('@/context', () => ({
vi.mock('@/hooks', () => ({
usePlannedDays: vi.fn(),
useShowWeekNumbers: vi.fn(() => [false]),
getLastLeaveType: vi.fn(() => 'vacation'),
setLastLeaveType: vi.fn(),
}))
vi.mock('@/components/layout/Layout', () => ({
@@ -143,4 +146,32 @@ describe('Calendar', () => {
expect(screen.getByTestId('calendar')).toBeInTheDocument()
})
it('highlights date range live while dragging, before pointerup', () => {
;(useWorkspace as any).mockReturnValue(mockWorkspace)
;(usePlannedDays as any).mockReturnValue(mockPlannedDays)
render(<Calendar />)
const calendarDays = screen.getAllByTestId('calendar-day')
const currentMonthDays = calendarDays.filter((el) => !el.classList.contains('calendar-day--disabled'))
expect(currentMonthDays.length).toBeGreaterThanOrEqual(2)
const startDay = currentMonthDays[0] as HTMLElement
const endDay = currentMonthDays[3] as HTMLElement
// Fire pointerdown on first day
fireEvent.pointerDown(startDay)
// Fire pointerenter on later day WITHOUT firing pointerup
fireEvent.pointerEnter(endDay)
// The range should now have the --selected class before pointerup fires
const selectedDaysInRange = Array.from(calendarDays).filter((el) =>
el.classList.contains('calendar-day--selected')
)
expect(selectedDaysInRange.length).toBeGreaterThan(0)
})
})