-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(systemtags): Sub folders should be opened in files #47135
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
123 changes: 123 additions & 0 deletions
123
apps/systemtags/src/files_actions/openInFilesAction.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { action } from './openInFilesAction' | ||
import { expect } from '@jest/globals' | ||
import { File, Folder, Permission, View, DefaultType, FileAction } from '@nextcloud/files' | ||
|
||
const view = { | ||
id: 'files', | ||
name: 'Files', | ||
} as View | ||
|
||
const systemTagsView = { | ||
id: 'tags', | ||
name: 'tags', | ||
} as View | ||
|
||
const validNode = new Folder({ | ||
id: 1, | ||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foo', | ||
owner: 'admin', | ||
mime: 'httpd/unix-directory', | ||
root: '/files/admin', | ||
permissions: Permission.ALL, | ||
}) | ||
|
||
const validTag = new Folder({ | ||
id: 1, | ||
source: 'https://cloud.domain.com/remote.php/dav/systemtags/2', | ||
displayname: 'Foo', | ||
owner: 'admin', | ||
mime: 'httpd/unix-directory', | ||
root: '/systemtags', | ||
permissions: Permission.ALL, | ||
attributes: { | ||
'is-tag': true, | ||
}, | ||
}) | ||
|
||
describe('Open in files action conditions tests', () => { | ||
test('Default values', () => { | ||
expect(action).toBeInstanceOf(FileAction) | ||
expect(action.id).toBe('systemtags:open-in-files') | ||
expect(action.displayName([], systemTagsView)).toBe('Open in Files') | ||
expect(action.iconSvgInline([], systemTagsView)).toBe('') | ||
expect(action.default).toBe(DefaultType.HIDDEN) | ||
expect(action.order).toBe(-1000) | ||
expect(action.inline).toBeUndefined() | ||
}) | ||
}) | ||
|
||
describe('Open in files action enabled tests', () => { | ||
test('Enabled with on valid view', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([validNode], systemTagsView)).toBe(true) | ||
}) | ||
|
||
test('Disabled on wrong view', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([validNode], view)).toBe(false) | ||
}) | ||
|
||
test('Disabled without nodes', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([], view)).toBe(false) | ||
}) | ||
|
||
test('Disabled with too many nodes', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([validNode, validNode], view)).toBe(false) | ||
}) | ||
|
||
test('Disabled with when node is a tag', () => { | ||
expect(action.enabled).toBeDefined() | ||
expect(action.enabled!([validTag], view)).toBe(false) | ||
}) | ||
}) | ||
|
||
describe('Open in files action execute tests', () => { | ||
test('Open in files', async () => { | ||
const goToRouteMock = jest.fn() | ||
// @ts-expect-error We only mock what needed, we do not need Files.Router.goTo or Files.Navigation | ||
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } | ||
|
||
const file = new File({ | ||
id: 1, | ||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/foobar.txt', | ||
owner: 'admin', | ||
mime: 'text/plain', | ||
root: '/files/admin', | ||
permissions: Permission.ALL, | ||
}) | ||
|
||
const exec = await action.exec(file, view, '/') | ||
|
||
// Silent action | ||
expect(exec).toBe(null) | ||
expect(goToRouteMock).toBeCalledTimes(1) | ||
expect(goToRouteMock).toBeCalledWith(null, { fileid: '1', view: 'files' }, { dir: '/Foo', openfile: 'true' }) | ||
}) | ||
|
||
test('Open in files with folder', async () => { | ||
const goToRouteMock = jest.fn() | ||
// @ts-expect-error We only mock what needed, we do not need Files.Router.goTo or Files.Navigation | ||
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } } | ||
|
||
const file = new Folder({ | ||
id: 1, | ||
source: 'https://cloud.domain.com/remote.php/dav/files/admin/Foo/Bar', | ||
owner: 'admin', | ||
root: '/files/admin', | ||
permissions: Permission.ALL, | ||
}) | ||
|
||
const exec = await action.exec(file, view, '/') | ||
|
||
// Silent action | ||
expect(exec).toBe(null) | ||
expect(goToRouteMock).toBeCalledTimes(1) | ||
expect(goToRouteMock).toBeCalledWith(null, { fileid: '1', view: 'files' }, { dir: '/Foo/Bar', openfile: 'true' }) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/** | ||
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors | ||
* SPDX-License-Identifier: AGPL-3.0-or-later | ||
*/ | ||
import { translate as t } from '@nextcloud/l10n' | ||
import { type Node, FileType, FileAction, DefaultType } from '@nextcloud/files' | ||
|
||
export const action = new FileAction({ | ||
id: 'systemtags:open-in-files', | ||
displayName: () => t('systemtags', 'Open in Files'), | ||
iconSvgInline: () => '', | ||
|
||
enabled(nodes, view) { | ||
// Only for the system tags view | ||
if (view.id !== 'tags') { | ||
return false | ||
} | ||
// Only for single nodes | ||
if (nodes.length !== 1) { | ||
return false | ||
} | ||
// Do not open tags (keep the default action) and only open folders | ||
return nodes[0].attributes['is-tag'] !== true | ||
&& nodes[0].type === FileType.Folder | ||
}, | ||
|
||
async exec(node: Node) { | ||
let dir = node.dirname | ||
if (node.type === FileType.Folder) { | ||
dir = node.path | ||
} | ||
|
||
window.OCP.Files.Router.goToRoute( | ||
null, // use default route | ||
{ view: 'files', fileid: String(node.fileid) }, | ||
{ dir, openfile: 'true' }, | ||
) | ||
return null | ||
}, | ||
|
||
// Before openFolderAction | ||
order: -1000, | ||
default: DefaultType.HIDDEN, | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This bother me more than it should 😅😅