[#101] prettified code + added test
This commit is contained in:
committed by
Benoit TELLIER
parent
ac9db2b520
commit
b46be3af29
@@ -209,4 +209,50 @@ describe("CalendarApp integration", () => {
|
|||||||
);
|
);
|
||||||
expect(found).toBe(false);
|
expect(found).toBe(false);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("does render a title for events without any attendees or user as organizer", async () => {
|
||||||
|
const mockCalendarRef = { current: null };
|
||||||
|
renderWithProviders(<CalendarApp calendarRef={mockCalendarRef} />, {
|
||||||
|
user: {
|
||||||
|
userData: {
|
||||||
|
sub: "test",
|
||||||
|
email: "test@test.com",
|
||||||
|
sid: "mockSid",
|
||||||
|
openpaasId: "667037022b752d0026472254",
|
||||||
|
},
|
||||||
|
tokens: {
|
||||||
|
accessToken: "token",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
calendars: {
|
||||||
|
list: {
|
||||||
|
"667037022b752d0026472254/cal1": {
|
||||||
|
name: "Calendar 1",
|
||||||
|
id: "667037022b752d0026472254/cal1",
|
||||||
|
color: "#FF0000",
|
||||||
|
ownerEmails: ["alice@example.com"],
|
||||||
|
events: {
|
||||||
|
event1: {
|
||||||
|
id: "event1",
|
||||||
|
calId: "667037022b752d0026472254/cal1",
|
||||||
|
uid: "event1",
|
||||||
|
start: new Date().toISOString(),
|
||||||
|
end: new Date(Date.now() + 3600000).toISOString(),
|
||||||
|
partstat: "ACCEPTED",
|
||||||
|
organizer: {
|
||||||
|
cn: "Alice",
|
||||||
|
cal_address: "alice@example.com",
|
||||||
|
},
|
||||||
|
class: "PUBLIC",
|
||||||
|
title: "Public Event",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
pending: false,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(screen.getByText("Public Event")).toBeInTheDocument();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ describe("parseCalendarEvent", () => {
|
|||||||
const baseColor = "#00FF00";
|
const baseColor = "#00FF00";
|
||||||
const calendarId = "calendar-123";
|
const calendarId = "calendar-123";
|
||||||
|
|
||||||
it("parses a full event correctly", () => {
|
it("parses a full event with MAILTO in caps correctly", () => {
|
||||||
const rawData = [
|
const rawData = [
|
||||||
["UID", {}, "text", "event-1"],
|
["UID", {}, "text", "event-1"],
|
||||||
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
|
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
|
||||||
@@ -70,6 +70,67 @@ describe("parseCalendarEvent", () => {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("parses a full event correctly", () => {
|
||||||
|
const rawData = [
|
||||||
|
["UID", {}, "text", "event-1"],
|
||||||
|
["DTSTART", {}, "date-time", "2025-07-18T09:00:00Z"],
|
||||||
|
["DTEND", {}, "date-time", "2025-07-18T10:00:00Z"],
|
||||||
|
["SUMMARY", {}, "text", "Team Meeting"],
|
||||||
|
["DESCRIPTION", {}, "text", "Discuss roadmap"],
|
||||||
|
["LOCATION", {}, "text", "Zoom"],
|
||||||
|
["ORGANIZER", { cn: "Alice" }, "cal-address", "MAILTO:alice@example.com"],
|
||||||
|
[
|
||||||
|
"ATTENDEE",
|
||||||
|
{ cn: "Bob", partstat: "ACCEPTED" },
|
||||||
|
"cal-address",
|
||||||
|
"MAILTO:bob@example.com",
|
||||||
|
],
|
||||||
|
["X-OPENPAAS-VIDEOCONFERENCE", {}, "text", "https://meet.link"],
|
||||||
|
["STATUS", {}, "text", "CONFIRMED"],
|
||||||
|
["SEQUENCE", {}, "integer", "2"],
|
||||||
|
["TRANSP", {}, "text", "OPAQUE"],
|
||||||
|
["CLASS", {}, "text", "PUBLIC"],
|
||||||
|
["DTSTAMP", {}, "date-time", "2025-07-18T08:00:00Z"],
|
||||||
|
] as unknown as [string, Record<string, string>, string, any];
|
||||||
|
|
||||||
|
const result = parseCalendarEvent(
|
||||||
|
rawData,
|
||||||
|
baseColor,
|
||||||
|
calendarId,
|
||||||
|
"/calendars/test.ics"
|
||||||
|
);
|
||||||
|
|
||||||
|
expect(result.uid).toBe("event-1");
|
||||||
|
expect(result.title).toBe("Team Meeting");
|
||||||
|
expect(result.description).toBe("Discuss roadmap");
|
||||||
|
expect(result.location).toBe("Zoom");
|
||||||
|
expect(result.start).toBe("2025-07-18T09:00:00Z");
|
||||||
|
expect(result.end).toBe("2025-07-18T10:00:00Z");
|
||||||
|
expect(result.stamp).toBe("2025-07-18T08:00:00Z");
|
||||||
|
expect(result.sequence).toBe(2);
|
||||||
|
expect(result.color).toBe(baseColor);
|
||||||
|
expect(result.status).toBe("CONFIRMED");
|
||||||
|
expect(result.transp).toBe("OPAQUE");
|
||||||
|
expect(result.class).toBe("PUBLIC");
|
||||||
|
expect(result.x_openpass_videoconference).toBe("https://meet.link");
|
||||||
|
|
||||||
|
expect(result.organizer).toEqual({
|
||||||
|
cn: "Alice",
|
||||||
|
cal_address: "alice@example.com",
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result.attendee).toEqual([
|
||||||
|
{
|
||||||
|
cn: "Bob",
|
||||||
|
cal_address: "bob@example.com",
|
||||||
|
partstat: "ACCEPTED",
|
||||||
|
rsvp: "",
|
||||||
|
role: "",
|
||||||
|
cutype: "",
|
||||||
|
},
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
it("marks allday true for DATE format", () => {
|
it("marks allday true for DATE format", () => {
|
||||||
const rawData = [
|
const rawData = [
|
||||||
["UID", {}, "text", "event-2"],
|
["UID", {}, "text", "event-2"],
|
||||||
|
|||||||
@@ -135,34 +135,32 @@ export const createViewHandlers = (props: ViewHandlersProps) => {
|
|||||||
|
|
||||||
const handleEventContent = (arg: any) => {
|
const handleEventContent = (arg: any) => {
|
||||||
const event = arg.event;
|
const event = arg.event;
|
||||||
if (
|
const props = event._def.extendedProps;
|
||||||
(!event._def.extendedProps.temp &&
|
const { calId, temp, attendees = [], class: classification } = props;
|
||||||
!calendars[arg.event._def.extendedProps.calId]) ||
|
|
||||||
(event._def.extendedProps.temp &&
|
|
||||||
!tempcalendars[arg.event._def.extendedProps.calId])
|
|
||||||
)
|
|
||||||
return;
|
|
||||||
|
|
||||||
const attendees = event._def.extendedProps.attendee || [];
|
const calendarsSource = temp ? tempcalendars : calendars;
|
||||||
const isPrivate =
|
const calendar = calendarsSource[calId];
|
||||||
event._def.extendedProps.class === "PRIVATE" ||
|
if (!calendar) return null;
|
||||||
event._def.extendedProps.class === "CONFIDENTIAL";
|
|
||||||
|
const isPrivate = ["PRIVATE", "CONFIDENTIAL"].includes(classification);
|
||||||
|
const ownerEmails = new Set(
|
||||||
|
calendar.ownerEmails?.map((e) => e.toLowerCase())
|
||||||
|
);
|
||||||
|
const delegated = calendar.delegated;
|
||||||
let Icon = null;
|
let Icon = null;
|
||||||
let titleStyle: React.CSSProperties = {};
|
let titleStyle: React.CSSProperties = {};
|
||||||
const ownerEmails = new Set(
|
|
||||||
(event._def.extendedProps.temp ? tempcalendars : calendars)[
|
|
||||||
arg.event._def.extendedProps.calId
|
|
||||||
].ownerEmails?.map((email) => email.toLowerCase())
|
|
||||||
);
|
|
||||||
|
|
||||||
const delegated = (
|
|
||||||
event._def.extendedProps.temp ? tempcalendars : calendars
|
|
||||||
)[arg.event._def.extendedProps.calId].delegated;
|
|
||||||
const showSpecialDisplay = attendees.filter((att: userAttendee) =>
|
const showSpecialDisplay = attendees.filter((att: userAttendee) =>
|
||||||
ownerEmails.has(att.cal_address.toLowerCase())
|
ownerEmails.has(att.cal_address.toLowerCase())
|
||||||
);
|
);
|
||||||
if (!delegated && showSpecialDisplay.length === 0) return null;
|
// if no special display
|
||||||
|
if (attendees.length && !delegated && !showSpecialDisplay.length) {
|
||||||
|
return React.createElement(
|
||||||
|
"div",
|
||||||
|
{ style: { display: "flex", alignItems: "center" } },
|
||||||
|
React.createElement("span", event.title)
|
||||||
|
);
|
||||||
|
}
|
||||||
switch (showSpecialDisplay?.[0]?.partstat) {
|
switch (showSpecialDisplay?.[0]?.partstat) {
|
||||||
case "DECLINED":
|
case "DECLINED":
|
||||||
Icon = null;
|
Icon = null;
|
||||||
|
|||||||
Reference in New Issue
Block a user