@@ -5,6 +5,7 @@ import BBranch from "../becca/entities/bbranch.js";
55import BNote from "../becca/entities/bnote.js" ;
66import tree from "./tree.js" ;
77import cls from "./cls.js" ;
8+ import { buildNote } from "../test/becca_easy_mocking.js" ;
89
910describe ( "Tree" , ( ) => {
1011 let rootNote ! : NoteBuilder ;
@@ -73,4 +74,43 @@ describe("Tree", () => {
7374 expect ( order ) . toStrictEqual ( expectedOrder ) ;
7475 }
7576 } ) ;
77+
78+ it ( "pins to the top and bottom" , ( ) => {
79+ const note = buildNote ( {
80+ children : [
81+ { title : "bottom" , "#bottom" : "" } ,
82+ { title : "5" } ,
83+ { title : "3" } ,
84+ { title : "2" } ,
85+ { title : "1" } ,
86+ { title : "top" , "#top" : "" }
87+ ] ,
88+ "#sorted" : ""
89+ } ) ;
90+ cls . init ( ( ) => {
91+ tree . sortNotesIfNeeded ( note . noteId ) ;
92+ } ) ;
93+ const orderedTitles = note . children . map ( ( child ) => child . title ) ;
94+ expect ( orderedTitles ) . toStrictEqual ( [ "top" , "1" , "2" , "3" , "5" , "bottom" ] ) ;
95+ } ) ;
96+
97+ it ( "pins to the top and bottom in reverse order" , ( ) => {
98+ const note = buildNote ( {
99+ children : [
100+ { title : "bottom" , "#bottom" : "" } ,
101+ { title : "1" } ,
102+ { title : "2" } ,
103+ { title : "3" } ,
104+ { title : "5" } ,
105+ { title : "top" , "#top" : "" }
106+ ] ,
107+ "#sorted" : "" ,
108+ "#sortDirection" : "desc"
109+ } ) ;
110+ cls . init ( ( ) => {
111+ tree . sortNotesIfNeeded ( note . noteId ) ;
112+ } ) ;
113+ const orderedTitles = note . children . map ( ( child ) => child . title ) ;
114+ expect ( orderedTitles ) . toStrictEqual ( [ "top" , "5" , "3" , "2" , "1" , "bottom" ] ) ;
115+ } ) ;
76116} ) ;
0 commit comments