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): relation as custom title
Elian Doranca7cff45c976
diff --git a/src/public/app/test/easy-froca.ts b/src/public/app/test/easy-froca.tsindex 7e214579c7..48dd5f2454 100644--- a/src/public/app/test/easy-froca.ts+++ b/src/public/app/test/easy-froca.ts@@ -3,9 +3,10 @@ import FNote from "../entities/fnote.js";import froca from "../services/froca.js";import FAttribute from "../entities/fattribute.js";-type AttributeDefinitions = { [key in `#${string}`]: string; }+type AttributeDefinitions = { [key in `#${string}`]: string; };+type RelationDefinitions = { [key in `~${string}`]: string; };-interface NoteDefinition extends AttributeDefinitions {+interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {id?: string | undefined;title: string;}@@ -42,21 +43,41 @@ export function buildNotes(notes: NoteDefinition[]) {let position = 0;for (const [ key, value ] of Object.entries(noteDef)) {+ const attributeId = utils.randomString(12);+ const name = key.substring(1);++ let attribute: FAttribute | null = null;if (key.startsWith("#")) {- const attributeId = utils.randomString(12);- const attribute = new FAttribute(froca, {+ attribute = new FAttribute(froca, {noteId: note.noteId,- attributeId: attributeId,+ attributeId,type: "label",- name: key.substring(1),- value: value,- position: position,+ name,+ value,+ position,+ isInheritable: false+ });+ }++ if (key.startsWith("~")) {+ console.log("Created relation with ", name, value);+ attribute = new FAttribute(froca, {+ noteId: note.noteId,+ attributeId,+ type: "relation",+ name,+ value,+ position,isInheritable: false});- froca.attributes[attributeId] = attribute;- note.attributes.push(attributeId);}+ if (!attribute) {+ continue;+ }++ froca.attributes[attributeId] = attribute;+ note.attributes.push(attributeId);position++;}}diff --git a/src/public/app/test/setup.ts b/src/public/app/test/setup.tsindex 47b827e0ea..5165534228 100644--- a/src/public/app/test/setup.ts+++ b/src/public/app/test/setup.ts@@ -46,6 +46,12 @@ function mockServer() {attributes: []}}+ },++ async post(url: string, data: {}) {+ if (url === "tree/load") {+ throw new Error(`A module tried to load from the server the following notes: ${data.noteIds.join(",")}\nThis is not supported, use Froca mocking instead and ensure the note exist in the mock.`)+ }}}};diff --git a/src/public/app/widgets/view_widgets/calendar_view.spec.ts b/src/public/app/widgets/view_widgets/calendar_view.spec.tsindex e5b536a62d..8c1be2961b 100644--- a/src/public/app/widgets/view_widgets/calendar_view.spec.ts+++ b/src/public/app/widgets/view_widgets/calendar_view.spec.ts@@ -85,4 +85,17 @@ describe("Building events", () => {expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });});+ 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" });+ });+});