import { describe, expect, it } from 'vitest' import { addDays, calendarDates, calendarRange, moveCalendar } from './calendar' describe('appointment calendar', () => { it('shows six complete Monday-first weeks across year boundaries', () => { const dates = calendarDates('2027-01-15', 'month') expect(dates).toHaveLength(42) expect(dates[0]).toBe('2026-12-28') expect(dates.at(-1)).toBe('2027-02-07') expect(calendarRange('2027-01-15', 'month').to).toBe('2027-02-08') }) it('moves by a week in week mode instead of following the prototype month-navigation bug', () => { expect(moveCalendar('2026-09-24', 'week', 1)).toBe('2026-10-01') expect(calendarDates('2026-09-27', 'week')).toEqual([ '2026-09-21', '2026-09-22', '2026-09-23', '2026-09-24', '2026-09-25', '2026-09-26', '2026-09-27', ]) }) it('clamps month-end selection and handles leap days', () => { expect(moveCalendar('2028-01-31', 'month', 1)).toBe('2028-02-29') expect(moveCalendar('2027-03-31', 'month', -1)).toBe('2027-02-28') expect(addDays('2028-02-28', 1)).toBe('2028-02-29') expect(() => addDays('2027-02-29', 1)).toThrow('无效的日历日期') }) })