Skip to content

Commit

Permalink
fix(files): open sidebar on sharing tab by default for files
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv authored and AndyScherzinger committed Feb 9, 2025
1 parent a178308 commit 300ffcb
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 3 deletions.
40 changes: 37 additions & 3 deletions apps/files/src/actions/sidebarAction.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*
*/
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'
Expand Down Expand Up @@ -125,7 +125,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()
window.OCP = { Files: { Router: { goToRoute: goToRouteMock } } }

Expand All @@ -140,6 +142,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 },
Expand All @@ -150,7 +182,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({
Expand Down
3 changes: 3 additions & 0 deletions apps/files/src/actions/sidebarAction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,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)

Expand Down
105 changes: 105 additions & 0 deletions cypress/e2e/files_sharing/files-inline-action.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*!
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
import type { User } from '@nextcloud/cypress'
import { createShare } from './filesSharingUtils.ts'
import { closeSidebar, getRowForFile } from '../files/FilesUtils.ts'

describe('files_sharing: Files inline status action', { testIsolation: true }, () => {
/**
* Regression test of https://github.com/nextcloud/server/issues/45723
*/
it('No "shared" tag when user ID is purely numerical', () => {
const user = {
language: 'en',
password: 'test1234',
userId: String(Math.floor(Math.random() * 1000)),
} as User
cy.createUser(user)
cy.mkdir(user, '/folder')
cy.login(user)

cy.visit('/apps/files')

getRowForFile('folder')
.should('be.visible')
.find('[data-cy-files-list-row-actions]')
.findByRole('button', { name: 'Shared' })
.should('not.exist')
})

describe('Sharing inline status action handling', () => {
let user: User
let sharee: User

beforeEach(() => {
cy.createRandomUser().then(($user) => {
user = $user
})
cy.createRandomUser().then(($user) => {
sharee = $user
})
})

it('Render quick option for sharing', () => {
cy.mkdir(user, '/folder')
cy.login(user)

cy.visit('/apps/files')
getRowForFile('folder')
.should('be.visible')

getRowForFile('folder')
.should('be.visible')
.find('[data-cy-files-list-row-actions]')
.findByRole('button', { name: /Show sharing options/ })
.should('be.visible')
.click()

// check the click opened the sidebar
cy.get('[data-cy-sidebar]')
.should('be.visible')
// and ensure the sharing tab is selected
.findByRole('tab', { name: 'Sharing', selected: true })
.should('exist')
})

it('Render inline status action for sharer', () => {
cy.mkdir(user, '/folder')
cy.login(user)

cy.visit('/apps/files')
getRowForFile('folder')
.should('be.visible')
createShare('folder', sharee.userId)
closeSidebar()

getRowForFile('folder')
.should('be.visible')
.find('[data-cy-files-list-row-actions]')
.findByRole('button', { name: /^Shared with/i })
.should('be.visible')
})

it('Render inline status action for sharee', () => {
cy.mkdir(user, '/folder')
cy.login(user)

cy.visit('/apps/files')
getRowForFile('folder')
.should('be.visible')
createShare('folder', sharee.userId)
closeSidebar()

cy.login(sharee)
cy.visit('/apps/files')

getRowForFile('folder')
.should('be.visible')
.find('[data-cy-files-list-row-actions]')
.findByRole('button', { name: `Shared by ${user.userId}` })
.should('be.visible')
})
})
})

0 comments on commit 300ffcb

Please sign in to comment.