test(collection/presentation): test slide order

This commit is contained in:
Elian Doran 2025-10-18 15:31:30 +03:00
parent 13f2061e75
commit 7e6231698c
No known key found for this signature in database
2 changed files with 82 additions and 0 deletions

View File

@ -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)) {

View File

@ -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"
}
]
}
]
})
});
});