fix(explorer): fix incorrect recursive case for folder rendering
This commit is contained in:
parent
e26658f4ed
commit
da1b6b37fe
2 changed files with 40 additions and 3 deletions
|
@ -134,9 +134,9 @@ function createFolderNode(
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const child of node.children) {
|
for (const child of node.children) {
|
||||||
const childNode = child.data
|
const childNode = child.isFolder
|
||||||
? createFileNode(currentSlug, child)
|
? createFolderNode(currentSlug, child, opts)
|
||||||
: createFolderNode(currentSlug, child, opts)
|
: createFileNode(currentSlug, child)
|
||||||
ul.appendChild(childNode)
|
ul.appendChild(childNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
import test, { describe, beforeEach } from "node:test"
|
import test, { describe, beforeEach } from "node:test"
|
||||||
import assert from "node:assert"
|
import assert from "node:assert"
|
||||||
import { FileTrieNode } from "./fileTrie"
|
import { FileTrieNode } from "./fileTrie"
|
||||||
|
import { FullSlug } from "./path"
|
||||||
|
|
||||||
interface TestData {
|
interface TestData {
|
||||||
title: string
|
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", () => {
|
describe("getFolderPaths", () => {
|
||||||
test("should return all folder paths", () => {
|
test("should return all folder paths", () => {
|
||||||
const data1 = {
|
const data1 = {
|
||||||
|
|
Loading…
Add table
Reference in a new issue