Skip to content

Commit bc6f204

Browse files
committed
test(createFileTree): add test code
1 parent a3f53ff commit bc6f204

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
import createFileTree, { updateFileList } from '../utils/createFileTree';
2+
3+
describe('createFileTree', () => {
4+
it('should create a file tree from a list of files', () => {
5+
const fileList = [
6+
{ localPath: 'file1.txt' },
7+
{ localPath: 'dir1/file2.txt' },
8+
{ localPath: 'dir1/file3.txt' },
9+
{ localPath: 'dir2/subdir1/file4.txt' },
10+
];
11+
12+
const expectedFileTree = {
13+
files: [{ localPath: 'file1.txt' }],
14+
dir1: {
15+
files: [
16+
{ localPath: 'dir1/file2.txt' },
17+
{ localPath: 'dir1/file3.txt' },
18+
],
19+
},
20+
dir2: {
21+
subdir1: {
22+
files: [{ localPath: 'dir2/subdir1/file4.txt' }],
23+
},
24+
},
25+
};
26+
27+
expect(createFileTree(fileList)).toEqual(expectedFileTree);
28+
});
29+
});
30+
31+
describe('updateFileList', () => {
32+
it('should convert user-defined array to File | Directory format', () => {
33+
const inputList = [
34+
{ customFileName: 'file1.txt', customLocalPath: 'path1' },
35+
{ customFileName: 'file2.txt', customLocalPath: 'path2' },
36+
{ customFileName: 'file3.txt', customLocalPath: 'path3' },
37+
];
38+
39+
const expectedOutput = [
40+
{
41+
fileName: 'file1.txt',
42+
localPath: 'path1',
43+
customFileName: 'file1.txt',
44+
customLocalPath: 'path1',
45+
},
46+
{
47+
fileName: 'file2.txt',
48+
localPath: 'path2',
49+
customFileName: 'file2.txt',
50+
customLocalPath: 'path2',
51+
},
52+
{
53+
fileName: 'file3.txt',
54+
localPath: 'path3',
55+
customFileName: 'file3.txt',
56+
customLocalPath: 'path3',
57+
},
58+
];
59+
60+
const result = updateFileList({
61+
list: inputList,
62+
fileNameKey: 'customFileName',
63+
localPathKey: 'customLocalPath',
64+
});
65+
66+
expect(result).toEqual(expectedOutput);
67+
});
68+
});

0 commit comments

Comments
 (0)