From f674ba0d4ac9ba06f632687c446c9084e45f5704 Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Fri, 28 Feb 2025 19:32:32 +0200 Subject: [PATCH] test(calendar): custom start/end date --- .../view_widgets/calendar_view.spec.ts | 37 +++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.ts index 828688f20..63e841745 100644 --- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts +++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts @@ -52,4 +52,41 @@ describe("Building events", () => { end: "2025-05-09" }); }); + + it("supports custom start date", async () => { + const noteIds = buildNotes([ + { title: "Note 1", "#myStartDate": "2025-05-05", "#calendar:startDate": "#myStartDate" }, + { title: "Note 2", "#startDate": "2025-05-07", "#calendar:startDate": "#myStartDate" }, + ]); + 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" + }); + }); + + it("supports custom start date and end date", async () => { + const noteIds = buildNotes([ + { title: "Note 1", "#myStartDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, + { title: "Note 2", "#myStartDate": "2025-05-07", "#endDate": "2025-05-08", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, + { title: "Note 3", "#startDate": "2025-05-05", "#myEndDate": "2025-05-05", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, + { title: "Note 4", "#startDate": "2025-05-07", "#myEndDate": "2025-05-08", "#calendar:startDate": "#myStartDate", "#calendar:endDate": "#myEndDate" }, + ]); + const events = await CalendarView.buildEvents(noteIds); + + expect(events).toHaveLength(4); + 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" }); + expect(events[2]).toMatchObject({ title: "Note 3", start: "2025-05-05", end: "2025-05-06" }); + expect(events[3]).toMatchObject({ title: "Note 4", start: "2025-05-07", end: "2025-05-09" }); + }); + });