Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions apps/files/src/services/PersonalFiles.spec.ts

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file is missing the SPDX headers, please add them

Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/

import { Folder } from '@nextcloud/files'
import { describe, expect, it, vi } from 'vitest'
import { getContents as getPersonalFiles } from './PersonalFiles.ts'

const getContents = vi.hoisted(() => vi.fn())
vi.mock('./Files.ts', () => ({ getContents }))

const fakeFolder = new Folder({
owner: 'owner',
source: 'https://cloud.example.com/remote.php/dav/files/owner/folder',
root: '/',
size: 3,
})

const fakeNodes = {
contents: [
{
attributes: {
'mount-type': '',
},
size: 1,
},
{
attributes: {
'mount-type': '',
},
size: 1,
},
{
attributes: {
'mount-type': 'group',
},
size: 1,
},
],
folder: fakeFolder,
}

describe('Personal files service', () => {
getContents.mockImplementationOnce(() => Promise.resolve(fakeNodes))

it('Excludes the file size of excluded files', async () => {
const contents = await getPersonalFiles('/', { signal: new AbortController().signal })
expect(contents.folder.size).toBe(2)
})
})
2 changes: 2 additions & 0 deletions apps/files/src/services/PersonalFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ export function getContents(path: string = '/', options: { signal: AbortSignal }
return getFiles(path, options)
.then((content) => {
content.contents = content.contents.filter(isPersonalFile)
content.folder.size = content.contents
.reduce((total, node) => total + (node.size ?? 0), 0)
return content
})
}
4 changes: 2 additions & 2 deletions dist/files-init.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/files-init.js.map

Large diffs are not rendered by default.