mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-11 02:42:27 +08:00
refactor(test): dedicated helper for froca
This commit is contained in:
parent
ad18916973
commit
d83b2a6a38
64
src/public/app/test/easy-froca.ts
Normal file
64
src/public/app/test/easy-froca.ts
Normal file
@ -0,0 +1,64 @@
|
||||
import utils from "../services/utils.js";
|
||||
import FNote from "../entities/fnote.js";
|
||||
import froca from "../services/froca.js";
|
||||
import FAttribute from "../entities/fattribute.js";
|
||||
|
||||
interface NoteDefinition {
|
||||
title: string;
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the given notes with the given title and optionally one or more attributes.
|
||||
*
|
||||
* For a label to be created, simply pass on a key prefixed with `#` and any desired value.
|
||||
*
|
||||
* The notes and attributes will be injected in the froca.
|
||||
*
|
||||
* @param notes
|
||||
* @returns an array containing the IDs of the created notes.
|
||||
* @example
|
||||
* buildNotes([
|
||||
* { title: "A", "#startDate": "2025-05-05" },
|
||||
* { title: "B", "#startDate": "2025-05-07" }
|
||||
* ]);
|
||||
*/
|
||||
export function buildNotes(notes: NoteDefinition[]) {
|
||||
const ids = [];
|
||||
|
||||
for (const noteDef of notes) {
|
||||
const fakeNoteId = utils.randomString(6);
|
||||
const note = new FNote(froca, {
|
||||
noteId: fakeNoteId,
|
||||
title: noteDef.title,
|
||||
type: "text",
|
||||
mime: "text/html",
|
||||
isProtected: false,
|
||||
blobId: ""
|
||||
});
|
||||
froca.notes[note.noteId] = note;
|
||||
ids.push(note.noteId);
|
||||
|
||||
let position = 0;
|
||||
for (const [ key, value ] of Object.entries(noteDef)) {
|
||||
if (key.startsWith("#")) {
|
||||
const attributeId = utils.randomString(12);
|
||||
const attribute = new FAttribute(froca, {
|
||||
noteId: note.noteId,
|
||||
attributeId: attributeId,
|
||||
type: "label",
|
||||
name: key.substring(1),
|
||||
value: value,
|
||||
position: position,
|
||||
isInheritable: false
|
||||
});
|
||||
froca.attributes[attributeId] = attribute;
|
||||
note.attributes.push(attributeId);
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
@ -1,61 +1,13 @@
|
||||
import { describe, it } from "vitest";
|
||||
import utils from "../../services/utils.js";
|
||||
import FNote from "../../entities/fnote.js";
|
||||
import froca from "../../services/froca.js";
|
||||
import FAttribute from "../../entities/fattribute.js";
|
||||
|
||||
interface NoteDefinition {
|
||||
title: string;
|
||||
[key: string]: string;
|
||||
}
|
||||
|
||||
async function buildNotes(notes: NoteDefinition[]) {
|
||||
const ids = [];
|
||||
|
||||
for (const noteDef of notes) {
|
||||
const fakeNoteId = utils.randomString(6);
|
||||
const note = new FNote(froca, {
|
||||
noteId: fakeNoteId,
|
||||
title: noteDef.title,
|
||||
type: "text",
|
||||
mime: "text/html",
|
||||
isProtected: false,
|
||||
blobId: ""
|
||||
});
|
||||
froca.notes[note.noteId] = note;
|
||||
ids.push(note.noteId);
|
||||
|
||||
let position = 0;
|
||||
for (const [ key, value ] of Object.entries(noteDef)) {
|
||||
if (key.startsWith("#")) {
|
||||
const attributeId = utils.randomString(12);
|
||||
const attribute = new FAttribute(froca, {
|
||||
noteId: note.noteId,
|
||||
attributeId: attributeId,
|
||||
type: "label",
|
||||
name: key.substring(1),
|
||||
value: value,
|
||||
position: position,
|
||||
isInheritable: false
|
||||
});
|
||||
froca.attributes[attributeId] = attribute;
|
||||
note.attributes.push(attributeId);
|
||||
}
|
||||
|
||||
position++;
|
||||
}
|
||||
}
|
||||
|
||||
return ids;
|
||||
}
|
||||
import { buildNotes } from "../../test/easy-froca.js";
|
||||
|
||||
describe("Building events", () => {
|
||||
it("supports start date", async () => {
|
||||
const noteIds = await buildNotes([
|
||||
{ title: "A", "#startDate": "2025-05-05" }
|
||||
const noteIds = buildNotes([
|
||||
{ title: "A", "#startDate": "2025-05-05" },
|
||||
{ title: "A", "#startDate": "2025-05-07" },
|
||||
]);
|
||||
|
||||
// import CalendarView from "./calendar_view.js";
|
||||
const CalendarView = (await import("./calendar_view.js")).default;
|
||||
const events = await CalendarView.buildEvents(noteIds);
|
||||
console.log(noteIds, events);
|
||||
|
Loading…
x
Reference in New Issue
Block a user