forked from GitHubMirrors/silverbullet-icalendar
switch to ical.js and cleanup obsolete files - v0.4.6 [skip-ci]
All checks were successful
Build SilverBullet Plug / build (push) Successful in 11s
All checks were successful
Build SilverBullet Plug / build (push) Successful in 11s
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { assertEquals, assert } from "jsr:@std/assert";
|
||||
import { resolveEventStart, expandRecurrences, localDateString } from "../icalendar.ts";
|
||||
import { resolveEventStart, expandRecurrences, dateToTimezoneString } from "../icalendar.ts";
|
||||
|
||||
const TEST_NOW = new Date("2026-01-20T12:00:00Z");
|
||||
|
||||
@@ -42,24 +42,26 @@ Deno.test("Variation: Transparent Meeting (Free)", async () => {
|
||||
});
|
||||
|
||||
Deno.test("Variation: Recurring Weekly (Multi-day: MO,TU,WE,TH,FR)", () => {
|
||||
const start = new Date("2026-01-16T13:00:00");
|
||||
const icsEvent = {
|
||||
summary: "BUSY Weekly",
|
||||
start: "2026-01-16T13:00:00",
|
||||
start: start.toISOString(),
|
||||
rrule: "FREQ=WEEKLY;UNTIL=20260814T170000Z;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR;WKST=SU"
|
||||
};
|
||||
|
||||
// Use TEST_NOW to ensure the window matches
|
||||
const results = expandRecurrences(icsEvent, 7, TEST_NOW);
|
||||
const results = expandRecurrences(icsEvent, 7, "UTC", TEST_NOW);
|
||||
// Should have multiple occurrences per week
|
||||
assert(results.length > 1);
|
||||
assert(results.some(r => r.start.includes("2026-01-19"))); // Monday
|
||||
assert(results.some(r => r.start.includes("2026-01-20"))); // Tuesday
|
||||
assert(results.some(r => r.startLocal.includes("2026-01-19"))); // Monday
|
||||
assert(results.some(r => r.startLocal.includes("2026-01-20"))); // Tuesday
|
||||
});
|
||||
|
||||
Deno.test("Variation: Recurring with WORKWEEKSTART (Outlook style)", () => {
|
||||
const start = new Date("2026-01-20T08:30:00");
|
||||
const icsEvent = {
|
||||
summary: "Outlook Style Meeting",
|
||||
start: "2026-01-20T08:30:00",
|
||||
start: start.toISOString(),
|
||||
rrule: {
|
||||
frequency: "WEEKLY",
|
||||
interval: 1,
|
||||
@@ -68,40 +70,42 @@ Deno.test("Variation: Recurring with WORKWEEKSTART (Outlook style)", () => {
|
||||
}
|
||||
};
|
||||
|
||||
const results = expandRecurrences(icsEvent, 30, TEST_NOW);
|
||||
const results = expandRecurrences(icsEvent, 30, "UTC", TEST_NOW);
|
||||
assert(results.length > 0);
|
||||
assert(results[0].start.includes("2026-01-20"));
|
||||
assert(results[0].startLocal.includes("2026-01-20"));
|
||||
});
|
||||
|
||||
Deno.test("Variation: Recurring with EXDATE (Exclusion)", () => {
|
||||
const start = new Date("2026-01-20T08:30:00");
|
||||
const icsEvent = {
|
||||
summary: "HPE-Veeam check-in",
|
||||
start: "2026-01-20T08:30:00",
|
||||
start: start.toISOString(),
|
||||
rrule: "FREQ=WEEKLY;UNTIL=20260324T143000Z;INTERVAL=1;BYDAY=TU;WKST=SU",
|
||||
exdate: ["2026-02-03T08:30:00"]
|
||||
};
|
||||
|
||||
const results = expandRecurrences(icsEvent, 60, TEST_NOW);
|
||||
const dates = results.map(r => r.start);
|
||||
assert(dates.includes("2026-01-20T08:30:00"));
|
||||
assert(dates.includes("2026-01-27T08:30:00"));
|
||||
assert(!dates.includes("2026-02-03T08:30:00"), "EXDATE should be excluded");
|
||||
assert(dates.includes("2026-02-10T08:30:00"));
|
||||
const results = expandRecurrences(icsEvent, 60, "UTC", TEST_NOW);
|
||||
const dates = results.map(r => r.startLocal);
|
||||
assert(dates.some(d => d.includes("2026-01-20T")), "Should find first occurrence");
|
||||
assert(dates.some(d => d.includes("2026-01-27T")), "Should find second occurrence");
|
||||
assert(!dates.some(d => d.includes("2026-02-03T")), "EXDATE 2026-02-03 should be excluded");
|
||||
assert(dates.some(d => d.includes("2026-02-10T")), "Should find fourth occurrence");
|
||||
});
|
||||
|
||||
Deno.test("Variation: Monthly Recurring (Last Friday)", () => {
|
||||
const start = new Date("2026-01-30T10:00:00");
|
||||
const icsEvent = {
|
||||
summary: "Monthly Planning",
|
||||
start: "2026-01-30T10:00:00", // This is the last Friday of Jan 2026
|
||||
start: start.toISOString(), // This is the last Friday of Jan 2026
|
||||
rrule: "FREQ=MONTHLY;UNTIL=20260731T170000Z;INTERVAL=1;BYDAY=-1FR"
|
||||
};
|
||||
|
||||
const results = expandRecurrences(icsEvent, 100, TEST_NOW);
|
||||
const dates = results.map(r => r.start);
|
||||
const results = expandRecurrences(icsEvent, 100, "UTC", TEST_NOW);
|
||||
const dates = results.map(r => r.startLocal);
|
||||
|
||||
assert(dates.includes("2026-01-30T10:00:00"));
|
||||
assert(dates.includes("2026-02-27T10:00:00")); // Last Friday of Feb 2026
|
||||
assert(dates.includes("2026-03-27T10:00:00")); // Last Friday of Mar 2026
|
||||
assert(dates.some(d => d.includes("2026-01-30")), "Should find Jan occurrence");
|
||||
assert(dates.some(d => d.includes("2026-02-27")), "Should find Feb occurrence");
|
||||
assert(dates.some(d => d.includes("2026-03-27")), "Should find Mar occurrence");
|
||||
});
|
||||
|
||||
Deno.test("Variation: Tentative Meeting", async () => {
|
||||
@@ -134,13 +138,13 @@ Deno.test("Feature: Unlimited lookback window", () => {
|
||||
const start = new Date(TEST_NOW.getTime() - 500 * 86400000); // 500 days ago
|
||||
const icsEvent = {
|
||||
summary: "Event from 500 days ago",
|
||||
start: localDateString(start),
|
||||
start: start.toISOString(),
|
||||
rrule: "FREQ=DAILY;COUNT=1000"
|
||||
};
|
||||
|
||||
const results = expandRecurrences(icsEvent, 30, TEST_NOW);
|
||||
const results = expandRecurrences(icsEvent, 30, "UTC", TEST_NOW);
|
||||
// Should include events from 500 days ago because there is now no limit
|
||||
assert(results.some(r => r.start === localDateString(start)), "Should find occurrence from 500 days ago");
|
||||
assert(results.some(r => r.startLocal === dateToTimezoneString(start, "UTC")), "Should find occurrence from 500 days ago");
|
||||
});
|
||||
|
||||
Deno.test("Feature: Hash Collision Prevention (Same UID/Start, Different Summary)", async () => {
|
||||
|
||||
Reference in New Issue
Block a user