mirror of
https://github.com/zadam/trilium.git
synced 2025-11-16 13:34:30 +01:00
fix(tree): #top/#bottom reversed in desc order (closes #7716)
This commit is contained in:
parent
948688a4ea
commit
c9f648fcb8
@ -5,6 +5,7 @@ import BBranch from "../becca/entities/bbranch.js";
|
||||
import BNote from "../becca/entities/bnote.js";
|
||||
import tree from "./tree.js";
|
||||
import cls from "./cls.js";
|
||||
import { buildNote } from "../test/becca_easy_mocking.js";
|
||||
|
||||
describe("Tree", () => {
|
||||
let rootNote!: NoteBuilder;
|
||||
@ -73,4 +74,43 @@ describe("Tree", () => {
|
||||
expect(order).toStrictEqual(expectedOrder);
|
||||
}
|
||||
});
|
||||
|
||||
it("pins to the top and bottom", () => {
|
||||
const note = buildNote({
|
||||
children: [
|
||||
{ title: "bottom", "#bottom": "" },
|
||||
{ title: "5" },
|
||||
{ title: "3" },
|
||||
{ title: "2" },
|
||||
{ title: "1" },
|
||||
{ title: "top", "#top": "" }
|
||||
],
|
||||
"#sorted": ""
|
||||
});
|
||||
cls.init(() => {
|
||||
tree.sortNotesIfNeeded(note.noteId);
|
||||
});
|
||||
const orderedTitles = note.children.map((child) => child.title);
|
||||
expect(orderedTitles).toStrictEqual([ "top", "1", "2", "3", "5", "bottom" ]);
|
||||
});
|
||||
|
||||
it("pins to the top and bottom in reverse order", () => {
|
||||
const note = buildNote({
|
||||
children: [
|
||||
{ title: "bottom", "#bottom": "" },
|
||||
{ title: "1" },
|
||||
{ title: "2" },
|
||||
{ title: "3" },
|
||||
{ title: "5" },
|
||||
{ title: "top", "#top": "" }
|
||||
],
|
||||
"#sorted": "",
|
||||
"#sortDirection": "desc"
|
||||
});
|
||||
cls.init(() => {
|
||||
tree.sortNotesIfNeeded(note.noteId);
|
||||
});
|
||||
const orderedTitles = note.children.map((child) => child.title);
|
||||
expect(orderedTitles).toStrictEqual([ "top", "5", "3", "2", "1", "bottom" ]);
|
||||
});
|
||||
});
|
||||
|
||||
@ -136,8 +136,8 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
|
||||
const topBEl = fetchValue(b, "top");
|
||||
|
||||
if (topAEl !== topBEl) {
|
||||
if (topAEl === null) return 1;
|
||||
if (topBEl === null) return -1;
|
||||
if (topAEl === null) return reverse ? -1 : 1;
|
||||
if (topBEl === null) return reverse ? 1 : -1;
|
||||
|
||||
// since "top" should not be reversible, we'll reverse it once more to nullify this effect
|
||||
return compare(topAEl, topBEl) * (reverse ? -1 : 1);
|
||||
@ -147,8 +147,8 @@ function sortNotes(parentNoteId: string, customSortBy: string = "title", reverse
|
||||
const bottomBEl = fetchValue(b, "bottom");
|
||||
|
||||
if (bottomAEl !== bottomBEl) {
|
||||
if (bottomAEl === null) return -1;
|
||||
if (bottomBEl === null) return 1;
|
||||
if (bottomAEl === null) return reverse ? 1 : -1;
|
||||
if (bottomBEl === null) return reverse ? -1 : 1;
|
||||
|
||||
// since "bottom" should not be reversible, we'll reverse it once more to nullify this effect
|
||||
return compare(bottomBEl, bottomAEl) * (reverse ? -1 : 1);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user