mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-06 11:30:13 +08:00
working: update file-graph-algorithm
This commit is contained in:
1 parent
ab570e9c1b
commit
821896f292
5 files changed
+162
-36
No files matched your search
@@ -0,0 +1,110 @@
|
||||
import FileGraph from './fileGraph.js'
|
||||
import FileNode from './fileNode.js'
|
||||
|
||||
describe('FileGraph', () => {
|
||||
let root
|
||||
|
||||
beforeEach(() => {
|
||||
root = new FileNode({
|
||||
path: '/',
|
||||
type: 'folder',
|
||||
discovered: true,
|
||||
})
|
||||
})
|
||||
|
||||
test('add files to graph', () => {
|
||||
const fileGraph = new FileGraph(root)
|
||||
|
||||
const filesToAdd = [
|
||||
{
|
||||
path: '/home/user/file1.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/folder1',
|
||||
type: 'folder',
|
||||
discovered: true,
|
||||
},
|
||||
]
|
||||
|
||||
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)
|
||||
})
|
||||
|
||||
test('remove files from graph', () => {
|
||||
const fileGraph = new FileGraph(root)
|
||||
|
||||
const filesToAdd = [
|
||||
{
|
||||
path: '/home/user/file1.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/folder1',
|
||||
type: 'folder',
|
||||
discovered: true,
|
||||
},
|
||||
]
|
||||
|
||||
fileGraph.add(filesToAdd)
|
||||
|
||||
const filesToRemove = [
|
||||
{
|
||||
path: '/home/user/folder1',
|
||||
type: 'folder',
|
||||
},
|
||||
]
|
||||
|
||||
fileGraph.remove(filesToRemove)
|
||||
|
||||
console.log(fileGraph.root.toString())
|
||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(1)
|
||||
})
|
||||
|
||||
test('discover new files', () => {
|
||||
const fileGraph = new FileGraph(root)
|
||||
|
||||
const filesToAdd = [
|
||||
{
|
||||
path: '/home/user/file1.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/folder1',
|
||||
type: 'folder',
|
||||
discovered: true,
|
||||
},
|
||||
]
|
||||
|
||||
fileGraph.add(filesToAdd)
|
||||
expect(fileGraph.root.children[0].children[0].children.length).toBe(2)
|
||||
|
||||
const newFiles = [
|
||||
{
|
||||
path: '/home/newfile.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
{
|
||||
path: '/home/user/file1.txt',
|
||||
type: 'file',
|
||||
discovered: true,
|
||||
},
|
||||
]
|
||||
|
||||
fileGraph.discover(newFiles)
|
||||
|
||||
console.log(fileGraph.root.toString())
|
||||
expect(fileGraph.root.children[0].children.length).toBe(2)
|
||||
expect(fileGraph.root.children[0].children[0].name).toBe('newfile.txt')
|
||||
expect(fileGraph.root.children[0].children[0].children[0].name).toBe(
|
||||
'file1.txt'
|
||||
)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user