Skip to content

Commit a8f1036

Browse files
committed
test: add cypress tests for sharing download permission
Signed-off-by: Ferdinand Thiessen <opensource@fthiessen.de> [skip ci]
1 parent d9ba5d6 commit a8f1036

3 files changed

Lines changed: 110 additions & 6 deletions

File tree

cypress/e2e/files_sharing/FilesSharingUtils.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ export function createShare(fileName: string, username: string, shareSettings: P
1919
openSharingPanel(fileName)
2020

2121
cy.get('#app-sidebar-vue').within(() => {
22-
cy.get('#sharing-search-input').clear()
2322
cy.intercept({ times: 1, method: 'GET', url: '**/apps/files_sharing/api/v1/sharees?*' }).as('userSearch')
24-
cy.get('#sharing-search-input').type(username)
23+
cy.findByRole('combobox', { name: /Search for internal recipients/i })
24+
.type(`{selectAll}${username}`)
2525
cy.wait('@userSearch')
2626
})
2727

cypress/e2e/files_sharing/public-share/download-files.cy.ts renamed to cypress/e2e/files_sharing/public-share/download.cy.ts

Lines changed: 96 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
*/
55
// @ts-expect-error The package is currently broken - but works...
66
import { deleteDownloadsFolderBeforeEach } from 'cypress-delete-downloads-folder'
7-
import { createShare, getShareUrl, setupPublicShare, type ShareContext } from './setup-public-share.ts'
7+
import { createShare, getShareUrl, openLinkShareDetails, setupPublicShare, type ShareContext } from './setup-public-share.ts'
88
import { getRowForFile, getRowForFileId, triggerActionForFile, triggerActionForFileId } from '../../files/FilesUtils.ts'
99
import { zipFileContains } from '../../../support/utils/assertions.ts'
10+
import type { User } from '@nextcloud/cypress'
1011

1112
describe('files_sharing: Public share - downloading files', { testIsolation: true }, () => {
1213

@@ -170,4 +171,98 @@ describe('files_sharing: Public share - downloading files', { testIsolation: tru
170171
})
171172
})
172173
})
174+
175+
describe('download permission - link share', () => {
176+
let context: ShareContext
177+
beforeEach(() => {
178+
cy.createRandomUser().then((user) => {
179+
cy.mkdir(user, '/test')
180+
181+
context = { user }
182+
createShare(context, 'test')
183+
cy.login(context.user)
184+
cy.visit('/apps/files')
185+
})
186+
})
187+
188+
deleteDownloadsFolderBeforeEach()
189+
190+
it('download permission is retained', () => {
191+
getRowForFile('test').should('be.visible')
192+
triggerActionForFile('test', 'details')
193+
194+
openLinkShareDetails(0)
195+
196+
cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('update')
197+
198+
cy.findByRole('checkbox', { name: /hide download/i })
199+
.should('exist')
200+
.and('not.be.checked')
201+
.check({ force: true })
202+
cy.findByRole('checkbox', { name: /hide download/i })
203+
.should('be.checked')
204+
cy.findByRole('button', { name: /update share/i })
205+
.click()
206+
207+
cy.wait('@update')
208+
209+
openLinkShareDetails(0)
210+
cy.findByRole('checkbox', { name: /hide download/i })
211+
.should('be.checked')
212+
213+
cy.reload()
214+
215+
getRowForFile('test').should('be.visible')
216+
triggerActionForFile('test', 'details')
217+
openLinkShareDetails(0)
218+
cy.findByRole('checkbox', { name: /hide download/i })
219+
.should('be.checked')
220+
})
221+
})
222+
223+
describe('download permission - mail share', () => {
224+
let user: User
225+
226+
beforeEach(() => {
227+
cy.createRandomUser().then(($user) => {
228+
user = $user
229+
cy.mkdir(user, '/test')
230+
cy.login(user)
231+
cy.visit('/apps/files')
232+
})
233+
})
234+
235+
it('download permission is retained', () => {
236+
getRowForFile('test').should('be.visible')
237+
triggerActionForFile('test', 'details')
238+
239+
cy.findByRole('combobox', { name: /Enter external recipients/i })
240+
.type('test@example.com')
241+
242+
cy.get('.option[sharetype="4"][user="test@example.com"]')
243+
.parent('li')
244+
.click()
245+
cy.findByRole('button', { name: /advanced settings/i })
246+
.should('be.visible')
247+
.click()
248+
249+
cy.intercept('PUT', '**/ocs/v2.php/apps/files_sharing/api/v1/shares/*').as('update')
250+
251+
cy.findByRole('checkbox', { name: /hide download/i })
252+
.should('exist')
253+
.and('not.be.checked')
254+
.check({ force: true })
255+
cy.findByRole('button', { name: /save share/i })
256+
.click()
257+
258+
cy.wait('@update')
259+
260+
openLinkShareDetails(1)
261+
cy.findByRole('button', { name: /advanced settings/i })
262+
.click()
263+
cy.findByRole('checkbox', { name: /hide download/i })
264+
.should('exist')
265+
.and('be.checked')
266+
})
267+
})
173268
})

cypress/e2e/files_sharing/public-share/setup-public-share.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,24 @@ export function createShare(context: ShareContext, shareName: string, options: S
122122
}
123123

124124
/**
125-
* Adjust share permissions to be editable
125+
* open link share details for specific index
126+
*
127+
* @param index
126128
*/
127-
function adjustSharePermission(): void {
129+
export function openLinkShareDetails(index: number) {
128130
cy.findByRole('list', { name: 'Link shares' })
129131
.findAllByRole('listitem')
130-
.first()
132+
.eq(index)
131133
.findByRole('button', { name: /Actions/i })
132134
.click()
133135
cy.findByRole('menuitem', { name: /Customize link/i }).click()
136+
}
137+
138+
/**
139+
* Adjust share permissions to be editable
140+
*/
141+
function adjustSharePermission(): void {
142+
openLinkShareDetails(0)
134143

135144
cy.get('[data-cy-files-sharing-share-permissions-bundle]').should('be.visible')
136145
cy.get('[data-cy-files-sharing-share-permissions-bundle="upload-edit"]').click()

0 commit comments

Comments
 (0)