[#78] added tests
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import { CalendarEvent } from "../../../src/features/Events/EventsTypes";
|
||||||
import {
|
import {
|
||||||
calendarEventToJCal,
|
calendarEventToJCal,
|
||||||
parseCalendarEvent,
|
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", () => {
|
it("appends recurrence-id to UID if present", () => {
|
||||||
const rawData: any = [
|
const rawData: any = [
|
||||||
["UID", {}, "text", "event-2"],
|
["UID", {}, "text", "event-2"],
|
||||||
@@ -110,6 +128,32 @@ describe("parseCalendarEvent", () => {
|
|||||||
expect(result2.error).toMatch(/missing crucial event param/);
|
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", () => {
|
it("handles optional organizer and attendee fields gracefully", () => {
|
||||||
const rawData = [
|
const rawData = [
|
||||||
["UID", {}, "text", "event-4"],
|
["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");
|
expect(result[0]).toBe("vcalendar");
|
||||||
const [vevent, vtimezone] = result[2];
|
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", () => {
|
it("should convert a CalendarEvent to JCal format, with all day activated", () => {
|
||||||
const mockEvent = {
|
const mockEvent = {
|
||||||
uid: "event-123",
|
uid: "event-123",
|
||||||
@@ -297,7 +388,7 @@ describe("calendarEventToJCal", () => {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
const result = calendarEventToJCal(mockEvent);
|
const result = calendarEventToJCal(mockEvent as CalendarEvent);
|
||||||
|
|
||||||
expect(result[0]).toBe("vcalendar");
|
expect(result[0]).toBe("vcalendar");
|
||||||
const [vevent, vtimezone] = result[2];
|
const [vevent, vtimezone] = result[2];
|
||||||
|
|||||||
@@ -91,7 +91,7 @@ export default function EventDisplayModal({
|
|||||||
const [repetition, setRepetition] = useState<RepetitionObject>(
|
const [repetition, setRepetition] = useState<RepetitionObject>(
|
||||||
event.repetition ?? ({} as RepetitionObject)
|
event.repetition ?? ({} as RepetitionObject)
|
||||||
);
|
);
|
||||||
const [alarm, setAlarm] = useState(event.alarm.trigger);
|
const [alarm, setAlarm] = useState(event?.alarm?.trigger ?? "");
|
||||||
const [busy, setBusy] = useState("");
|
const [busy, setBusy] = useState("");
|
||||||
const [eventClass, setEventClass] = useState(event?.class ?? "PUBLIC");
|
const [eventClass, setEventClass] = useState(event?.class ?? "PUBLIC");
|
||||||
const [timezone, setTimezone] = useState(event?.timezone ?? "UTC");
|
const [timezone, setTimezone] = useState(event?.timezone ?? "UTC");
|
||||||
|
|||||||
@@ -105,7 +105,6 @@ export function parseCalendarEvent(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (valarm) {
|
if (valarm) {
|
||||||
console.log(valarm);
|
|
||||||
event.alarm = {} as AlarmObject;
|
event.alarm = {} as AlarmObject;
|
||||||
for (const [key, params, type, value] of valarm[1]) {
|
for (const [key, params, type, value] of valarm[1]) {
|
||||||
switch (key.toLowerCase()) {
|
switch (key.toLowerCase()) {
|
||||||
|
|||||||
Reference in New Issue
Block a user