2025-02-28 19:23:45 +02:00
|
|
|
import { describe, expect, it } from "vitest";
|
2025-02-28 20:34:30 +02:00
|
|
|
import { buildNote, buildNotes } from "../../test/easy-froca.js";
|
2025-02-28 19:23:45 +02:00
|
|
|
import CalendarView from "./calendar_view.js";
|
2025-02-28 19:03:08 +02:00
|
|
|
|
|
|
|
|
describe("Building events", () => {
|
|
|
|
|
it("supports start date", async () => {
|
2025-02-28 19:17:52 +02:00
|
|
|
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:03:08 +02:00
|
|
|
]);
|
2025-02-28 19:23:45 +02:00
|
|
|
const events = await CalendarView.buildEvents(noteIds);
|
|
|
|
|
|
|
|
|
|
expect(events).toHaveLength(2);
|
2025-02-28 19:36:50 +02:00
|
|
|
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
|
|
|
});
|
2025-02-28 19:03:08 +02:00
|
|
|
|
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" },
|
2025-02-28 19:44:32 +02:00
|
|
|
{ title: "Note 2", "#endDateDate": "2025-05-07" }
|
2025-02-28 19:23:45 +02:00
|
|
|
]);
|
2025-02-28 19:03:19 +02:00
|
|
|
const events = await CalendarView.buildEvents(noteIds);
|
2025-02-28 19:23:45 +02:00
|
|
|
|
|
|
|
|
expect(events).toHaveLength(0);
|
2025-02-28 19:03:08 +02:00
|
|
|
});
|
|
|
|
|
|
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);
|
2025-02-28 19:36:50 +02:00
|
|
|
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" });
|
2025-02-28 19:23:45 +02:00
|
|
|
});
|
2025-02-28 19:32:32 +02:00
|
|
|
|
|
|
|
|
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" });
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-28 19:36:50 +02:00
|
|
|
it("supports label as custom title", async () => {
|
|
|
|
|
const noteIds = buildNotes([
|
|
|
|
|
{ title: "Note 1", "#myTitle": "My Custom Title 1", "#startDate": "2025-05-05", "#calendar:title": "#myTitle" },
|
|
|
|
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "#myTitle" },
|
|
|
|
|
]);
|
|
|
|
|
const events = await CalendarView.buildEvents(noteIds);
|
|
|
|
|
|
|
|
|
|
expect(events).toHaveLength(2);
|
|
|
|
|
expect(events[0]).toMatchObject({ title: "My Custom Title 1", start: "2025-05-05" });
|
|
|
|
|
expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-28 19:55:02 +02:00
|
|
|
it("supports relation as custom title", async () => {
|
|
|
|
|
const noteIds = buildNotes([
|
|
|
|
|
{ id: "mySharedTitle", title: "My shared title" },
|
|
|
|
|
{ title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },
|
|
|
|
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },
|
|
|
|
|
]);
|
|
|
|
|
const events = await CalendarView.buildEvents(noteIds);
|
|
|
|
|
|
|
|
|
|
expect(events).toHaveLength(2);
|
|
|
|
|
expect(events[0]).toMatchObject({ title: "My shared title", start: "2025-05-05" });
|
|
|
|
|
expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-28 20:11:45 +02:00
|
|
|
it("supports relation as custom title with custom label", async () => {
|
|
|
|
|
const noteIds = buildNotes([
|
|
|
|
|
{ id: "mySharedTitle", title: "My custom title", "#myTitle": "My shared custom title", "#calendar:title": "#myTitle" },
|
|
|
|
|
{ title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },
|
|
|
|
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },
|
|
|
|
|
]);
|
|
|
|
|
const events = await CalendarView.buildEvents(noteIds);
|
|
|
|
|
|
|
|
|
|
expect(events).toHaveLength(2);
|
|
|
|
|
expect(events[0]).toMatchObject({ title: "My shared custom title", start: "2025-05-05" });
|
|
|
|
|
expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-28 20:13:37 +02:00
|
|
|
it("discards relation as custom title with custom relation", async () => {
|
|
|
|
|
const noteIds = buildNotes([
|
|
|
|
|
{ id: "myParentNote", title: "My parent note" },
|
|
|
|
|
{ id: "mySharedTitle", title: "My custom title", "~myTitle": "myParentNote", "#calendar:title": "~myTitle" },
|
|
|
|
|
{ title: "Note 1", "~myTitle": "mySharedTitle", "#startDate": "2025-05-05", "#calendar:title": "~myTitle" },
|
|
|
|
|
{ title: "Note 2", "#startDate": "2025-05-07", "#calendar:title": "~myTitle" },
|
|
|
|
|
]);
|
|
|
|
|
const events = await CalendarView.buildEvents(noteIds);
|
|
|
|
|
|
|
|
|
|
expect(events).toHaveLength(2);
|
|
|
|
|
expect(events[0]).toMatchObject({ title: "My shared custom title", start: "2025-05-05" });
|
|
|
|
|
expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
|
|
|
|
|
});
|
|
|
|
|
|
2025-02-28 19:03:08 +02:00
|
|
|
});
|
2025-02-28 20:34:30 +02:00
|
|
|
|
|
|
|
|
describe("Promoted attributes", () => {
|
|
|
|
|
it("supports labels", async () => {
|
|
|
|
|
const note = buildNote({
|
|
|
|
|
"title": "Hello",
|
|
|
|
|
"#weight": "75",
|
|
|
|
|
"#mood": "happy",
|
|
|
|
|
"#label:weight": "promoted,number,single,precision=1",
|
|
|
|
|
"#label:mood": "promoted,alias=Mood,single,text",
|
|
|
|
|
"#calendar:promotedAttributes": "label:weight,label:mood"
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const event = await CalendarView.buildEvent(note, "2025-04-04");
|
|
|
|
|
expect(event).toHaveLength(1);
|
|
|
|
|
expect(event[0]?.promotedAttributes).toMatchObject({
|
|
|
|
|
weight: "75",
|
|
|
|
|
Mood: "happy"
|
|
|
|
|
})
|
|
|
|
|
});
|
2025-02-28 20:45:23 +02:00
|
|
|
|
|
|
|
|
it("supports relations", async () => {
|
|
|
|
|
const note = buildNote({
|
|
|
|
|
"title": "Hello",
|
|
|
|
|
"~assignee": buildNote({
|
|
|
|
|
"title": "Target note"
|
|
|
|
|
}).noteId,
|
|
|
|
|
"#calendar:promotedAttributes": "relation:assignee",
|
|
|
|
|
"#relation:assignee": "promoted,alias=Assignee,single,text",
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const event = await CalendarView.buildEvent(note, "2025-04-04");
|
|
|
|
|
expect(event).toHaveLength(1);
|
|
|
|
|
expect(event[0]?.promotedAttributes).toMatchObject({
|
|
|
|
|
"Assignee": "Target note"
|
|
|
|
|
})
|
|
|
|
|
});
|
2025-02-28 20:34:30 +02:00
|
|
|
});
|