|
| 1 | +import { beforeEach, describe, expect, it } from "@jest/globals"; |
| 2 | + |
| 3 | +import { createICSEvent } from "../../../src/bases/calendar-core"; |
| 4 | +import type TaskNotesPlugin from "../../../src/main"; |
| 5 | +import type { ICSEvent } from "../../../src/types"; |
| 6 | + |
| 7 | +function createCalendarPlugin(): TaskNotesPlugin { |
| 8 | + return {} as TaskNotesPlugin; |
| 9 | +} |
| 10 | + |
| 11 | +beforeEach(() => { |
| 12 | + (globalThis as typeof globalThis & { |
| 13 | + activeDocument?: { |
| 14 | + body: { |
| 15 | + classList: { |
| 16 | + contains: (className: string) => boolean; |
| 17 | + }; |
| 18 | + }; |
| 19 | + }; |
| 20 | + }).activeDocument = { |
| 21 | + body: { |
| 22 | + classList: { |
| 23 | + contains: (_className: string) => false, |
| 24 | + }, |
| 25 | + }, |
| 26 | + }; |
| 27 | +}); |
| 28 | + |
| 29 | +function createGoogleCalendarEvent(overrides: Partial<ICSEvent> = {}): ICSEvent { |
| 30 | + return { |
| 31 | + id: "google-primary-zero-duration-event", |
| 32 | + subscriptionId: "google-primary", |
| 33 | + title: "Reserved pickup cutoff", |
| 34 | + start: "2026-04-22T23:12:00", |
| 35 | + end: "2026-04-22T23:12:00", |
| 36 | + allDay: false, |
| 37 | + color: "#16a765", |
| 38 | + ...overrides, |
| 39 | + }; |
| 40 | +} |
| 41 | + |
| 42 | +describe("Issue #1823: zero-duration Google Calendar list duplication", () => { |
| 43 | + it("adds a minimal duration to zero-duration timed Google Calendar events", () => { |
| 44 | + const icsEvent = createGoogleCalendarEvent(); |
| 45 | + |
| 46 | + const calendarEvent = createICSEvent(icsEvent, createCalendarPlugin()); |
| 47 | + |
| 48 | + expect(calendarEvent).not.toBeNull(); |
| 49 | + expect(calendarEvent?.start).toBe("2026-04-22T23:12:00"); |
| 50 | + expect(calendarEvent?.end).not.toBe("2026-04-22T23:12:00"); |
| 51 | + expect(calendarEvent?.allDay).toBe(false); |
| 52 | + expect(calendarEvent?.extendedProps.icsEvent?.end).toBe("2026-04-22T23:12:00"); |
| 53 | + expect(new Date(calendarEvent!.end!).getTime() - new Date(calendarEvent!.start).getTime()).toBe(1); |
| 54 | + }); |
| 55 | + |
| 56 | + it("preserves an explicit offset when normalizing zero-duration timed events", () => { |
| 57 | + const icsEvent = createGoogleCalendarEvent({ |
| 58 | + start: "2026-04-22T23:12:00+01:00", |
| 59 | + end: "2026-04-22T23:12:00+01:00", |
| 60 | + }); |
| 61 | + |
| 62 | + const calendarEvent = createICSEvent(icsEvent, createCalendarPlugin()); |
| 63 | + |
| 64 | + expect(calendarEvent?.start).toBe("2026-04-22T23:12:00+01:00"); |
| 65 | + expect(calendarEvent?.end).toBe("2026-04-22T23:12:00.001+01:00"); |
| 66 | + expect(new Date(calendarEvent!.end!).getTime() - new Date(calendarEvent!.start).getTime()).toBe(1); |
| 67 | + }); |
| 68 | + |
| 69 | + it("preserves UTC formatting when normalizing zero-duration timed events", () => { |
| 70 | + const icsEvent = createGoogleCalendarEvent({ |
| 71 | + start: "2026-04-22T22:12:00.000Z", |
| 72 | + end: "2026-04-22T22:12:00.000Z", |
| 73 | + }); |
| 74 | + |
| 75 | + const calendarEvent = createICSEvent(icsEvent, createCalendarPlugin()); |
| 76 | + |
| 77 | + expect(calendarEvent?.start).toBe("2026-04-22T22:12:00.000Z"); |
| 78 | + expect(calendarEvent?.end).toBe("2026-04-22T22:12:00.001Z"); |
| 79 | + expect(new Date(calendarEvent!.end!).getTime() - new Date(calendarEvent!.start).getTime()).toBe(1); |
| 80 | + }); |
| 81 | + |
| 82 | + it("leaves non-zero timed Google Calendar events unchanged", () => { |
| 83 | + const icsEvent = createGoogleCalendarEvent({ |
| 84 | + end: "2026-04-22T23:42:00", |
| 85 | + }); |
| 86 | + |
| 87 | + const calendarEvent = createICSEvent(icsEvent, createCalendarPlugin()); |
| 88 | + |
| 89 | + expect(calendarEvent?.start).toBe("2026-04-22T23:12:00"); |
| 90 | + expect(calendarEvent?.end).toBe("2026-04-22T23:42:00"); |
| 91 | + }); |
| 92 | + |
| 93 | + it("leaves all-day Google Calendar events unchanged", () => { |
| 94 | + const icsEvent = createGoogleCalendarEvent({ |
| 95 | + start: "2026-04-22", |
| 96 | + end: "2026-04-23", |
| 97 | + allDay: true, |
| 98 | + }); |
| 99 | + |
| 100 | + const calendarEvent = createICSEvent(icsEvent, createCalendarPlugin()); |
| 101 | + |
| 102 | + expect(calendarEvent?.start).toBe("2026-04-22"); |
| 103 | + expect(calendarEvent?.end).toBe("2026-04-23"); |
| 104 | + expect(calendarEvent?.allDay).toBe(true); |
| 105 | + }); |
| 106 | +}); |
0 commit comments