diff options
author | skjnldsv <skjnldsv@protonmail.com> | 2024-11-08 11:02:53 +0100 |
---|---|---|
committer | skjnldsv <skjnldsv@protonmail.com> | 2024-11-09 11:42:08 +0100 |
commit | 606241cf76d0f3bbcf9996ccc4e1a29123706058 (patch) | |
tree | 50b13b5b793539817f9e5ad3ac1501a4109eb2a9 | |
parent | b48a877c621e1757e35e1571362157da6589ff74 (diff) | |
download | nextcloud-server-606241cf76d0f3bbcf9996ccc4e1a29123706058.tar.gz nextcloud-server-606241cf76d0f3bbcf9996ccc4e1a29123706058.zip |
fix(files): open sidebar on sharing tab by default for files
Signed-off-by: skjnldsv <skjnldsv@protonmail.com>
-rw-r--r-- | apps/files/src/actions/sidebarAction.spec.ts | 40 | ||||
-rw-r--r-- | apps/files/src/actions/sidebarAction.ts | 3 | ||||
-rw-r--r-- | cypress/e2e/files_sharing/files-inline-action.cy.ts | 2 |
3 files changed, 41 insertions, 4 deletions
diff --git a/apps/files/src/actions/sidebarAction.spec.ts b/apps/files/src/actions/sidebarAction.spec.ts index 21b48eba105..0e973d83914 100644 --- a/apps/files/src/actions/sidebarAction.spec.ts +++ b/apps/files/src/actions/sidebarAction.spec.ts @@ -3,7 +3,7 @@ * SPDX-License-Identifier: AGPL-3.0-or-later */ import { expect } from '@jest/globals' -import { File, Permission, View, FileAction } from '@nextcloud/files' +import { File, Permission, View, FileAction, Folder } from '@nextcloud/files' import { action } from './sidebarAction' import logger from '../logger' @@ -108,7 +108,9 @@ describe('Open sidebar action enabled tests', () => { describe('Open sidebar action exec tests', () => { test('Open sidebar', async () => { const openMock = jest.fn() - window.OCA = { Files: { Sidebar: { open: openMock } } } + const defaultTabMock = jest.fn() + window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } } + 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 } } } @@ -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 = jest.fn() + const defaultTabMock = jest.fn() + window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } } + + 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/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,9 @@ describe('Open sidebar action exec tests', () => { test('Open sidebar fails', async () => { const openMock = jest.fn(() => { throw new Error('Mock error') }) - window.OCA = { Files: { Sidebar: { open: openMock } } } + const defaultTabMock = jest.fn() + window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } } + jest.spyOn(logger, 'error').mockImplementation(() => jest.fn()) const file = new File({ diff --git a/apps/files/src/actions/sidebarAction.ts b/apps/files/src/actions/sidebarAction.ts index f00088f8d0c..6dcb6df2bbc 100644 --- a/apps/files/src/actions/sidebarAction.ts +++ b/apps/files/src/actions/sidebarAction.ts @@ -36,6 +36,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) diff --git a/cypress/e2e/files_sharing/files-inline-action.cy.ts b/cypress/e2e/files_sharing/files-inline-action.cy.ts index 0fd476ca6ed..4d7763bd778 100644 --- a/cypress/e2e/files_sharing/files-inline-action.cy.ts +++ b/cypress/e2e/files_sharing/files-inline-action.cy.ts @@ -29,7 +29,7 @@ describe('files_sharing: Files inline status action', { testIsolation: true }, ( .should('not.exist') }) - describe('', () => { + describe('Sharing inline status action handling', () => { let user: User let sharee: User |