import { clampToDayViewBoundary } from './clampToDayViewBoundary'; describe('clampToDayViewBoundary', () => { describe('no boundaries', () => { it('returns date unchanged when no min or max', () => { const date = new Date(2000, 0, 15); expect(clampToDayViewBoundary(date, null, null)).toBe(date); }); }); describe('min boundary', () => { it('returns date unchanged when within range', () => { const date = new Date(2000, 0, 20); const min = new Date(2000, 0, 15); expect(clampToDayViewBoundary(date, min, null)).toBe(date); }); it('allows navigation past min within the same month', () => { const date = new Date(2000, 0, 10); const min = new Date(2000, 0, 15); expect(clampToDayViewBoundary(date, min, null)).toBe(date); }); it('clamps to first of min month when navigating to a previous month', () => { const date = new Date(1999, 11, 31); const min = new Date(2000, 0, 15); expect(clampToDayViewBoundary(date, min, null)).toEqual(new Date(2000, 0, 1)); }); it('clamps to first of min month across year boundary', () => { const date = new Date(1999, 11, 25); const min = new Date(2000, 0, 5); expect(clampToDayViewBoundary(date, min, null)).toEqual(new Date(2000, 0, 1)); }); it('clamps to first of min month when min is on the 1st', () => { const date = new Date(1999, 11, 31); const min = new Date(2000, 0, 1); expect(clampToDayViewBoundary(date, min, null)).toEqual(new Date(2000, 0, 1)); }); }); describe('max boundary', () => { it('returns date unchanged when within range', () => { const date = new Date(2000, 0, 10); const max = new Date(2000, 0, 15); expect(clampToDayViewBoundary(date, null, max)).toBe(date); }); it('allows navigation past max within the same month', () => { const date = new Date(2000, 0, 20); const max = new Date(2000, 0, 15); expect(clampToDayViewBoundary(date, null, max)).toBe(date); }); it('clamps to last of max month when navigating to a next month', () => { const date = new Date(2000, 1, 1); const max = new Date(2000, 0, 20); expect(clampToDayViewBoundary(date, null, max)).toEqual(new Date(2000, 0, 31)); }); it('clamps to last of max month across year boundary', () => { const date = new Date(2001, 0, 1); const max = new Date(2000, 11, 25); expect(clampToDayViewBoundary(date, null, max)).toEqual(new Date(2000, 11, 31)); }); it('clamps to last of max month when max is on the last day', () => { const date = new Date(2000, 1, 1); const max = new Date(2000, 0, 31); expect(clampToDayViewBoundary(date, null, max)).toEqual(new Date(2000, 0, 31)); }); }); describe('both boundaries', () => { it('allows past min within same month when both min and max set', () => { const date = new Date(2000, 0, 10); const min = new Date(2000, 0, 15); const max = new Date(2000, 0, 25); expect(clampToDayViewBoundary(date, min, max)).toBe(date); }); it('allows past max within same month when both min and max set', () => { const date = new Date(2000, 0, 28); const min = new Date(2000, 0, 15); const max = new Date(2000, 0, 25); expect(clampToDayViewBoundary(date, min, max)).toBe(date); }); }); });