Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
test(calendar): start date & end date
Elian Doran5731cb9b4d0e
diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.tsindex 75eb670790..828688f20d 100644--- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts+++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts@@ -1,16 +1,55 @@-import { describe, it } from "vitest";+import { describe, expect, it } from "vitest";import { buildNotes } from "../../test/easy-froca.js";+import CalendarView from "./calendar_view.js";describe("Building events", () => {it("supports start date", async () => {const noteIds = buildNotes([- { title: "A", "#startDate": "2025-05-05" },- { title: "A", "#startDate": "2025-05-07" },+ { title: "Note 1", "#startDate": "2025-05-05" },+ { title: "Note 2", "#startDate": "2025-05-07" },]);+ const events = await CalendarView.buildEvents(noteIds);++ expect(events).toHaveLength(2);+ expect(events[0]).toMatchObject({+ title: "Note 1",+ start: "2025-05-05",+ end: "2025-05-06"+ });+ expect(events[1]).toMatchObject({+ title: "Note 2",+ start: "2025-05-07",+ end: "2025-05-08"+ });+ });- const CalendarView = (await import("./calendar_view.js")).default;+ it("ignores notes with only end date", async () => {+ const noteIds = buildNotes([+ { title: "Note 1", "#endDate": "2025-05-05" },+ { title: "Note 2", "#endDateDate": "2025-05-07" },+ ]);const events = await CalendarView.buildEvents(noteIds);- console.log(noteIds, events);++ expect(events).toHaveLength(0);});+ it("supports both start date and end date", async () => {+ const noteIds = buildNotes([+ { title: "Note 1", "#startDate": "2025-05-05", "#endDate": "2025-05-05" },+ { title: "Note 2", "#startDate": "2025-05-07", "#endDate": "2025-05-08" },+ ]);+ const events = await CalendarView.buildEvents(noteIds);++ expect(events).toHaveLength(2);+ expect(events[0]).toMatchObject({+ title: "Note 1",+ start: "2025-05-05",+ end: "2025-05-06"+ });+ expect(events[1]).toMatchObject({+ title: "Note 2",+ start: "2025-05-07",+ end: "2025-05-09"+ });+ });});