diff --git a/__test__/features/Events/eventUtils.test.ts b/__test__/features/Events/eventUtils.test.ts index 2807740..4cb01b1 100644 --- a/__test__/features/Events/eventUtils.test.ts +++ b/__test__/features/Events/eventUtils.test.ts @@ -1,3 +1,4 @@ +import { CalendarEvent } from "../../../src/features/Events/EventsTypes"; import { calendarEventToJCal, parseCalendarEvent, @@ -69,6 +70,23 @@ describe("parseCalendarEvent", () => { ]); }); + it("marks allday true for DATE format", () => { + const rawData = [ + ["UID", {}, "text", "event-2"], + ["DTSTART", {}, "date", "2025-07-20"], + ["DTEND", {}, "date", "2025-07-21"], + ] as any; + + const result = parseCalendarEvent( + rawData, + baseColor, + calendarId, + "/calendars/test.ics" + ); + + expect(result.allday).toBe(true); + }); + it("appends recurrence-id to UID if present", () => { const rawData: any = [ ["UID", {}, "text", "event-2"], @@ -110,6 +128,32 @@ describe("parseCalendarEvent", () => { expect(result2.error).toMatch(/missing crucial event param/); }); + it("parses alarm block correctly", () => { + const rawData = [ + ["UID", {}, "text", "event-5"], + ["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"], + ] as any; + + const valarm: any = [ + "VALARM", + [ + ["ACTION", {}, "text", "DISPLAY"], + ["TRIGGER", {}, "duration", "-PT15M"], + ], + ]; + + const result = parseCalendarEvent( + rawData, + baseColor, + calendarId, + "/calendars/test.ics", + valarm + ); + + expect(result.alarm?.action).toBe("DISPLAY"); + expect(result.alarm?.trigger).toBe("-PT15M"); + }); + it("handles optional organizer and attendee fields gracefully", () => { const rawData = [ ["UID", {}, "text", "event-4"], @@ -184,7 +228,7 @@ describe("calendarEventToJCal", () => { ], }; - const result = calendarEventToJCal(mockEvent); + const result = calendarEventToJCal(mockEvent as CalendarEvent); expect(result[0]).toBe("vcalendar"); const [vevent, vtimezone] = result[2]; @@ -266,6 +310,53 @@ describe("calendarEventToJCal", () => { ]) ); }); + + it("converts with alarm included", () => { + const mockEvent: any = { + uid: "event-10", + title: "Alarm Event", + start: new Date("2025-07-20T09:00:00"), + end: new Date("2025-07-20T10:00:00"), + timezone: "Europe/Paris", + allday: false, + alarm: { trigger: "-PT10M", action: "DISPLAY" }, + attendee: [], + }; + + const result = calendarEventToJCal(mockEvent, "owner@example.com"); + const vevent = result[2][0]; + + expect(vevent[2][0][0]).toBe("valarm"); + expect(vevent[2][0][1]).toEqual( + expect.arrayContaining([ + ["trigger", {}, "duration", "-PT10M"], + ["action", {}, "text", "DISPLAY"], + ]) + ); + }); + + it("converts all-day events adjusting dtend", () => { + const mockEvent: any = { + uid: "event-11", + title: "All Day", + start: new Date("2025-07-21"), + end: new Date("2025-07-21"), + timezone: "Europe/Paris", + allday: true, + attendee: [], + }; + + const result = calendarEventToJCal(mockEvent); + const veventProps = result[2][0][1]; + + expect(veventProps).toEqual( + expect.arrayContaining([ + ["dtstart", { tzid: "Europe/Paris" }, "date", "2025-07-21"], + ["dtend", { tzid: "Europe/Paris" }, "date", "2025-07-22"], + ]) + ); + }); + it("should convert a CalendarEvent to JCal format, with all day activated", () => { const mockEvent = { uid: "event-123", @@ -297,7 +388,7 @@ describe("calendarEventToJCal", () => { ], }; - const result = calendarEventToJCal(mockEvent); + const result = calendarEventToJCal(mockEvent as CalendarEvent); expect(result[0]).toBe("vcalendar"); const [vevent, vtimezone] = result[2]; diff --git a/src/features/Events/EventDisplay.tsx b/src/features/Events/EventDisplay.tsx index e9f9472..9b0027d 100644 --- a/src/features/Events/EventDisplay.tsx +++ b/src/features/Events/EventDisplay.tsx @@ -91,7 +91,7 @@ export default function EventDisplayModal({ const [repetition, setRepetition] = useState( event.repetition ?? ({} as RepetitionObject) ); - const [alarm, setAlarm] = useState(event.alarm.trigger); + const [alarm, setAlarm] = useState(event?.alarm?.trigger ?? ""); const [busy, setBusy] = useState(""); const [eventClass, setEventClass] = useState(event?.class ?? "PUBLIC"); const [timezone, setTimezone] = useState(event?.timezone ?? "UTC"); diff --git a/src/features/Events/eventUtils.ts b/src/features/Events/eventUtils.ts index d48dd89..7326688 100644 --- a/src/features/Events/eventUtils.ts +++ b/src/features/Events/eventUtils.ts @@ -105,7 +105,6 @@ export function parseCalendarEvent( } if (valarm) { - console.log(valarm); event.alarm = {} as AlarmObject; for (const [key, params, type, value] of valarm[1]) { switch (key.toLowerCase()) {