Skip to content

Commit 2bbc919

Browse files
committed
Fix file tree remove
1 parent d3c8df9 commit 2bbc919

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

site/src/util/filetree.test.ts

+19-1
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ test("getFileContent() return the file content from the file tree", () => {
3030
)
3131
})
3232

33-
test("removeFile() removes a file from the file tree", () => {
33+
test("removeFile() removes a file from a folder", () => {
3434
let fileTree: FileTree = {
3535
"main.tf": "terraform content",
3636
images: {
@@ -48,6 +48,24 @@ test("removeFile() removes a file from the file tree", () => {
4848
expect(expectedFileTree).toEqual(fileTree)
4949
})
5050

51+
test("removeFile() removes a file from root", () => {
52+
let fileTree: FileTree = {
53+
"main.tf": "terraform content",
54+
images: {
55+
"java.Dockerfile": "java dockerfile",
56+
"python.Dockerfile": "python Dockerfile",
57+
},
58+
}
59+
fileTree = removeFile("main.tf", fileTree)
60+
const expectedFileTree = {
61+
images: {
62+
"java.Dockerfile": "java dockerfile",
63+
"python.Dockerfile": "python Dockerfile",
64+
},
65+
}
66+
expect(expectedFileTree).toEqual(fileTree)
67+
})
68+
5169
test("moveFile() moves a file from in file tree", () => {
5270
let fileTree: FileTree = {
5371
"main.tf": "terraform content",

site/src/util/filetree.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export const existsFile = (path: string, fileTree: FileTree) => {
2121

2222
export const removeFile = (path: string, fileTree: FileTree) => {
2323
const updatedFileTree = { ...fileTree }
24-
unset(fileTree, path.split("/"))
24+
unset(updatedFileTree, path.split("/"))
2525
return updatedFileTree
2626
}
2727

0 commit comments

Comments
 (0)