Skip to content

Commit b929670

Browse files
committed
Merge branch 'test-code'
Merge branch 'test-code'
2 parents 16d5203 + bc6f204 commit b929670

File tree

2 files changed

+89
-0
lines changed

2 files changed

+89
-0
lines changed

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 in-ch
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.
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)