Skip to content

Commit 0ee80f5

Browse files
committed
fix(files): Exclude file size of excluded files in personal files view
Signed-off-by: Rens Groothuijsen <l.groothuijsen@alumni.maastrichtuniversity.nl>
1 parent 92fb69c commit 0ee80f5

2 files changed

Lines changed: 50 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import { Folder } from '@nextcloud/files'
2+
import { describe, expect, it, vi } from 'vitest'
3+
import { getContents as getPersonalFiles } from './PersonalFiles.ts'
4+
5+
const getContents = vi.hoisted(() => vi.fn())
6+
vi.mock('./Files.ts', () => ({ getContents }))
7+
8+
const fakeFolder = new Folder({
9+
owner: 'owner',
10+
source: 'https://cloud.example.com/remote.php/dav/files/owner/folder',
11+
root: '/',
12+
size: 3,
13+
})
14+
15+
const fakeNodes = {
16+
contents: [
17+
{
18+
attributes: {
19+
'mount-type': '',
20+
},
21+
size: 1,
22+
},
23+
{
24+
attributes: {
25+
'mount-type': '',
26+
},
27+
size: 1,
28+
},
29+
{
30+
attributes: {
31+
'mount-type': 'group',
32+
},
33+
size: 1,
34+
},
35+
],
36+
folder: fakeFolder,
37+
}
38+
39+
describe('Personal files service', () => {
40+
getContents.mockImplementationOnce(() => Promise.resolve(fakeNodes))
41+
42+
it('Excludes the file size of excluded files', async () => {
43+
const contents = await getPersonalFiles('/', { signal: new AbortController().signal })
44+
expect(contents.folder.size).toBe(2)
45+
})
46+
})

apps/files/src/services/PersonalFiles.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export function getContents(path: string = '/', options: { signal: AbortSignal }
4343
return getFiles(path, options)
4444
.then((content) => {
4545
content.contents = content.contents.filter(isPersonalFile)
46+
content.folder.size = content.contents
47+
.map((node) => node.size)
48+
.filter((size) => size !== undefined)
49+
.reduce((total, size) => total + size)
4650
return content
4751
})
4852
}

0 commit comments

Comments
 (0)