Skip to content

Commit 300ffcb

Browse files
skjnldsvAndyScherzinger
authored andcommitted
fix(files): open sidebar on sharing tab by default for files
Signed-off-by: skjnldsv <[email protected]>
1 parent a178308 commit 300ffcb

3 files changed

Lines changed: 145 additions & 3 deletions

File tree

apps/files/src/actions/sidebarAction.spec.ts

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
*
2121
*/
2222
import { expect } from '@jest/globals'
23-
import { File, Permission, View, FileAction } from '@nextcloud/files'
23+
import { File, Permission, View, FileAction, Folder } from '@nextcloud/files'
2424

2525
import { action } from './sidebarAction'
2626
import logger from '../logger'
@@ -125,7 +125,9 @@ describe('Open sidebar action enabled tests', () => {
125125
describe('Open sidebar action exec tests', () => {
126126
test('Open sidebar', async () => {
127127
const openMock = jest.fn()
128-
window.OCA = { Files: { Sidebar: { open: openMock } } }
128+
const defaultTabMock = jest.fn()
129+
window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } }
130+
129131
const goToRouteMock = jest.fn()
130132
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }
131133

@@ -140,6 +142,36 @@ describe('Open sidebar action exec tests', () => {
140142
// Silent action
141143
expect(exec).toBe(null)
142144
expect(openMock).toBeCalledWith('/foobar.txt')
145+
expect(defaultTabMock).toBeCalledWith('sharing')
146+
expect(goToRouteMock).toBeCalledWith(
147+
null,
148+
{ view: view.id, fileid: '1' },
149+
{ dir: '/' },
150+
true,
151+
)
152+
})
153+
154+
test('Open sidebar for folder', async () => {
155+
const openMock = jest.fn()
156+
const defaultTabMock = jest.fn()
157+
window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } }
158+
159+
const goToRouteMock = jest.fn()
160+
// @ts-expect-error We only mock what needed, we do not need Files.Router.goTo or Files.Navigation
161+
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }
162+
163+
const file = new Folder({
164+
id: 1,
165+
source: 'https://cloud.domain.com/remote.php/dav/files/admin/foobar',
166+
owner: 'admin',
167+
mime: 'httpd/unix-directory',
168+
})
169+
170+
const exec = await action.exec(file, view, '/')
171+
// Silent action
172+
expect(exec).toBe(null)
173+
expect(openMock).toBeCalledWith('/foobar')
174+
expect(defaultTabMock).toBeCalledWith('sharing')
143175
expect(goToRouteMock).toBeCalledWith(
144176
null,
145177
{ view: view.id, fileid: 1 },
@@ -150,7 +182,9 @@ describe('Open sidebar action exec tests', () => {
150182

151183
test('Open sidebar fails', async () => {
152184
const openMock = jest.fn(() => { throw new Error('Mock error') })
153-
window.OCA = { Files: { Sidebar: { open: openMock } } }
185+
const defaultTabMock = jest.fn()
186+
window.OCA = { Files: { Sidebar: { open: openMock, setActiveTab: defaultTabMock } } }
187+
154188
jest.spyOn(logger, 'error').mockImplementation(() => jest.fn())
155189

156190
const file = new File({

apps/files/src/actions/sidebarAction.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export const action = new FileAction({
5353

5454
async exec(node: Node, view: View, dir: string) {
5555
try {
56+
// Open sidebar and set active tab to sharing by default
57+
window.OCA.Files.Sidebar.setActiveTab('sharing')
58+
5659
// TODO: migrate Sidebar to use a Node instead
5760
await window.OCA.Files.Sidebar.open(node.path)
5861

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*!
2+
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
import type { User } from '@nextcloud/cypress'
6+
import { createShare } from './filesSharingUtils.ts'
7+
import { closeSidebar, getRowForFile } from '../files/FilesUtils.ts'
8+
9+
describe('files_sharing: Files inline status action', { testIsolation: true }, () => {
10+
/**
11+
* Regression test of https://github.com/nextcloud/server/issues/45723
12+
*/
13+
it('No "shared" tag when user ID is purely numerical', () => {
14+
const user = {
15+
language: 'en',
16+
password: 'test1234',
17+
userId: String(Math.floor(Math.random() * 1000)),
18+
} as User
19+
cy.createUser(user)
20+
cy.mkdir(user, '/folder')
21+
cy.login(user)
22+
23+
cy.visit('/apps/files')
24+
25+
getRowForFile('folder')
26+
.should('be.visible')
27+
.find('[data-cy-files-list-row-actions]')
28+
.findByRole('button', { name: 'Shared' })
29+
.should('not.exist')
30+
})
31+
32+
describe('Sharing inline status action handling', () => {
33+
let user: User
34+
let sharee: User
35+
36+
beforeEach(() => {
37+
cy.createRandomUser().then(($user) => {
38+
user = $user
39+
})
40+
cy.createRandomUser().then(($user) => {
41+
sharee = $user
42+
})
43+
})
44+
45+
it('Render quick option for sharing', () => {
46+
cy.mkdir(user, '/folder')
47+
cy.login(user)
48+
49+
cy.visit('/apps/files')
50+
getRowForFile('folder')
51+
.should('be.visible')
52+
53+
getRowForFile('folder')
54+
.should('be.visible')
55+
.find('[data-cy-files-list-row-actions]')
56+
.findByRole('button', { name: /Show sharing options/ })
57+
.should('be.visible')
58+
.click()
59+
60+
// check the click opened the sidebar
61+
cy.get('[data-cy-sidebar]')
62+
.should('be.visible')
63+
// and ensure the sharing tab is selected
64+
.findByRole('tab', { name: 'Sharing', selected: true })
65+
.should('exist')
66+
})
67+
68+
it('Render inline status action for sharer', () => {
69+
cy.mkdir(user, '/folder')
70+
cy.login(user)
71+
72+
cy.visit('/apps/files')
73+
getRowForFile('folder')
74+
.should('be.visible')
75+
createShare('folder', sharee.userId)
76+
closeSidebar()
77+
78+
getRowForFile('folder')
79+
.should('be.visible')
80+
.find('[data-cy-files-list-row-actions]')
81+
.findByRole('button', { name: /^Shared with/i })
82+
.should('be.visible')
83+
})
84+
85+
it('Render inline status action for sharee', () => {
86+
cy.mkdir(user, '/folder')
87+
cy.login(user)
88+
89+
cy.visit('/apps/files')
90+
getRowForFile('folder')
91+
.should('be.visible')
92+
createShare('folder', sharee.userId)
93+
closeSidebar()
94+
95+
cy.login(sharee)
96+
cy.visit('/apps/files')
97+
98+
getRowForFile('folder')
99+
.should('be.visible')
100+
.find('[data-cy-files-list-row-actions]')
101+
.findByRole('button', { name: `Shared by ${user.userId}` })
102+
.should('be.visible')
103+
})
104+
})
105+
})

0 commit comments

Comments
 (0)