mirror of
https://github.com/gitbutlerapp/gitbutler.git
synced 2024-11-29 14:25:45 +03:00
Fix file tree tests
This commit is contained in:
parent
92b0ed9a65
commit
8aeb85fee1
@ -37,16 +37,20 @@ test('creates a file tree', () => {
|
||||
})
|
||||
];
|
||||
const fileTree = filesToFileTree(files);
|
||||
expect(fileTree).toHaveLength(2);
|
||||
const children = fileTree.children;
|
||||
expect(children).toHaveLength(2);
|
||||
|
||||
expect(fileTree[0].name).toEqual('test');
|
||||
expect(fileTree[0].children[0].name).toEqual('foo.py');
|
||||
expect(fileTree[0].children[0].file).toEqual(files[0]);
|
||||
expect(fileTree[0].children[1].name).toEqual('bar.rs');
|
||||
expect(fileTree[0].children[1].file).toEqual(files[1]);
|
||||
// Note that the result is sorted
|
||||
// - folders first
|
||||
// - then alphanumerically
|
||||
expect(children[1].name).toEqual('test');
|
||||
expect(children[1].children[0].name).toEqual('bar.rs');
|
||||
expect(children[1].children[0].file).toEqual(files[1]);
|
||||
expect(children[1].children[1].name).toEqual('foo.py');
|
||||
expect(children[1].children[1].file).toEqual(files[0]);
|
||||
|
||||
expect(fileTree[1].name).toEqual('src');
|
||||
expect(fileTree[1].children[0].name).toEqual('hello');
|
||||
expect(fileTree[1].children[0].children[0].name).toEqual('world.txt');
|
||||
expect(fileTree[1].children[0].children[0].file).toEqual(files[2]);
|
||||
expect(children[0].name).toEqual('src');
|
||||
expect(children[0].children[0].name).toEqual('hello');
|
||||
expect(children[0].children[0].children[0].name).toEqual('world.txt');
|
||||
expect(children[0].children[0].children[0].file).toEqual(files[2]);
|
||||
});
|
||||
|
@ -25,9 +25,7 @@ function createNode(acc: TreeNode, pathParts: string[]) {
|
||||
}
|
||||
|
||||
export function sortChildren(node: TreeNode) {
|
||||
console.log(node.name);
|
||||
node.children.sort((a, b) => {
|
||||
console.log(a.file, b.file);
|
||||
if (a.file && !b.file) {
|
||||
return 1;
|
||||
} else if (!a.file && b.file) {
|
||||
|
Loading…
Reference in New Issue
Block a user