fix(explorer): fix incorrect recursive case for folder rendering

This commit is contained in:
Jacky Zhao 2025-03-14 10:05:26 -07:00
parent e26658f4ed
commit da1b6b37fe
2 changed files with 40 additions and 3 deletions

View file

@ -134,9 +134,9 @@ function createFolderNode(
}
for (const child of node.children) {
const childNode = child.data
? createFileNode(currentSlug, child)
: createFolderNode(currentSlug, child, opts)
const childNode = child.isFolder
? createFolderNode(currentSlug, child, opts)
: createFileNode(currentSlug, child)
ul.appendChild(childNode)
}

View file

@ -1,6 +1,7 @@
import test, { describe, beforeEach } from "node:test"
import assert from "node:assert"
import { FileTrieNode } from "./fileTrie"
import { FullSlug } from "./path"
interface TestData {
title: string
@ -192,6 +193,42 @@ describe("FileTrie", () => {
})
})
describe("fromEntries", () => {
test("nested", () => {
const trie = FileTrieNode.fromEntries([
["index" as FullSlug, { title: "Root", slug: "index", filePath: "index.md" }],
[
"folder/file1" as FullSlug,
{ title: "File 1", slug: "folder/file1", filePath: "folder/file1.md" },
],
[
"folder/index" as FullSlug,
{ title: "Folder Index", slug: "folder/index", filePath: "folder/index.md" },
],
[
"folder/file2" as FullSlug,
{ title: "File 2", slug: "folder/file2", filePath: "folder/file2.md" },
],
[
"folder/folder2/index" as FullSlug,
{
title: "Subfolder Index",
slug: "folder/folder2/index",
filePath: "folder/folder2/index.md",
},
],
])
assert.strictEqual(trie.children.length, 1)
assert.strictEqual(trie.children[0].slug, "folder/index")
assert.strictEqual(trie.children[0].children.length, 3)
assert.strictEqual(trie.children[0].children[0].slug, "folder/file1")
assert.strictEqual(trie.children[0].children[1].slug, "folder/file2")
assert.strictEqual(trie.children[0].children[2].slug, "folder/folder2/index")
assert.strictEqual(trie.children[0].children[2].children.length, 0)
})
})
describe("getFolderPaths", () => {
test("should return all folder paths", () => {
const data1 = {