Files
lunch/tests/calendar.test.ts
kai 6f43b81f9b
release / which version (push) Successful in 2s
release / olares chart · sanity (push) Successful in 3s
release / app (push) Successful in 1m5s
release / tag and release (push) Successful in 2s
26.11.45: Runde beenden, Tage, Kalender-Abo (#46)
2026-11-08 05:23:22 +00:00

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");
});
});