37 lines
1.8 KiB
TypeScript
37 lines
1.8 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { buildCalendar, escapeText, fold } from "@/lib/calendar";
|
|
|
|
// Kalender-Abo (26.11.45): RFC 5545 ohne Datenbank.
|
|
describe("calendar", () => {
|
|
it("escapes text", () => {
|
|
expect(escapeText("Linsen, rot; scharf\\mild\nmit Reis")).toBe("Linsen\\, rot\; scharf\\\\mild\\nmit Reis");
|
|
});
|
|
|
|
it("folds long lines without splitting a character", () => {
|
|
const line = `SUMMARY:${"Käsespätzle ".repeat(12)}`;
|
|
const folded = fold(line);
|
|
for (const part of folded.split("\r\n")) expect(Buffer.byteLength(part, "utf8")).toBeLessThanOrEqual(75);
|
|
expect(folded.split("\r\n").map((p, i) => (i ? p.slice(1) : p)).join("")).toBe(line);
|
|
});
|
|
|
|
it("writes one event per dish at meal time in Berlin time", () => {
|
|
const ics = buildCalendar(
|
|
"Böhm · Essen",
|
|
[{ uid: "s1@foodplanhero", day: "2026-11-09", start: "18:30", minutes: 60, summary: "Curry, rot", description: "Es kocht Maike\n4 Portionen", url: "https://x/gerichte/1" }],
|
|
new Date("2026-11-08T10:00:00Z"),
|
|
);
|
|
expect(ics).toContain("BEGIN:VTIMEZONE\r\nTZID:Europe/Berlin");
|
|
expect(ics).toContain("UID:s1@foodplanhero\r\nDTSTAMP:20261108T100000Z\r\nDTSTART;TZID=Europe/Berlin:20261109T183000\r\nDTEND;TZID=Europe/Berlin:20261109T193000");
|
|
expect(ics).toContain("SUMMARY:Curry\\, rot");
|
|
expect(ics).toContain("DESCRIPTION:Es kocht Maike\\n4 Portionen");
|
|
expect(ics.endsWith("END:VCALENDAR\r\n")).toBe(true);
|
|
expect(ics.split("BEGIN:VEVENT")).toHaveLength(2);
|
|
});
|
|
|
|
it("carries a late meal past midnight", () => {
|
|
const ics = buildCalendar("x", [{ uid: "a", day: "2026-12-31", start: "23:30", minutes: 60, summary: "Fondue", description: "", url: null }]);
|
|
expect(ics).toContain("DTEND;TZID=Europe/Berlin:20270101T003000");
|
|
expect(ics).not.toContain("DESCRIPTION");
|
|
});
|
|
});
|