mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-05 19:20:12 +08:00
feat: add directly discover tests
This commit is contained in:
1 parent
cfb23347f8
commit
264d70fe3f
2 files changed
+50
-28
No files matched your search
@@ -1,17 +1,13 @@
|
||||
import FileNode from './fileNode.js'
|
||||
|
||||
export default class FileGraph {
|
||||
constructor(root) {
|
||||
this.root = new FileNode(root)
|
||||
}
|
||||
|
||||
export default class FileGraph extends FileNode {
|
||||
add(files) {
|
||||
// Logic to add the file node to the graph
|
||||
// You can implement the logic to find the appropriate location in the file graph
|
||||
// If the file node already exists, throw an error
|
||||
|
||||
files.forEach((file) => {
|
||||
this.root.addChild(file, { makeParents: true })
|
||||
this.addChild(file, { makeParents: true })
|
||||
})
|
||||
}
|
||||
|
||||
@@ -21,7 +17,7 @@ export default class FileGraph {
|
||||
// If the file node doesn't exist, throw an error
|
||||
|
||||
files.forEach((file) => {
|
||||
this.root.removeChild(file)
|
||||
this.removeChild(file)
|
||||
})
|
||||
}
|
||||
|
||||
@@ -36,7 +32,7 @@ export default class FileGraph {
|
||||
newNode.addChild(file, { makeParents: true })
|
||||
})
|
||||
|
||||
this.root.merge(newNode)
|
||||
this.merge(newNode)
|
||||
}
|
||||
|
||||
handleEvent(event) {
|
||||
@@ -54,8 +50,4 @@ export default class FileGraph {
|
||||
// Implement other cases if needed
|
||||
}
|
||||
}
|
||||
|
||||
toJSON() {
|
||||
return this.root.toJSON()
|
||||
}
|
||||
}
|
||||
@@ -30,9 +30,9 @@ describe('FileGraph', () => {
|
||||
|
||||
fileGraph.add(filesToAdd)
|
||||
|
||||
console.log(fileGraph.root.toString())
|
||||
expect(fileGraph.root.children.length).toBe(1)
|
||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(2)
|
||||
console.log(fileGraph.toString())
|
||||
expect(fileGraph.children.length).toBe(1)
|
||||
expect(fileGraph.children[0].children[0].children.length).toBe(2)
|
||||
})
|
||||
|
||||
test('remove files from graph', () => {
|
||||
@@ -76,14 +76,44 @@ describe('FileGraph', () => {
|
||||
|
||||
fileGraph.remove(filesToRemove)
|
||||
|
||||
console.log(fileGraph.root.toString())
|
||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(1)
|
||||
expect(fileGraph.root.children[0].children[0].children[0].name).toBe(
|
||||
'folder1'
|
||||
console.log(fileGraph.toString())
|
||||
expect(fileGraph.children[0].children[0].children.length).toBe(1)
|
||||
expect(fileGraph.children[0].children[0].children[0].name).toBe('folder1')
|
||||
expect(fileGraph.children[0].children[0].children[0].children.length).toBe(
|
||||
0
|
||||
)
|
||||
})
|
||||
|
||||
test('discover', () => {
|
||||
const fileGraph = new FileGraph(root)
|
||||
const discoverFiles = [
|
||||
{
|
||||
path: '/home/user/folder1',
|
||||
type: 'folder',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/folder1/file1.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/folder1/file2.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/folder1/file3.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
]
|
||||
|
||||
fileGraph.discover(discoverFiles)
|
||||
console.log(fileGraph.toString())
|
||||
expect(fileGraph.children[0].children[0].children[0].children.length).toBe(
|
||||
3
|
||||
)
|
||||
expect(
|
||||
fileGraph.root.children[0].children[0].children[0].children.length
|
||||
).toBe(0)
|
||||
})
|
||||
|
||||
test('discover new files', () => {
|
||||
@@ -113,7 +143,7 @@ describe('FileGraph', () => {
|
||||
]
|
||||
|
||||
fileGraph.add(filesToAdd)
|
||||
console.log(fileGraph.root.toString())
|
||||
console.log(fileGraph.toString())
|
||||
|
||||
const newFiles = [
|
||||
{
|
||||
@@ -140,10 +170,10 @@ describe('FileGraph', () => {
|
||||
|
||||
fileGraph.discover(newFiles)
|
||||
|
||||
console.log(fileGraph.root.toString())
|
||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(2)
|
||||
expect(
|
||||
fileGraph.root.children[0].children[0].children[0].children.length
|
||||
).toBe(3)
|
||||
console.log(fileGraph.toString())
|
||||
expect(fileGraph.children[0].children[0].children.length).toBe(2)
|
||||
expect(fileGraph.children[0].children[0].children[0].children.length).toBe(
|
||||
3
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user