|
1 | | -import { renderHook } from '@testing-library/react-hooks'; |
2 | | -import { useDateInterval } from './useDateInterval'; |
3 | | - |
4 | | -const today = new Date('2023-10-10'); |
5 | | - |
6 | | -const edition = { |
7 | | - tickets: { |
8 | | - startDay: '2023-10-01', |
9 | | - endDay: '2023-10-15', |
10 | | - }, |
11 | | - cfp: { |
12 | | - startDay: '2023-09-01', |
13 | | - endDay: '2023-09-30', |
14 | | - }, |
15 | | - sponsors: { |
16 | | - startDate: '2023-10-05', |
17 | | - endDate: '2023-10-20', |
18 | | - }, |
19 | | -}; |
20 | | - |
21 | | -describe('useDateInterval', () => { |
22 | | - it('should return correct disabled states for tickets, cfp, and sponsors', () => { |
| 1 | +import { renderHook } from "@testing-library/react-hooks"; |
| 2 | +import { useDateInterval } from "./useDateInterval"; |
| 3 | + |
| 4 | +describe("useDateInterval", () => { |
| 5 | + // Complete edition object with all required properties |
| 6 | + const createEdition = (overrides = {}) => ({ |
| 7 | + tickets: { |
| 8 | + startDay: "2023-10-01", |
| 9 | + endDay: "2023-10-15", |
| 10 | + }, |
| 11 | + cfp: { |
| 12 | + startDay: "2023-09-01", |
| 13 | + endDay: "2023-09-30", |
| 14 | + }, |
| 15 | + sponsors: { |
| 16 | + startDate: "2023-10-05", |
| 17 | + endDate: "2023-10-20", |
| 18 | + }, |
| 19 | + startDay: "2023-10-25", |
| 20 | + endDay: "2023-10-27", |
| 21 | + ...overrides, |
| 22 | + }); |
| 23 | + |
| 24 | + it("should return correct states during the conference", () => { |
| 25 | + const today = new Date("2023-10-26"); |
| 26 | + const edition = createEdition(); |
| 27 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 28 | + |
| 29 | + expect(result.current.isTicketsDisabled).toBe(true); |
| 30 | + expect(result.current.isCfpDisabled).toBe(true); |
| 31 | + expect(result.current.isSponsorDisabled).toBe(true); |
| 32 | + expect(result.current.isConferenceActive).toBe(true); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should return correct states during ticket sales period", () => { |
| 36 | + const today = new Date("2023-10-10"); |
| 37 | + const edition = createEdition(); |
23 | 38 | const { result } = renderHook(() => useDateInterval(today, edition)); |
24 | 39 |
|
25 | 40 | expect(result.current.isTicketsDisabled).toBe(false); |
26 | 41 | expect(result.current.isCfpDisabled).toBe(true); |
27 | 42 | expect(result.current.isSponsorDisabled).toBe(false); |
| 43 | + expect(result.current.isConferenceActive).toBe(false); |
| 44 | + }); |
| 45 | + |
| 46 | + it("should return correct states during CFP period", () => { |
| 47 | + const today = new Date("2023-09-15"); |
| 48 | + const edition = createEdition(); |
| 49 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 50 | + |
| 51 | + expect(result.current.isTicketsDisabled).toBe(true); |
| 52 | + expect(result.current.isCfpDisabled).toBe(false); |
| 53 | + expect(result.current.isSponsorDisabled).toBe(true); |
| 54 | + expect(result.current.isConferenceActive).toBe(false); |
| 55 | + }); |
| 56 | + |
| 57 | + it("should return correct states during sponsor registration period", () => { |
| 58 | + const today = new Date("2023-10-18"); |
| 59 | + const edition = createEdition(); |
| 60 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 61 | + |
| 62 | + expect(result.current.isTicketsDisabled).toBe(true); |
| 63 | + expect(result.current.isCfpDisabled).toBe(true); |
| 64 | + expect(result.current.isSponsorDisabled).toBe(false); |
| 65 | + expect(result.current.isConferenceActive).toBe(false); |
| 66 | + }); |
| 67 | + |
| 68 | + it("should return all disabled states before any period starts", () => { |
| 69 | + const today = new Date("2023-08-15"); |
| 70 | + const edition = createEdition(); |
| 71 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 72 | + |
| 73 | + expect(result.current.isTicketsDisabled).toBe(true); |
| 74 | + expect(result.current.isCfpDisabled).toBe(true); |
| 75 | + expect(result.current.isSponsorDisabled).toBe(true); |
| 76 | + expect(result.current.isConferenceActive).toBe(false); |
| 77 | + }); |
| 78 | + |
| 79 | + it("should return all disabled states after all periods end", () => { |
| 80 | + const today = new Date("2023-11-01"); |
| 81 | + const edition = createEdition(); |
| 82 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 83 | + |
| 84 | + expect(result.current.isTicketsDisabled).toBe(true); |
| 85 | + expect(result.current.isCfpDisabled).toBe(true); |
| 86 | + expect(result.current.isSponsorDisabled).toBe(true); |
| 87 | + expect(result.current.isConferenceActive).toBe(false); |
| 88 | + }); |
| 89 | + |
| 90 | + it("should handle edge case: exactly on start date", () => { |
| 91 | + const today = new Date("2023-10-01"); |
| 92 | + const edition = createEdition(); |
| 93 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 94 | + |
| 95 | + expect(result.current.isTicketsDisabled).toBe(false); // Should be enabled on start date |
| 96 | + expect(result.current.isCfpDisabled).toBe(true); |
| 97 | + expect(result.current.isSponsorDisabled).toBe(true); |
| 98 | + expect(result.current.isConferenceActive).toBe(false); |
| 99 | + }); |
| 100 | + |
| 101 | + it("should handle edge case: exactly on end date", () => { |
| 102 | + const today = new Date("2023-10-15"); |
| 103 | + const edition = createEdition(); |
| 104 | + const { result } = renderHook(() => useDateInterval(today, edition)); |
| 105 | + |
| 106 | + expect(result.current.isTicketsDisabled).toBe(false); // Should be enabled on end date |
| 107 | + expect(result.current.isCfpDisabled).toBe(true); |
| 108 | + expect(result.current.isSponsorDisabled).toBe(false); |
| 109 | + expect(result.current.isConferenceActive).toBe(false); |
28 | 110 | }); |
29 | 111 | }); |
0 commit comments