33 lines
1.4 KiB
TypeScript
33 lines
1.4 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { addDays, calendarDates, calendarRange, moveCalendar } from './calendar'
|
|
|
|
describe('appointment calendar', () => {
|
|
it.each([
|
|
['2026-10-19', '2026-09-28', '2026-11-02', 35],
|
|
['2027-01-15', '2026-12-28', '2027-02-01', 35],
|
|
['2027-02-15', '2027-02-01', '2027-03-01', 28],
|
|
['2026-08-15', '2026-07-27', '2026-09-07', 42],
|
|
] as const)('shows only the complete weeks needed for %s', (anchor, from, to, count) => {
|
|
const dates = calendarDates(anchor, 'month')
|
|
expect(dates).toHaveLength(count)
|
|
expect(dates[0]).toBe(from)
|
|
expect(dates.at(-1)).toBe(addDays(to, -1))
|
|
expect(calendarRange(anchor, 'month')).toEqual({ from, to })
|
|
})
|
|
|
|
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('无效的日历日期')
|
|
})
|
|
})
|