mirror of
https://github.com/zadam/trilium.git
synced 2025-10-19 06:38:59 +02:00
test(collection/presentation): test slide order
This commit is contained in:
parent
13f2061e75
commit
7e6231698c
@ -3,6 +3,7 @@ import FNote from "../entities/fnote.js";
|
||||
import froca from "../services/froca.js";
|
||||
import FAttribute from "../entities/fattribute.js";
|
||||
import noteAttributeCache from "../services/note_attribute_cache.js";
|
||||
import FBranch from "../entities/fbranch.js";
|
||||
|
||||
type AttributeDefinitions = { [key in `#${string}`]: string; };
|
||||
type RelationDefinitions = { [key in `~${string}`]: string; };
|
||||
@ -10,6 +11,7 @@ type RelationDefinitions = { [key in `~${string}`]: string; };
|
||||
interface NoteDefinition extends AttributeDefinitions, RelationDefinitions {
|
||||
id?: string | undefined;
|
||||
title: string;
|
||||
children?: NoteDefinition[];
|
||||
}
|
||||
|
||||
/**
|
||||
@ -47,6 +49,24 @@ export function buildNote(noteDef: NoteDefinition) {
|
||||
blobId: ""
|
||||
});
|
||||
froca.notes[note.noteId] = note;
|
||||
let childNotePosition = 0;
|
||||
|
||||
if (noteDef.children) {
|
||||
for (const childDef of noteDef.children) {
|
||||
const childNote = buildNote(childDef);
|
||||
const branchId = `${note.noteId}_${childNote.noteId}`;
|
||||
const branch = new FBranch(froca, {
|
||||
branchId,
|
||||
noteId: childNote.noteId,
|
||||
parentNoteId: note.noteId,
|
||||
notePosition: childNotePosition,
|
||||
fromSearchNote: false
|
||||
});
|
||||
froca.branches[branchId] = branch;
|
||||
note.addChild(childNote.noteId, branchId, false);
|
||||
childNotePosition += 10;
|
||||
}
|
||||
}
|
||||
|
||||
let position = 0;
|
||||
for (const [ key, value ] of Object.entries(noteDef)) {
|
||||
|
@ -0,0 +1,62 @@
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { buildNote } from "../../../test/easy-froca";
|
||||
import FNote from "../../../entities/fnote";
|
||||
import { buildPresentationModel, PresentationModel } from "./model";
|
||||
|
||||
let presentationNote!: FNote;
|
||||
let data!: PresentationModel;
|
||||
|
||||
describe("Presentation model", () => {
|
||||
beforeAll(async () => {
|
||||
presentationNote = buildNote({
|
||||
title: "Presentation",
|
||||
"#viewType": "presentation",
|
||||
"children": [
|
||||
{
|
||||
id: "slide1",
|
||||
title: "First slide",
|
||||
children: [
|
||||
{
|
||||
id: "slide2",
|
||||
title: "First-sub"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
title: "Second slide",
|
||||
id: "slide3",
|
||||
children: [
|
||||
{
|
||||
id: "slide4",
|
||||
title: "Second-sub"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
});
|
||||
data = await buildPresentationModel(presentationNote);
|
||||
});
|
||||
|
||||
it("it correctly maps horizontal and vertical slides", () => {
|
||||
expect(data).toMatchObject({
|
||||
slides: [
|
||||
{
|
||||
noteId: "slide1",
|
||||
verticalSlides: [
|
||||
{
|
||||
noteId: "slide2"
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
noteId: "slide3",
|
||||
verticalSlides: [
|
||||
{
|
||||
noteId: "slide4"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
})
|
||||
});
|
||||
});
|
Loading…
x
Reference in New Issue
Block a user