import {afterEach, beforeEach, describe, expect, it, vi} from 'vitest' import {ref} from 'vue' import {useCalendarView} from './useCalendarView' describe('useCalendarView', () => { beforeEach(() => { vi.useFakeTimers() vi.setSystemTime(new Date(2026, 4, 19)) // 19 mai 2026 }) afterEach(() => vi.useRealTimers()) it('initialises to the current month and year', () => { const {currentMonth, currentYear} = useCalendarView(ref('days')) expect(currentMonth.value).toBe(4) expect(currentYear.value).toBe(2026) }) it('goToNext advances the month in days view', () => { const {currentMonth, goToNext} = useCalendarView(ref('days')) goToNext() expect(currentMonth.value).toBe(5) }) it('rolls December to January and bumps the year', () => { const {currentMonth, currentYear, goToNext} = useCalendarView(ref('days')) currentMonth.value = 11 goToNext() expect(currentMonth.value).toBe(0) expect(currentYear.value).toBe(2027) }) it('rolls January to December backwards', () => { const {currentMonth, currentYear, goToPrev} = useCalendarView(ref('days')) currentMonth.value = 0 goToPrev() expect(currentMonth.value).toBe(11) expect(currentYear.value).toBe(2025) }) it('navigates the year in months view', () => { const {currentYear, goToNext, goToPrev} = useCalendarView(ref('months')) goToNext() expect(currentYear.value).toBe(2027) goToPrev() expect(currentYear.value).toBe(2026) }) it('selectMonth sets the current month', () => { const {currentMonth, selectMonth} = useCalendarView(ref('days')) selectMonth(0) expect(currentMonth.value).toBe(0) }) it('syncToIso sets month/year from a valid ISO', () => { const {currentMonth, currentYear, syncToIso} = useCalendarView(ref('days')) syncToIso('2025-12-25') expect(currentMonth.value).toBe(11) expect(currentYear.value).toBe(2025) }) it('syncToIso falls back to today for null/invalid', () => { const {currentMonth, currentYear, syncToIso} = useCalendarView(ref('days')) syncToIso('2025-12-25') syncToIso(null) expect(currentMonth.value).toBe(4) expect(currentYear.value).toBe(2026) }) })