mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 02:52:27 +08:00
test(calendar): relation as custom title
This commit is contained in:
parent
6f2a0f9ee1
commit
ca7cff45c9
@ -3,9 +3,10 @@ import FNote from "../entities/fnote.js";
|
|||||||
import froca from "../services/froca.js";
|
import froca from "../services/froca.js";
|
||||||
import FAttribute from "../entities/fattribute.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;
|
id?: string | undefined;
|
||||||
title: string;
|
title: string;
|
||||||
}
|
}
|
||||||
@ -42,21 +43,41 @@ export function buildNotes(notes: NoteDefinition[]) {
|
|||||||
|
|
||||||
let position = 0;
|
let position = 0;
|
||||||
for (const [ key, value ] of Object.entries(noteDef)) {
|
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("#")) {
|
if (key.startsWith("#")) {
|
||||||
const attributeId = utils.randomString(12);
|
attribute = new FAttribute(froca, {
|
||||||
const attribute = new FAttribute(froca, {
|
|
||||||
noteId: note.noteId,
|
noteId: note.noteId,
|
||||||
attributeId: attributeId,
|
attributeId,
|
||||||
type: "label",
|
type: "label",
|
||||||
name: key.substring(1),
|
name,
|
||||||
value: value,
|
value,
|
||||||
position: position,
|
position,
|
||||||
isInheritable: false
|
isInheritable: false
|
||||||
});
|
});
|
||||||
froca.attributes[attributeId] = attribute;
|
|
||||||
note.attributes.push(attributeId);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!attribute) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
froca.attributes[attributeId] = attribute;
|
||||||
|
note.attributes.push(attributeId);
|
||||||
position++;
|
position++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -46,6 +46,12 @@ function mockServer() {
|
|||||||
attributes: []
|
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.`)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -85,4 +85,17 @@ describe("Building events", () => {
|
|||||||
expect(events[1]).toMatchObject({ title: "Note 2", start: "2025-05-07" });
|
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" });
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user