mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 11:02:27 +08:00
test(calendar): labels as promoted attributes
This commit is contained in:
parent
a8b119e4df
commit
e7d06fceba
@ -31,6 +31,13 @@ export function buildNotes(notes: NoteDefinition[]) {
|
|||||||
const ids = [];
|
const ids = [];
|
||||||
|
|
||||||
for (const noteDef of notes) {
|
for (const noteDef of notes) {
|
||||||
|
ids.push(buildNote(noteDef).noteId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ids;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function buildNote(noteDef: NoteDefinition) {
|
||||||
const note = new FNote(froca, {
|
const note = new FNote(froca, {
|
||||||
noteId: noteDef.id ?? utils.randomString(12),
|
noteId: noteDef.id ?? utils.randomString(12),
|
||||||
title: noteDef.title,
|
title: noteDef.title,
|
||||||
@ -40,7 +47,6 @@ export function buildNotes(notes: NoteDefinition[]) {
|
|||||||
blobId: ""
|
blobId: ""
|
||||||
});
|
});
|
||||||
froca.notes[note.noteId] = note;
|
froca.notes[note.noteId] = note;
|
||||||
ids.push(note.noteId);
|
|
||||||
|
|
||||||
let position = 0;
|
let position = 0;
|
||||||
for (const [ key, value ] of Object.entries(noteDef)) {
|
for (const [ key, value ] of Object.entries(noteDef)) {
|
||||||
@ -87,7 +93,5 @@ export function buildNotes(notes: NoteDefinition[]) {
|
|||||||
}
|
}
|
||||||
noteAttributeCache.attributes[note.noteId].push(attribute);
|
noteAttributeCache.attributes[note.noteId].push(attribute);
|
||||||
}
|
}
|
||||||
}
|
return note;
|
||||||
|
|
||||||
return ids;
|
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { describe, expect, it } from "vitest";
|
import { describe, expect, it } from "vitest";
|
||||||
import { buildNotes } from "../../test/easy-froca.js";
|
import { buildNote, buildNotes } from "../../test/easy-froca.js";
|
||||||
import CalendarView from "./calendar_view.js";
|
import CalendarView from "./calendar_view.js";
|
||||||
|
|
||||||
describe("Building events", () => {
|
describe("Building events", () => {
|
||||||
@ -126,3 +126,23 @@ describe("Building events", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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"
|
||||||
|
})
|
||||||
|
});
|
||||||
|
});
|
||||||
|
@ -272,7 +272,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
events.push(await CalendarView.#buildEvent(dateNote, startDate));
|
events.push(await CalendarView.buildEvent(dateNote, startDate));
|
||||||
|
|
||||||
if (dateNote.hasChildren()) {
|
if (dateNote.hasChildren()) {
|
||||||
const childNoteIds = dateNote.getChildNoteIds();
|
const childNoteIds = dateNote.getChildNoteIds();
|
||||||
@ -287,7 +287,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
const childNotes = await froca.getNotes(childNoteIds);
|
const childNotes = await froca.getNotes(childNoteIds);
|
||||||
for (const childNote of childNotes) {
|
for (const childNote of childNotes) {
|
||||||
const startDate = childNoteToDateMapping[childNote.noteId];
|
const startDate = childNoteToDateMapping[childNote.noteId];
|
||||||
const event = await CalendarView.#buildEvent(childNote, startDate);
|
const event = await CalendarView.buildEvent(childNote, startDate);
|
||||||
events.push(event);
|
events.push(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -313,7 +313,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const endDate = CalendarView.#getCustomisableLabel(note, "endDate", "calendar:endDate");
|
const endDate = CalendarView.#getCustomisableLabel(note, "endDate", "calendar:endDate");
|
||||||
events.push(await CalendarView.#buildEvent(note, startDate, endDate));
|
events.push(await CalendarView.buildEvent(note, startDate, endDate));
|
||||||
}
|
}
|
||||||
|
|
||||||
return events.flat();
|
return events.flat();
|
||||||
@ -341,7 +341,7 @@ export default class CalendarView extends ViewMode {
|
|||||||
return note.getLabelValue(defaultLabelName);
|
return note.getLabelValue(defaultLabelName);
|
||||||
}
|
}
|
||||||
|
|
||||||
static async #buildEvent(note: FNote, startDate: string, endDate?: string | null) {
|
static async buildEvent(note: FNote, startDate: string, endDate?: string | null) {
|
||||||
const customTitle = note.getLabelValue("calendar:title");
|
const customTitle = note.getLabelValue("calendar:title");
|
||||||
const titles = await CalendarView.#parseCustomTitle(customTitle, note);
|
const titles = await CalendarView.#parseCustomTitle(customTitle, note);
|
||||||
const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color");
|
const color = note.getLabelValue("calendar:color") ?? note.getLabelValue("color");
|
||||||
@ -378,6 +378,8 @@ export default class CalendarView extends ViewMode {
|
|||||||
const filteredPromotedAttributes = note.getPromotedDefinitionAttributes().filter((attr) => promotedAttributeNames.includes(attr.name));
|
const filteredPromotedAttributes = note.getPromotedDefinitionAttributes().filter((attr) => promotedAttributeNames.includes(attr.name));
|
||||||
const result: Record<string, string> = {};
|
const result: Record<string, string> = {};
|
||||||
|
|
||||||
|
console.log("Got promoted attributes ", promotedAttributeNames, filteredPromotedAttributes);
|
||||||
|
|
||||||
for (const promotedAttribute of filteredPromotedAttributes) {
|
for (const promotedAttribute of filteredPromotedAttributes) {
|
||||||
const [ type, name ] = promotedAttribute.name.split(":", 2);
|
const [ type, name ] = promotedAttribute.name.split(":", 2);
|
||||||
const definition = promotedAttribute.getDefinition();
|
const definition = promotedAttribute.getDefinition();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user