|
| 1 | +import { isScheduleInPast, isScheduleToday } from '@/lib/program/time-utils' |
| 2 | + |
| 3 | +describe('program/time-utils.ts', () => { |
| 4 | + describe('isScheduleInPast', () => { |
| 5 | + it('should return true for dates in the past', () => { |
| 6 | + const currentTime = new Date('2025-10-28T12:00:00') |
| 7 | + const scheduleDate = '2025-10-27' |
| 8 | + expect(isScheduleInPast(scheduleDate, currentTime)).toBe(true) |
| 9 | + }) |
| 10 | + |
| 11 | + it('should return false for today', () => { |
| 12 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 13 | + const scheduleDate = '2025-10-27' |
| 14 | + expect(isScheduleInPast(scheduleDate, currentTime)).toBe(false) |
| 15 | + }) |
| 16 | + |
| 17 | + it('should return false for dates in the future', () => { |
| 18 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 19 | + const scheduleDate = '2025-10-28' |
| 20 | + expect(isScheduleInPast(scheduleDate, currentTime)).toBe(false) |
| 21 | + }) |
| 22 | + |
| 23 | + it('should handle dates far in the past', () => { |
| 24 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 25 | + const scheduleDate = '2024-01-01' |
| 26 | + expect(isScheduleInPast(scheduleDate, currentTime)).toBe(true) |
| 27 | + }) |
| 28 | + |
| 29 | + it('should handle dates far in the future', () => { |
| 30 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 31 | + const scheduleDate = '2026-12-31' |
| 32 | + expect(isScheduleInPast(scheduleDate, currentTime)).toBe(false) |
| 33 | + }) |
| 34 | + |
| 35 | + it('should ignore time of day (only compare dates)', () => { |
| 36 | + // Morning |
| 37 | + const morningTime = new Date('2025-10-28T08:00:00') |
| 38 | + expect(isScheduleInPast('2025-10-27', morningTime)).toBe(true) |
| 39 | + |
| 40 | + // Evening |
| 41 | + const eveningTime = new Date('2025-10-28T23:59:59') |
| 42 | + expect(isScheduleInPast('2025-10-27', eveningTime)).toBe(true) |
| 43 | + |
| 44 | + // Today should still be false regardless of time |
| 45 | + expect(isScheduleInPast('2025-10-28', morningTime)).toBe(false) |
| 46 | + expect(isScheduleInPast('2025-10-28', eveningTime)).toBe(false) |
| 47 | + }) |
| 48 | + }) |
| 49 | + |
| 50 | + describe('isScheduleToday', () => { |
| 51 | + it('should return true when schedule date matches current date', () => { |
| 52 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 53 | + const scheduleDate = '2025-10-27' |
| 54 | + expect(isScheduleToday(scheduleDate, currentTime)).toBe(true) |
| 55 | + }) |
| 56 | + |
| 57 | + it('should return false when schedule date is in the past', () => { |
| 58 | + const currentTime = new Date('2025-10-28T12:00:00') |
| 59 | + const scheduleDate = '2025-10-27' |
| 60 | + expect(isScheduleToday(scheduleDate, currentTime)).toBe(false) |
| 61 | + }) |
| 62 | + |
| 63 | + it('should return false when schedule date is in the future', () => { |
| 64 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 65 | + const scheduleDate = '2025-10-28' |
| 66 | + expect(isScheduleToday(scheduleDate, currentTime)).toBe(false) |
| 67 | + }) |
| 68 | + }) |
| 69 | + |
| 70 | + describe('integration: isScheduleInPast and isScheduleToday', () => { |
| 71 | + it('should have mutually exclusive results for past and today', () => { |
| 72 | + const currentTime = new Date('2025-10-27T12:00:00') |
| 73 | + const yesterdayDate = '2025-10-26' |
| 74 | + const todayDate = '2025-10-27' |
| 75 | + const tomorrowDate = '2025-10-28' |
| 76 | + |
| 77 | + // Yesterday |
| 78 | + expect(isScheduleInPast(yesterdayDate, currentTime)).toBe(true) |
| 79 | + expect(isScheduleToday(yesterdayDate, currentTime)).toBe(false) |
| 80 | + |
| 81 | + // Today |
| 82 | + expect(isScheduleInPast(todayDate, currentTime)).toBe(false) |
| 83 | + expect(isScheduleToday(todayDate, currentTime)).toBe(true) |
| 84 | + |
| 85 | + // Tomorrow |
| 86 | + expect(isScheduleInPast(tomorrowDate, currentTime)).toBe(false) |
| 87 | + expect(isScheduleToday(tomorrowDate, currentTime)).toBe(false) |
| 88 | + }) |
| 89 | + }) |
| 90 | +}) |
0 commit comments