mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
fix: merge discovery state (with test)
* update fileNode.toString to add discovery state
This commit is contained in:
1 parent
f360d783f8
commit
6b94b1ae81
2 files changed
+40
-5
No files matched your search
@@ -80,6 +80,9 @@ export default class FileNode extends File {
|
|||||||
|
|
||||||
// If this is the same node, merge the children
|
// If this is the same node, merge the children
|
||||||
if (fileNode.path === this.path) {
|
if (fileNode.path === this.path) {
|
||||||
|
// Update the state of this node
|
||||||
|
this.discovered = this.discovered || fileNode.discovered
|
||||||
|
|
||||||
fileNode.children.forEach((child) => {
|
fileNode.children.forEach((child) => {
|
||||||
const existingChild = this.children.find((c) => c.path === child.path)
|
const existingChild = this.children.find((c) => c.path === child.path)
|
||||||
if (existingChild) {
|
if (existingChild) {
|
||||||
@@ -116,12 +119,15 @@ export default class FileNode extends File {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
toString() {
|
toString(level = 0) {
|
||||||
const indent = ' '.repeat(this.path.split('/').length - 1)
|
let { name } = this
|
||||||
const suffix = this.isDirectory() ? '/' : ''
|
const indent = ' '.repeat(level)
|
||||||
|
name = `${indent}${name}`
|
||||||
|
if (this.isDirectory()) name += '/'
|
||||||
|
if (!this.discovered) name += `*`
|
||||||
const childrenString = this.children
|
const childrenString = this.children
|
||||||
.map((child) => child.toString())
|
.map((child) => child.toString(level + 1))
|
||||||
.join('')
|
.join('')
|
||||||
return `${indent}${this.name}${suffix}\n${childrenString}`
|
return `${name}\n${childrenString}`
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -193,6 +193,35 @@ describe('FileNode', () => {
|
|||||||
mergeTest(files1, files2, expected)
|
mergeTest(files1, files2, expected)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('merge-hidden', () => {
|
||||||
|
const root = {
|
||||||
|
path: '/',
|
||||||
|
type: 'folder',
|
||||||
|
}
|
||||||
|
const files1 = [
|
||||||
|
root,
|
||||||
|
{ path: '/a', type: 'file', discovered: true },
|
||||||
|
{ path: '/.b', type: 'file', discovered: false },
|
||||||
|
{ path: '/c', type: 'folder', discovered: true },
|
||||||
|
{ path: '/c/.d', type: 'file', discovered: false },
|
||||||
|
]
|
||||||
|
|
||||||
|
const files2 = [
|
||||||
|
{ path: '/c', type: 'folder', discovered: true },
|
||||||
|
{ path: '/c/.d', type: 'file', discovered: true },
|
||||||
|
]
|
||||||
|
|
||||||
|
const expected = [
|
||||||
|
root,
|
||||||
|
{ path: '/a', type: 'file', discovered: true },
|
||||||
|
{ path: '/.b', type: 'file', discovered: false },
|
||||||
|
{ path: '/c', type: 'folder', discovered: true },
|
||||||
|
{ path: '/c/.d', type: 'file', discovered: true },
|
||||||
|
]
|
||||||
|
|
||||||
|
mergeTest(files1, files2, expected)
|
||||||
|
})
|
||||||
|
|
||||||
test('remove-child', () => {
|
test('remove-child', () => {
|
||||||
const root = {
|
const root = {
|
||||||
path: '/',
|
path: '/',
|
||||||
|
|||||||
Reference in new issue
Block a user