feat: create FileNode class, addChild method

This commit is contained in:
wancat authored and Chen, Tai-Lin committed 2023-08-28 14:39:52 +08:00
1 parent bdb979e608
commit fa496ceae7
4 files changed
+131

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
import FileNode from './fileNode.js'
test('addChild method adds a child node to the tree', () => {
const files = [
{
path: '/home/rudeus',
name: 'rudeus',
type: 'folder',
discovered: 'test',
},
{
path: '/home/rudeus/.bash_history',
name: '.bash_history',
type: 'file',
discovered: 'test',
},
{
path: '/home/rudeus/.viminfo',
name: '.viminfo',
type: 'file',
discovered: 'test',
},
{
path: '/home/rudeus/.zshrc',
name: '.zshrc',
type: 'file',
discovered: 'test',
},
{
path: '/home/rudeus/forgotten_scroll.txt',
name: 'forgotten_scroll.txt',
type: 'file',
discovered: 'test',
},
{
path: '/home/rudeus/test',
name: 'test',
type: 'folder',
discovered: 'test',
},
{
path: '/home/rudeus/test/.b',
name: '.b',
type: 'file',
discovered: false,
},
{
path: '/home/rudeus/test/a',
name: 'a',
type: 'file',
discovered: false,
},
]
const root = new FileNode(files[0])
files.slice(1).forEach((file) => {
root.addChild(file)
})
console.log(root.toString())
expect(root.children.length).toBe(5)
})