Files
Trilium/src/public/app/widgets/view_widgets/calendar_view.spec.ts

56 lines
1.8 KiB
TypeScript
Raw Normal View History

2025-02-28 19:23:45 +02:00
import { describe, expect, it } from "vitest";
import { buildNotes } from "../../test/easy-froca.js";
2025-02-28 19:23:45 +02:00
import CalendarView from "./calendar_view.js";
describe("Building events", () => {
it("supports start date", async () => {
const noteIds = buildNotes([
2025-02-28 19:23:45 +02:00
{ title: "Note 1", "#startDate": "2025-05-05" },
{ title: "Note 2", "#startDate": "2025-05-07" },
]);
2025-02-28 19:23:45 +02:00
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"
});
});
2025-02-28 19:23:45 +02:00
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);
2025-02-28 19:23:45 +02:00
expect(events).toHaveLength(0);
});
2025-02-28 19:23:45 +02:00
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"
});
});
});