|
| 1 | +import { describe, expect, it } from 'vitest'; |
| 2 | + |
| 3 | +import { |
| 4 | + getEffectiveSpecialTermAcadYear, |
| 5 | + isPreviousAySpecialTermActive, |
| 6 | + isUsingPreviousAySpecialTermData, |
| 7 | + shouldUsePreviousAyForSemester, |
| 8 | +} from './index.js'; |
| 9 | + |
| 10 | +// Refer to packages/nusmods-academic-calendar/academic-calendar.json each AY's configs. |
| 11 | + |
| 12 | +describe(isPreviousAySpecialTermActive, () => { |
| 13 | + it('returns true during previous AY Special Term I after AY migration', () => { |
| 14 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 4, 15))).toBe(true); |
| 15 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 4, 12))).toBe(true); |
| 16 | + }); |
| 17 | + |
| 18 | + it('returns true during previous AY Special Term II after AY migration', () => { |
| 19 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 6, 1))).toBe(true); |
| 20 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 7, 10))).toBe(true); |
| 21 | + }); |
| 22 | + |
| 23 | + it('returns false before previous AY Special Term I starts', () => { |
| 24 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 4, 1))).toBe(false); |
| 25 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 4, 11))).toBe(false); |
| 26 | + }); |
| 27 | + |
| 28 | + it('returns false after new AY semester 1 starts', () => { |
| 29 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2025, 7, 11))).toBe(false); |
| 30 | + expect(isPreviousAySpecialTermActive('2025/2026', new Date(2026, 0, 1))).toBe(false); |
| 31 | + }); |
| 32 | +}); |
| 33 | + |
| 34 | +describe(getEffectiveSpecialTermAcadYear, () => { |
| 35 | + it('auto-detects previous AY during overlap', () => { |
| 36 | + expect(getEffectiveSpecialTermAcadYear('2025/2026', null, new Date(2025, 4, 15))).toBe( |
| 37 | + '2024/2025', |
| 38 | + ); |
| 39 | + expect(getEffectiveSpecialTermAcadYear('2025/2026', null, new Date(2025, 6, 1))).toBe( |
| 40 | + '2024/2025', |
| 41 | + ); |
| 42 | + expect(getEffectiveSpecialTermAcadYear('2025/2026', null, new Date(2025, 7, 10))).toBe( |
| 43 | + '2024/2025', |
| 44 | + ); |
| 45 | + }); |
| 46 | + |
| 47 | + it('uses current AY outside overlap', () => { |
| 48 | + expect(getEffectiveSpecialTermAcadYear('2025/2026', null, new Date(2025, 7, 11))).toBe( |
| 49 | + '2025/2026', |
| 50 | + ); |
| 51 | + expect(getEffectiveSpecialTermAcadYear('2025/2026', null, new Date(2025, 8, 1))).toBe( |
| 52 | + '2025/2026', |
| 53 | + ); |
| 54 | + }); |
| 55 | + |
| 56 | + it('uses manual override when configured', () => { |
| 57 | + expect(getEffectiveSpecialTermAcadYear('2025/2026', '2023/2024', new Date(2025, 6, 1))).toBe( |
| 58 | + '2023/2024', |
| 59 | + ); |
| 60 | + }); |
| 61 | +}); |
| 62 | + |
| 63 | +describe(isUsingPreviousAySpecialTermData, () => { |
| 64 | + it('returns true only during overlap', () => { |
| 65 | + expect(isUsingPreviousAySpecialTermData('2025/2026', null, new Date(2025, 4, 15))).toBe(true); |
| 66 | + expect(isUsingPreviousAySpecialTermData('2025/2026', null, new Date(2025, 6, 1))).toBe(true); |
| 67 | + expect(isUsingPreviousAySpecialTermData('2025/2026', null, new Date(2025, 8, 1))).toBe(false); |
| 68 | + }); |
| 69 | +}); |
| 70 | + |
| 71 | +describe(shouldUsePreviousAyForSemester, () => { |
| 72 | + it('returns true for special term semesters during overlap', () => { |
| 73 | + expect(shouldUsePreviousAyForSemester(3, '2025/2026', null, new Date(2025, 4, 15))).toBe(true); |
| 74 | + expect(shouldUsePreviousAyForSemester(4, '2025/2026', null, new Date(2025, 6, 1))).toBe(true); |
| 75 | + }); |
| 76 | + |
| 77 | + it('returns false for normal semesters during overlap', () => { |
| 78 | + expect(shouldUsePreviousAyForSemester(1, '2025/2026', null, new Date(2025, 6, 1))).toBe(false); |
| 79 | + expect(shouldUsePreviousAyForSemester(2, '2025/2026', null, new Date(2025, 6, 1))).toBe(false); |
| 80 | + }); |
| 81 | +}); |
0 commit comments