aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files
diff options
context:
space:
mode:
authorskjnldsv <skjnldsv@protonmail.com>2024-11-08 11:02:53 +0100
committerskjnldsv <skjnldsv@protonmail.com>2024-11-08 16:41:25 +0100
commit191e839a5fbcfad854947619bd6e94c229ecff16 (patch)
treef5b011c46cb2bcb0c5a631b0d99491bdef6c9f87 /apps/files
parentc8868ce4520419ab13f7e30d783158eb598c67f2 (diff)
downloadnextcloud-server-191e839a5fbcfad854947619bd6e94c229ecff16.tar.gz
nextcloud-server-191e839a5fbcfad854947619bd6e94c229ecff16.zip
fix(files): open sidebar on sharing tab by default for files
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
Diffstat (limited to 'apps/files')
-rw-r--r--apps/files/src/actions/sidebarAction.spec.ts39
-rw-r--r--apps/files/src/actions/sidebarAction.ts3
2 files changed, 39 insertions, 3 deletions
diff --git a/apps/files/src/actions/sidebarAction.spec.ts b/apps/files/src/actions/sidebarAction.spec.ts
index 9755f519306..1f1e81dbeaf 100644
--- a/apps/files/src/actions/sidebarAction.spec.ts
+++ b/apps/files/src/actions/sidebarAction.spec.ts
@@ -2,7 +2,7 @@
* SPDX-FileCopyrightText: 2023 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
-import { File, Permission, View, FileAction } from '@nextcloud/files'
+import { File, Permission, View, FileAction, Folder } from '@nextcloud/files'
import { describe, expect, test, vi } from 'vitest'
import { action } from './sidebarAction'
@@ -108,7 +108,9 @@ describe('Open sidebar action enabled tests', () => {
describe('Open sidebar action exec tests', () => {
test('Open sidebar', async () => {
const openMock = vi.fn()
- window.OCA = { Files: { Sidebar: { open: openMock } } }
+ const defaultTabMock = vi.fn()
+ window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } }
+
const goToRouteMock = vi.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 } } }
@@ -124,6 +126,36 @@ describe('Open sidebar action exec tests', () => {
// Silent action
expect(exec).toBe(null)
expect(openMock).toBeCalledWith('/foobar.txt')
+ expect(defaultTabMock).toBeCalledWith('sharing')
+ expect(goToRouteMock).toBeCalledWith(
+ null,
+ { view: view.id, fileid: '1' },
+ { dir: '/' },
+ true,
+ )
+ })
+
+ test('Open sidebar for folder', async () => {
+ const openMock = vi.fn()
+ const defaultTabMock = vi.fn()
+ window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } }
+
+ const goToRouteMock = vi.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/foobar',
+ owner: 'admin',
+ mime: 'httpd/unix-directory',
+ })
+
+ const exec = await action.exec(file, view, '/')
+ // Silent action
+ expect(exec).toBe(null)
+ expect(openMock).toBeCalledWith('/foobar')
+ expect(defaultTabMock).toBeCalledWith('sharing')
expect(goToRouteMock).toBeCalledWith(
null,
{ view: view.id, fileid: '1' },
@@ -134,7 +166,8 @@ describe('Open sidebar action exec tests', () => {
test('Open sidebar fails', async () => {
const openMock = vi.fn(() => { throw new Error('Mock error') })
- window.OCA = { Files: { Sidebar: { open: openMock } } }
+ const defaultTabMock = vi.fn()
+ window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } }
vi.spyOn(logger, 'error').mockImplementation(() => vi.fn())
const file = new File({
diff --git a/apps/files/src/actions/sidebarAction.ts b/apps/files/src/actions/sidebarAction.ts
index a9d80c412da..a951de1db97 100644
--- a/apps/files/src/actions/sidebarAction.ts
+++ b/apps/files/src/actions/sidebarAction.ts
@@ -44,6 +44,9 @@ export const action = new FileAction({
async exec(node: Node, view: View, dir: string) {
try {
+ // Open sidebar and set active tab to sharing by default
+ window.OCA.Files.Sidebar.setActiveTab('sharing')
+
// TODO: migrate Sidebar to use a Node instead
await window.OCA.Files.Sidebar.open(node.path)