import { hasDisabledDatesInMonth } from './hasDisabledDatesInMonth'; import type { DisabledRules } from '../../Calendar.types'; describe('hasDisabledDatesInMonth', () => { describe('weekdays', () => { it('returns true when weekday rules exist (every month has all weekdays)', () => { const rules: DisabledRules = { weekdays: ['sat', 'sun'], reason: 'Closed' }; expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(true); }); it('returns true for any month when weekday rules exist', () => { const rules: DisabledRules = { weekdays: ['mon'], reason: 'Closed' }; expect(hasDisabledDatesInMonth(0, 2024, rules)).toBe(true); expect(hasDisabledDatesInMonth(11, 2024, rules)).toBe(true); }); it('returns false when weekdays array is empty', () => { const rules: DisabledRules = { weekdays: [], reason: 'None' }; expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(false); }); }); describe('specific dates', () => { const rules: DisabledRules = { dates: [new Date(2024, 6, 11), new Date(2024, 6, 25), new Date(2025, 0, 1)], reason: 'Bank holidays', }; it('returns true when month contains a disabled date', () => { expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(true); }); it('returns false when month has no disabled dates', () => { expect(hasDisabledDatesInMonth(5, 2024, rules)).toBe(false); }); it('returns true for another year with disabled date', () => { expect(hasDisabledDatesInMonth(0, 2025, rules)).toBe(true); }); }); describe('ranges', () => { const rules: DisabledRules = { ranges: [{ start: new Date(2024, 2, 29), end: new Date(2024, 3, 3) }], reason: 'Maintenance', }; it('returns true when range starts in the month', () => { expect(hasDisabledDatesInMonth(2, 2024, rules)).toBe(true); }); it('returns true when range ends in the month', () => { expect(hasDisabledDatesInMonth(3, 2024, rules)).toBe(true); }); it('returns true when range spans the entire month', () => { const spanRules: DisabledRules = { ranges: [{ start: new Date(2024, 0, 1), end: new Date(2024, 11, 31) }], reason: 'Year-long', }; expect(hasDisabledDatesInMonth(6, 2024, spanRules)).toBe(true); }); it('returns false when range does not overlap the month', () => { expect(hasDisabledDatesInMonth(4, 2024, rules)).toBe(false); }); }); describe('min/max constraints', () => { it('returns false when all disabled dates in month are outside min/max', () => { const rules: DisabledRules = { dates: [new Date(2024, 6, 1), new Date(2024, 6, 2)], reason: 'Early', }; const min = new Date(2024, 6, 10); const max = new Date(2024, 6, 31); expect(hasDisabledDatesInMonth(6, 2024, rules, min, max)).toBe(false); }); it('returns true when weekdays exist regardless of min/max', () => { const rules: DisabledRules = { weekdays: ['sat'], reason: 'Closed' }; const min = new Date(2024, 6, 10); const max = new Date(2024, 6, 20); expect(hasDisabledDatesInMonth(6, 2024, rules, min, max)).toBe(true); }); }); describe('no rules', () => { it('returns false when disabledRules is undefined', () => { expect(hasDisabledDatesInMonth(6, 2024, undefined)).toBe(false); }); it('returns false when only reason is provided', () => { const rules: DisabledRules = { reason: 'Reason only' }; expect(hasDisabledDatesInMonth(6, 2024, rules)).toBe(false); }); }); });