mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: revise fileGraph discover
This commit is contained in:
1 parent
3c41764f85
commit
02e1219228
2 files changed
+60
-17
No files matched your search
@@ -30,9 +30,13 @@ export default class FileGraph {
|
|||||||
// Overwrite the file graph with the provided files
|
// Overwrite the file graph with the provided files
|
||||||
// Remove file nodes that don't exist anymore and add new ones
|
// Remove file nodes that don't exist anymore and add new ones
|
||||||
|
|
||||||
eventFiles.forEach((file) => {
|
const newNode = new FileNode(eventFiles[0])
|
||||||
this.root.merge(file)
|
|
||||||
|
eventFiles.slice(1).forEach((file) => {
|
||||||
|
newNode.addChild(file, { makeParents: true })
|
||||||
})
|
})
|
||||||
|
|
||||||
|
this.root.merge(newNode)
|
||||||
}
|
}
|
||||||
|
|
||||||
handleEvent(event) {
|
handleEvent(event) {
|
||||||
|
|||||||
@@ -40,13 +40,23 @@ describe('FileGraph', () => {
|
|||||||
|
|
||||||
const filesToAdd = [
|
const filesToAdd = [
|
||||||
{
|
{
|
||||||
path: '/home/user/file1.txt',
|
path: '/home/user/folder1',
|
||||||
|
type: 'folder',
|
||||||
|
discovered: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder2',
|
||||||
|
type: 'folder',
|
||||||
|
discovered: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder1/file1.txt',
|
||||||
type: 'file',
|
type: 'file',
|
||||||
discovered: true,
|
discovered: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/home/user/folder1',
|
path: '/home/user/folder2/file2.txt',
|
||||||
type: 'folder',
|
type: 'file',
|
||||||
discovered: true,
|
discovered: true,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -55,7 +65,11 @@ describe('FileGraph', () => {
|
|||||||
|
|
||||||
const filesToRemove = [
|
const filesToRemove = [
|
||||||
{
|
{
|
||||||
path: '/home/user/folder1',
|
path: '/home/user/folder1/file1.txt',
|
||||||
|
type: 'folder',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder2',
|
||||||
type: 'folder',
|
type: 'folder',
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
@@ -64,6 +78,12 @@ describe('FileGraph', () => {
|
|||||||
|
|
||||||
console.log(fileGraph.root.toString())
|
console.log(fileGraph.root.toString())
|
||||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(1)
|
expect(fileGraph.root.children[0].children[0].children.length).toBe(1)
|
||||||
|
expect(fileGraph.root.children[0].children[0].children[0].name).toBe(
|
||||||
|
'folder1'
|
||||||
|
)
|
||||||
|
expect(
|
||||||
|
fileGraph.root.children[0].children[0].children[0].children.length
|
||||||
|
).toBe(0)
|
||||||
})
|
})
|
||||||
|
|
||||||
test('discover new files', () => {
|
test('discover new files', () => {
|
||||||
@@ -71,28 +91,48 @@ describe('FileGraph', () => {
|
|||||||
|
|
||||||
const filesToAdd = [
|
const filesToAdd = [
|
||||||
{
|
{
|
||||||
path: '/home/user/file1.txt',
|
path: '/home/user/folder1',
|
||||||
|
type: 'folder',
|
||||||
|
discovered: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder2',
|
||||||
|
type: 'folder',
|
||||||
|
discovered: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder1/file1.txt',
|
||||||
type: 'file',
|
type: 'file',
|
||||||
discovered: true,
|
discovered: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/home/user/folder1',
|
path: '/home/user/folder2/file2.txt',
|
||||||
type: 'folder',
|
type: 'file',
|
||||||
discovered: true,
|
discovered: true,
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
fileGraph.add(filesToAdd)
|
fileGraph.add(filesToAdd)
|
||||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(2)
|
console.log(fileGraph.root.toString())
|
||||||
|
|
||||||
const newFiles = [
|
const newFiles = [
|
||||||
{
|
{
|
||||||
path: '/home/newfile.txt',
|
path: '/home/user/folder1',
|
||||||
|
type: 'folder',
|
||||||
|
discovered: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder1/file1.txt',
|
||||||
type: 'file',
|
type: 'file',
|
||||||
discovered: true,
|
discovered: true,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
path: '/home/user/file1.txt',
|
path: '/home/user/folder1/file2.txt',
|
||||||
|
type: 'file',
|
||||||
|
discovered: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/home/user/folder1/file3.txt',
|
||||||
type: 'file',
|
type: 'file',
|
||||||
discovered: true,
|
discovered: true,
|
||||||
},
|
},
|
||||||
@@ -101,10 +141,9 @@ describe('FileGraph', () => {
|
|||||||
fileGraph.discover(newFiles)
|
fileGraph.discover(newFiles)
|
||||||
|
|
||||||
console.log(fileGraph.root.toString())
|
console.log(fileGraph.root.toString())
|
||||||
expect(fileGraph.root.children[0].children.length).toBe(2)
|
expect(fileGraph.root.children[0].children[0].children.length).toBe(2)
|
||||||
expect(fileGraph.root.children[0].children[0].name).toBe('newfile.txt')
|
expect(
|
||||||
expect(fileGraph.root.children[0].children[0].children[0].name).toBe(
|
fileGraph.root.children[0].children[0].children[0].children.length
|
||||||
'file1.txt'
|
).toBe(3)
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
Reference in new issue
Block a user