mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 03:20:12 +08:00
feat: rewrite remove function and add remove test
This commit is contained in:
1 parent
887bbf5c1b
commit
7f2a57824b
3 files changed
+57
-35
No files matched your search
@@ -23,6 +23,15 @@ function mergeTest(files1, files2, expectedFiles) {
|
||||
expect(node1.toString()).toBe(expectedNode.toString())
|
||||
}
|
||||
|
||||
function removeChildTest(files, fileToRemove, expectedFiles) {
|
||||
const node = createNodeFromFiles(files)
|
||||
const expectedNode = createNodeFromFiles(expectedFiles)
|
||||
|
||||
node.removeChild(fileToRemove)
|
||||
|
||||
expect(node.toString()).toBe(expectedNode.toString())
|
||||
}
|
||||
|
||||
describe('FileNode', () => {
|
||||
let rootNode
|
||||
|
||||
@@ -183,4 +192,30 @@ describe('FileNode', () => {
|
||||
|
||||
mergeTest(files1, files2, expected)
|
||||
})
|
||||
|
||||
test('remove-child', () => {
|
||||
const root = {
|
||||
path: '/',
|
||||
type: 'folder',
|
||||
}
|
||||
const files = [
|
||||
root,
|
||||
{ path: '/a', type: 'file' },
|
||||
{ path: '/b', type: 'folder' },
|
||||
{ path: '/b/c', type: 'folder' },
|
||||
{ path: '/b/d', type: 'file' },
|
||||
{ path: '/b/c/f', type: 'file' },
|
||||
]
|
||||
|
||||
const fileToRemove = { path: '/b/c', type: 'folder' }
|
||||
|
||||
const expected = [
|
||||
root,
|
||||
{ path: '/a', type: 'file' },
|
||||
{ path: '/b', type: 'folder' },
|
||||
{ path: '/b/d', type: 'file' },
|
||||
]
|
||||
|
||||
removeChildTest(files, fileToRemove, expected)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user